BGTabBarController.m 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. //
  2. // BGTabBarController.m
  3. // BuguLive
  4. //
  5. // Created by xfg on 2017/6/26.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "BGTabBarController.h"
  9. #import "BGTabBar.h"
  10. #import "BGNavigationController.h"
  11. #import "HMHomeViewController.h"
  12. #import "PublishLivestViewController.h"
  13. #import "AgreementViewController.h"
  14. #import "MPersonCenterVC.h"
  15. #import "MSmallVideoVC.h"
  16. #import "ListDayViewController.h"
  17. #import "LeaderboardViewController.h"
  18. #import "SChargerVC.h"
  19. #import "LEEAlertHelper.h"
  20. #import "LEEAlert.h"
  21. #import "HMCenterPopView.h"
  22. #import "SmallVideoViewController.h"
  23. #import "CustomPagerController.h"
  24. #import "AppDelegate.h"
  25. #import "NewSmallVideoViewController.h"
  26. #import "TCVideoRecordViewController.h"
  27. #import "YHTimeLineViewController.h"
  28. #import "MGAlertIncodeView.h"
  29. #import "UpgradeTipView.h"
  30. //#import <UGCKit/UGCKit.h>
  31. #import <UGCKit/UGCKit.h>
  32. #import <TXLiteAVSDK_Professional/TXVideoEditer.h>
  33. //主页
  34. #import "BogoHomeViewController.h"
  35. //广场
  36. #import "BogoSquareViewController.h"
  37. //消息
  38. #import "BogoNewsViewController.h"
  39. //青少年模式弹窗
  40. #import "BogoYounthModePopView.h"
  41. #import "SIdentificationVC.h"
  42. #import "IMALoginParam.h"
  43. #import "BogoNewsTabNumModel.h"
  44. #import "MineViewController.h"
  45. #import "BogoShopKit.h"
  46. #import "BogoYouthModeViewController.h"
  47. #import "BogoYoungModeVideoViewController.h"
  48. #import "BogoYoungModeVideoViewController.h"
  49. #import "BogoNewSquareViewController.h"
  50. #import "VoiceHomeListViewController.h"
  51. #import "GKDBViewController.h"
  52. #import "GKAllRefreshViewController.h"
  53. #import "AudioChatTool.h"
  54. #import "CustomTabbarView.h"
  55. @interface BGTabBarController ()<UITabBarControllerDelegate,UIActionSheetDelegate,BogoHomeTopViewDelegate, CustomTabbarViewDelegate>
  56. @property (nonatomic, strong) CustomTabbarView *customTabBar;
  57. @property (nonatomic, strong) HMCenterPopView *popView;
  58. @property (nonatomic, strong) VideoDynamicViewC *videoDynamicViewC;
  59. @property(nonatomic, strong) MGAlertIncodeView *alertView;
  60. @property(nonatomic, strong) BogoYounthModePopView *youthView;
  61. @property(nonatomic, strong) UIView *tipView;
  62. @end
  63. @implementation BGTabBarController
  64. BogoSingletonM(Instance);
  65. - (void)viewDidLoad
  66. {
  67. [super viewDidLoad];
  68. [[GiftListManager sharedInstance] reloadGiftList];
  69. [BGIMMsgHandler sharedInstance];
  70. [BGIMPrivateMsgHandler sharedInstance];
  71. if ([BGIMLoginManager sharedInstance].isIMSDKOK) {
  72. NSLog(@"已经登录了");
  73. }else{
  74. NSLog(@"没有");
  75. [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
  76. }
  77. self.delegate = self;
  78. [self setupCustomTabBar];
  79. [self setUpChildViewControllers];
  80. self.view.backgroundColor = kWhiteColor;
  81. self.alertView = [MGAlertIncodeView new];
  82. self.alertView.frame = CGRectMake(0, 0, kScreenW, kScreenH);
  83. self.alertView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
  84. FWWeakify(self)
  85. self.alertView.clickBlock = ^(NSInteger i) {
  86. FWStrongify(self)
  87. if (i == 0) {
  88. // [self.alertView removeAllSubViews];
  89. self.alertView.hidden = YES;
  90. }
  91. };
  92. self.alertView.hidden = YES;
  93. [self.view addSubview:self.alertView];
  94. if (kIsCheckingVersion())
  95. {
  96. }
  97. else
  98. {
  99. #ifdef DEBUG
  100. #else
  101. [self checkCode];
  102. #endif
  103. }
  104. // [[UIBarButtonItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:kClearColor,
  105. // NSFontAttributeName:[UIFont systemFontOfSize:20.0]
  106. // } forState:UIControlStateNormal];
  107. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isOpenYoung:) name:@"isOpenYoung" object:nil];
  108. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDarkContent];
  109. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IMChatMsgNotfication:) name:g_notif_chatmsg object:nil];
  110. }
  111. - (void)getGiftNumber {
  112. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  113. [dict setValue:@"deal" forKey:@"ctl"];
  114. [dict setValue:@"get_gift_quantity" forKey:@"act"];
  115. [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  116. NSLog(@"104responseJson%@",responseJson);
  117. if ([responseJson toInt:@"status"] == 1) {
  118. NSArray *list = responseJson[@"data"];
  119. [GlobalVariables sharedInstance].giftQuantityModelList = [NSArray modelArrayWithClass:GiftQuantityModel.class json:list];
  120. // for (int i = 0; i<list.count; i++) {
  121. // GiftQuantityModel *model = [GiftQuantityModel modelWithDictionary:list[i]];
  122. //
  123. // }
  124. }else{
  125. //接口请求失败
  126. NSLog(ASLocalizedString(@"礼物responseJson:%@"),responseJson);
  127. }
  128. } FailureBlock:^(NSError *error) {
  129. NSLog(ASLocalizedString(@"礼物error:%@"),error);
  130. }];
  131. }
  132. - (void)isOpenYoung:(NSNotification *)center{
  133. // NSDictionary *dic = center.object;
  134. if ([GlobalVariables sharedInstance].userModel.is_open_young.integerValue) {
  135. NSMutableDictionary *hotDic = [NSMutableDictionary dictionary];
  136. [hotDic setObject:@"1" forKey:@"order"];
  137. [hotDic setObject:@"0" forKey:@"cate"];
  138. BogoYoungModeVideoViewController *vc = [BogoYoungModeVideoViewController new];
  139. vc.isHaveNavBar = NO;
  140. vc.paramDict = hotDic;
  141. vc.notHaveTabbar = NO;
  142. vc.hidesBottomBarWhenPushed = YES;
  143. [self.viewControllers.firstObject pushViewController:vc animated:YES];
  144. }else{
  145. if (![GlobalVariables sharedInstance].isShutDownYoung) {
  146. [self.youthView show:self.view type:FDPopTypeCenter];
  147. }else{
  148. [self.view addSubview:self.tipView];
  149. [UIView animateWithDuration:0.25 animations:^{
  150. self.tipView.alpha = 1;
  151. }];
  152. [self performSelector:@selector(hideTipView) afterDelay:3];
  153. }
  154. }
  155. }
  156. - (void)hideTipView{
  157. [UIView animateWithDuration:0.25 animations:^{
  158. self.tipView.alpha = 0;
  159. } completion:^(BOOL finished) {
  160. [self.tipView removeFromSuperview];
  161. }];
  162. }
  163. - (UIView *)tipView{
  164. if (!_tipView) {
  165. _tipView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 180, 40)];
  166. _tipView.backgroundColor = [FD_BlackColor colorWithAlphaComponent:0.4];
  167. _tipView.layer.cornerRadius = 20;
  168. _tipView.clipsToBounds = YES;
  169. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 140, 20)];
  170. titleLabel.textColor = FD_WhiteColor;
  171. titleLabel.center = _tipView.center;
  172. titleLabel.text =ASLocalizedString( @"青少年模式已关闭");
  173. titleLabel.font = [UIFont systemFontOfSize:14];
  174. titleLabel.textAlignment = NSTextAlignmentCenter;
  175. [_tipView addSubview:titleLabel];
  176. _tipView.center = self.view.center;
  177. _tipView.alpha = 0;
  178. }
  179. return _tipView;
  180. }
  181. - (void)viewWillAppear:(BOOL)animated {
  182. [super viewWillAppear:animated];
  183. [self getGiftNumber];
  184. [[AppDelegate sharedAppDelegate] showNesBarRedNum];
  185. NSLog(@"%@",self.view);
  186. }
  187. - (void)checkCode {
  188. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  189. [mDict setObject:@"login" forKey:@"ctl"];
  190. [mDict setObject:@"is_invitation" forKey:@"act"];
  191. [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  192. if([[GlobalVariables sharedInstance].appModel.is_invite_code intValue] == 1)
  193. {
  194. if([responseJson toInt:@"state"] == 0)
  195. {
  196. self.alertView.hidden = NO;
  197. self.alertView.textField.placeholder = ASLocalizedString(@"请输入邀请码");
  198. }
  199. }
  200. else
  201. {
  202. if([responseJson toInt:@"state"] == 0)
  203. {
  204. self.alertView.hidden = NO;
  205. }
  206. }
  207. } FailureBlock:^(NSError *error) {
  208. }];
  209. }
  210. -(void)postCode:(NSString *)code
  211. {
  212. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  213. [mDict setObject:@"login" forKey:@"ctl"];
  214. [mDict setObject:@"invitation" forKey:@"act"];
  215. [mDict setObject:code forKey:@"invitation_id"];
  216. [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  217. if ([responseJson toInt:@"status"] == 1)
  218. {
  219. [LEEAlert closeWithCompletionBlock:^{
  220. }];
  221. [FanweMessage alert:ASLocalizedString(@"提交成功")];
  222. }
  223. else
  224. {
  225. __block UITextField *tf = nil;
  226. [BGHUDHelper alert:[responseJson valueForKey:@"error"] action:^{
  227. [LEEAlert alert].config
  228. .LeeTitle(ASLocalizedString(@"邀请码"))
  229. .LeeAddTextField(^(UITextField *textField) {
  230. // 这里可以进行自定义的设置
  231. textField.placeholder = ASLocalizedString(@"请输入邀请码");
  232. textField.textColor = [UIColor darkGrayColor];
  233. tf = textField; //赋值
  234. })
  235. .LeeAction(ASLocalizedString(@"确定"), ^{
  236. if(tf.text == nil || tf.text.length < 1)
  237. {
  238. // [self checkCode];
  239. [BGHUDHelper alert:ASLocalizedString(@"邀请码不能为空")action:^{
  240. [self checkCode];
  241. }];
  242. // [BGHUDHelper alert:ASLocalizedString(@"邀请码不能为空")];
  243. return;
  244. }
  245. [self postCode:tf.text];
  246. [tf resignFirstResponder];
  247. })
  248. // 点击事件的Block如果不需要可以传nil
  249. .LeeShow();
  250. }];
  251. }
  252. } FailureBlock:^(NSError *error) {
  253. }];
  254. //
  255. }
  256. #pragma mark - 设置子控制器
  257. - (void)setUpChildViewControllers
  258. {
  259. // if (@available(iOS 13.0, *)) {
  260. //
  261. // [[UITabBar appearance] setUnselectedItemTintColor:[UIColor colorWithHexString:@"#999999"]];
  262. // self.tabBar.tintColor = [UIColor colorWithHexString:@"#9152F8"];
  263. //// kAppMainColor;
  264. // }else{
  265. //
  266. // }
  267. // 首页
  268. BogoHomeViewController *home = [[BogoHomeViewController alloc] init];
  269. home.topViewdelegate = self;
  270. home.clickSquareBtnBlock = ^(NSInteger index) {
  271. [self showDynamicVC];
  272. };
  273. [self addChildViewController:home image:@"ic_tab_live_normal" seletedImage:@"ic_tab_live_selected" title:ASLocalizedString(@"首页")];
  274. // VoiceHomeListViewController *voiceRoom = [VoiceHomeListViewController new];
  275. // voiceRoom.types = @"1";
  276. // voiceRoom.delegate = home;
  277. // voiceRoom.topViewdelegate = self;
  278. // [self addChildViewController:voiceRoom image:@"语音1" seletedImage:@"语音2" title:ASLocalizedString(@"语音")];
  279. GKAllRefreshViewController *voiceRoom2 = [GKAllRefreshViewController new];
  280. voiceRoom2.types = @"1";
  281. voiceRoom2.delegate = home;
  282. voiceRoom2.topViewdelegate = self;
  283. [self addChildViewController:voiceRoom2 image:@"ic_tab_party_normal" seletedImage:@"ic_tab_party_sel" title:ASLocalizedString(@"派对")];
  284. // guangc
  285. if (![GlobalVariables sharedInstance].appModel.short_video.integerValue) {
  286. BogoSquareViewController *squareVC = [BogoSquareViewController new];
  287. squareVC.clickSquareBtnBlock = ^(NSInteger index) {
  288. [self showDynamicVC];
  289. };
  290. [self addChildViewController:squareVC image:@"ic_tab_moment_normal" seletedImage:@"ic_tab_moment_sel" title:ASLocalizedString(@"动态")];
  291. }else{
  292. BogoNewSquareViewController *squareVC = [BogoNewSquareViewController new];
  293. squareVC.clickSquareBtnBlock = ^(NSInteger index) {
  294. [self showDynamicVC];
  295. };
  296. [self addChildViewController:squareVC image:@"ic_tab_moment_normal" seletedImage:@"ic_tab_moment_sel" title:ASLocalizedString(@"动态")];
  297. }
  298. // 发布直播==》放在FWTabBar里面
  299. // [self setupTabBar];
  300. // 直播
  301. [self addChildViewController:[[BogoNewsViewController alloc] init] image:@"ic_tab_message_normal" seletedImage:@"ic_tab_message_sel" title:ASLocalizedString(@"消息")];
  302. // 我的
  303. [self addChildViewController:[[MineViewController alloc] initWithNibName:@"MineViewController" bundle:[NSBundle mainBundle]] image:@"ic_tab_me_normal" seletedImage:@"ic_tab_me_sel" title:ASLocalizedString(@"我的")];
  304. }
  305. - (void)setupCustomTabBar {
  306. self.tabBar.hidden = YES;
  307. // 创建自定义TabBar,高度为80
  308. CGFloat tabBarHeight = 80;
  309. CGFloat safeAreaBottom = 0;
  310. if (@available(iOS 11.0, *)) {
  311. safeAreaBottom = self.view.safeAreaInsets.bottom;
  312. }
  313. self.customTabBar = [[CustomTabbarView alloc] initWithFrame:CGRectMake(0,
  314. self.view.frame.size.height - tabBarHeight - safeAreaBottom,
  315. self.view.frame.size.width,
  316. tabBarHeight + safeAreaBottom)];
  317. self.customTabBar.delegate = self;
  318. // 根据BGTabBarController中setUpChildViewControllers方法添加TabBar项
  319. // 注意:这里使用的图片名称需要与原项目中的图片资源匹配
  320. // 首页
  321. [self.customTabBar addTabBarItemWithTitle:@"首页"
  322. normalImage:@"ic_tab_live_normal"
  323. selectedImage:@"ic_tab_live_selected"];
  324. // 派对
  325. [self.customTabBar addTabBarItemWithTitle:@"派对"
  326. normalImage:@"ic_tab_party_normal"
  327. selectedImage:@"ic_tab_party_sel"];
  328. // 动态
  329. [self.customTabBar addTabBarItemWithTitle:@"动态"
  330. normalImage:@"ic_tab_moment_normal"
  331. selectedImage:@"ic_tab_moment_sel"];
  332. // 消息
  333. [self.customTabBar addTabBarItemWithTitle:@"消息"
  334. normalImage:@"ic_tab_message_normal"
  335. selectedImage:@"ic_tab_message_sel"];
  336. // 我的
  337. [self.customTabBar addTabBarItemWithTitle:@"我的"
  338. normalImage:@"ic_tab_me_normal"
  339. selectedImage:@"ic_tab_me_sel"];
  340. [self.view addSubview:self.customTabBar];
  341. }
  342. #pragma mark - CustomTabbarViewDelegate
  343. - (void)customTabbarView:(CustomTabbarView *)tabbarView didSelectItemAtIndex:(NSInteger)index {
  344. NSLog(@"选中了第%ld个TabBar项", (long)index);
  345. self.selectedIndex = index;
  346. }
  347. //-(void)showNesBarRedNum{
  348. //
  349. // dispatch_async(dispatch_get_main_queue(), ^{
  350. //
  351. // UITabBarItem *itme = [self.tabBar.items objectAtIndex:3];
  352. // SFriendObj *xxx = nil;
  353. //
  354. // // [SFriendObj getMyFriendMsgList:0
  355. // // lastObj:xxx
  356. // // block:^(SResBase *resb, NSArray *all, int unReadNum) {
  357. // NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  358. // [parmDict setObject:@"dynamic" forKey:@"ctl"];
  359. // [parmDict setObject:@"unread_messages" forKey:@"act"];
  360. //
  361. // [[NetHttpsManager manager]POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  362. //
  363. // if ([[responseJson valueForKey:@"status"]integerValue] == 1) {
  364. //
  365. // BogoNewsTabNumModel *model = [BogoNewsTabNumModel modelWithDictionary:[responseJson valueForKey:@"data"]];
  366. //
  367. //
  368. // // if ((model.bzone_reply + model.bzone_like) == 0) {
  369. // // itme.badgeValue = nil;
  370. // // }else{
  371. // //
  372. // //
  373. // // }
  374. // [SFriendObj getAllUnReadCountComplete:^(int num) {
  375. // if ((model.bzone_reply + model.bzone_like + num) == 0) {
  376. // itme.badgeValue = nil;
  377. // }else{
  378. // itme.badgeValue = [NSString stringWithFormat:@"%ld",model.bzone_reply + model.bzone_like + num + model.msg.count];
  379. // }
  380. //
  381. // }];
  382. // // self.headView.model = model;
  383. //
  384. // }
  385. //
  386. // } FailureBlock:^(NSError *error) {
  387. //
  388. // }];
  389. // });
  390. //
  391. //
  392. //
  393. //}
  394. -(UIImage *)imageResize :(UIImage*)img andResizeTo:(CGSize)newSize withTop:(CGFloat)top
  395. {
  396. CGFloat scale = [[UIScreen mainScreen]scale];
  397. //UIGraphicsBeginImageContext(newSize);
  398. UIGraphicsBeginImageContextWithOptions(newSize, NO, scale);
  399. [img drawInRect:CGRectMake(0,top,newSize.width,newSize.height)];
  400. UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
  401. UIGraphicsEndImageContext();
  402. return newImage;
  403. }
  404. #pragma mark - 添加子控制器
  405. - (UIViewController *)addChildViewController:(UIViewController *)childController image:(NSString *)image seletedImage:(NSString *)selectedImage title:(NSString *)title
  406. {
  407. // if (![BGUtils isBlankString:title])
  408. // {
  409. childController.title = title;
  410. // NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
  411. // normalAttrs[NSForegroundColorAttributeName] = kAppGrayColor3;
  412. // [childController.tabBarItem setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
  413. //
  414. // NSMutableDictionary *selectedAtrrs = [NSMutableDictionary dictionary];
  415. // selectedAtrrs[NSForegroundColorAttributeName] = UIColorFromRGB(0x4BC8FC);
  416. // [childController.tabBarItem setTitleTextAttributes:selectedAtrrs forState:UIControlStateSelected];
  417. // childController.tabBarItem.imageInsets = UIEdgeInsetsMake(12, 12, 12, 12);
  418. // childController.tabBarItem.imageInsets = UIEdgeInsetsMake(-10, 0, -5, 0);
  419. // childController.tabBarItem.imageInsets = UIEdgeInsetsMake(-10, 0, -5, 0);
  420. // }
  421. // else
  422. // {
  423. // childController.tabBarItem.imageInsets = UIEdgeInsetsMake(-16, 0, -5, 0);
  424. // }
  425. // 设置图片
  426. // if ([title isEqualToString:@""]) {
  427. //// UIImage *imageS = [[self imageResize:[UIImage imageNamed:image] andResizeTo:CGSizeMake(50, 50)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  428. //// [childController.tabBarItem setImage:imageS];
  429. //// [imageS drawInRect:CGRectMake(-10,0,50,50)];
  430. // [childController.tabBarItem setImage:[[self imageResize:[UIImage imageNamed:image] andResizeTo:CGSizeMake(kRealValue(45), kRealValue(45)) withTop:0] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  431. // }else{
  432. // UITabBarItem* itm= [[UITabBarItem alloc] initWithTitle:title image:[UIImage imageNamed:image] selectedImage:[UIImage imageNamed:selectedImage]];
  433. // childController.tabBarItem = itm;
  434. // [childController.tabBarItem setImage:[[self imageResize:[UIImage imageNamed:image] andResizeTo:CGSizeMake(20, 20) withTop:0] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  435. // [childController.tabBarItem setSelectedImage:[[self imageResize:[UIImage imageNamed:selectedImage] andResizeTo:CGSizeMake(20, 20) withTop:0] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  436. // }
  437. // 导航条
  438. BGNavigationController *nav = [[BGNavigationController alloc] initWithRootViewController:childController];
  439. [self addChildViewController:nav];
  440. nav.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-80-SafeAreaBottomHeight);
  441. return childController;
  442. }
  443. //- (void)setupTabBar
  444. //{
  445. // BGTabBar *tabbar = [[BGTabBar alloc] init];
  446. // tabbar.backgroundColor = kWhiteColor;
  447. // [self setValue:tabbar forKey:@"tabBar"];
  448. // FWWeakify(self)
  449. // [tabbar setCenterBtnClickBlock:^{
  450. // FWStrongify(self)
  451. // [self onClickedCenterTabBar];
  452. // }];
  453. //}
  454. - (void)startLive {
  455. if ([GlobalVariables sharedInstance].appModel.must_authentication.intValue == 1) {
  456. if ([GlobalVariables sharedInstance].userModel.is_authentication.intValue != 2) {
  457. [self showAuthView];
  458. return;
  459. }
  460. }
  461. IMALoginParam *loginParam = [IMALoginParam loadFromLocal];
  462. if (loginParam.isAgree ==1)
  463. {
  464. if (AppDelegate.sharedAppDelegate.isInAudioVideoChatVc) {
  465. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"通话中,请结束通话后再试")];
  466. return;
  467. }
  468. PublishLivestViewController *pvc = [[PublishLivestViewController alloc] init];
  469. [[AppDelegate sharedAppDelegate] presentViewController:pvc animated:YES completion:^{
  470. }];
  471. }
  472. else
  473. {
  474. AgreementViewController *agreeVC = [AgreementViewController webControlerWithUrlStr:[GlobalVariables sharedInstance].appModel.agreement_link isShowIndicator:YES isShowNavBar:YES];
  475. [[AppDelegate sharedAppDelegate] presentViewController:agreeVC animated:YES completion:^{
  476. }];
  477. }
  478. }
  479. #pragma mark 点击直播
  480. - (void)onClickedCenterTabBar
  481. {
  482. // PopMenuCenter *popMenuCenter = [PopMenuCenter sharePopMenuCenter];
  483. // [popMenuCenter setTabBarC:self];
  484. // [popMenuCenter setStPopMenuShowState:STPopMenuShow];
  485. NSArray *objs = [[NSBundle mainBundle]loadNibNamed:@"HMCenterPopView" owner:nil options:nil];
  486. self.popView = objs.firstObject;
  487. [self setUpLocalizationStringForView:self.popView];
  488. FWWeakify(self)
  489. [self.popView setClickPopViewBtnBlock:^(HMCenterPopViewBtnType type) {
  490. FWStrongify(self)
  491. switch (type) {
  492. case HMCenterPopViewBtnTypeLive:
  493. {
  494. [self startLive];
  495. }
  496. break;
  497. case HMCenterPopViewBtnTypeVideo:
  498. {
  499. [self showDynamicVC];
  500. }
  501. break;
  502. case HMCenterPopViewBtnTypeClose:
  503. break;
  504. default:
  505. break;
  506. }
  507. }];
  508. [self.popView show:[UIApplication sharedApplication].keyWindow];
  509. }
  510. -(void)showDynamicVC{
  511. self.videoDynamicViewC = (VideoDynamicViewC *)[VideoDynamicViewC showSTBaseViewCOnSuperViewC:self.selectedViewController
  512. andFrameRect:CGRectMake(0, 0, kScreenW, kScreenH)
  513. andSTViewCTransitionType:STViewCTransitionTypeOfModal
  514. andComplete:^(BOOL finished,
  515. STBaseViewC *stBaseViewC) {
  516. }];
  517. self.videoDynamicViewC.recordTabBarC = self;
  518. [self.videoDynamicViewC videoDynamicView];
  519. // 开启IQ
  520. self.videoDynamicViewC.isOpenIQKeyboardManager = YES;
  521. // 加载View层
  522. //[videoDynamicViewC graphicDynamicView];
  523. //跳转
  524. //找到当前ViewC
  525. UIViewController *currentViewC = self.selectedViewController.childViewControllers[0];
  526. //TabBarc隐藏
  527. currentViewC.hidesBottomBarWhenPushed=YES;
  528. currentViewC.navigationController.navigationBar.tintColor = kAppGrayColor1;
  529. self.videoDynamicViewC.navigationController.navigationBar.hidden = NO;
  530. self.videoDynamicViewC.title = ASLocalizedString(@"发布短视频");
  531. self.videoDynamicViewC.navigationController.navigationBar.tintColor =kAppGrayColor1;
  532. //改变颜色 必须跳转后
  533. self.videoDynamicViewC.navigationController.navigationBar.hidden = NO;
  534. [self.videoDynamicViewC.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:kAppGrayColor1}];
  535. currentViewC.hidesBottomBarWhenPushed=NO;
  536. UIActionSheet *headImgSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  537. [headImgSheet addButtonWithTitle:ASLocalizedString(@"拍摄视频")];
  538. [headImgSheet addButtonWithTitle:ASLocalizedString(@"相册中获取视频")];
  539. [headImgSheet addButtonWithTitle:ASLocalizedString(@"取消")];
  540. headImgSheet.cancelButtonIndex = headImgSheet.numberOfButtons-1;
  541. headImgSheet.delegate = self;
  542. [headImgSheet showInView:[UIApplication sharedApplication].keyWindow];
  543. }
  544. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger) buttonIndex
  545. {
  546. if (buttonIndex == 0) {
  547. //如果短视频key为空,调本地视频
  548. if ([BGUtils isBlankString:[GlobalVariables sharedInstance].appModel.tencent_video_sdk_key]) {
  549. [[AppDelegate sharedAppDelegate]pushViewController:self.videoDynamicViewC animated:YES];
  550. [self.videoDynamicViewC ceartVideoViewWithType:(int)buttonIndex];
  551. return;
  552. }
  553. #warning 暂时注释
  554. UGCKitRecordViewController *recordViewController = [[UGCKitRecordViewController alloc] initWithConfig:nil theme:nil];
  555. recordViewController.completion = ^(UGCKitResult *result) {
  556. if (result.cancelled) {
  557. [[AppDelegate sharedAppDelegate]popViewController];
  558. // UGCKitEditViewController *vc= [UGCKitEditViewController new];
  559. // [[AppDelegate sharedAppDelegate]pushViewController:vc];
  560. }else{
  561. [self showEditViewController:result rotation:TCEditRotation0 inNavigationController:[AppDelegate sharedAppDelegate].topViewController.navigationController];
  562. // self.navigationController];
  563. }
  564. };
  565. // TCVideoRecordViewController *vc = [[TCVideoRecordViewController alloc] init];
  566. [[AppDelegate sharedAppDelegate] pushViewController:recordViewController animated:YES];
  567. return;
  568. }else if (buttonIndex == 1){
  569. [[AppDelegate sharedAppDelegate]pushViewController:self.videoDynamicViewC animated:YES];
  570. [self.videoDynamicViewC ceartVideoViewWithType:(int)buttonIndex];
  571. }
  572. }
  573. - (void)showEditViewController:(UGCKitResult *)result
  574. rotation:(TCEditRotation)rotation
  575. inNavigationController:(UINavigationController *)nav
  576. {
  577. UGCKitMedia *media = result.media;
  578. UGCKitEditConfig *config = [[UGCKitEditConfig alloc] init];
  579. config.rotation = (TCEditRotation)(rotation / 90);
  580. UIImage *tailWatermarkImage = [UIImage imageNamed:@"tcloud_logo"];
  581. TXVideoInfo *info = [TXVideoInfoReader getVideoInfoWithAsset:media.videoAsset];
  582. float w = 0.15;
  583. float x = (1.0 - w) / 2.0;
  584. float width = w * info.width;
  585. float height = width * tailWatermarkImage.size.height / tailWatermarkImage.size.width;
  586. float y = (info.height - height) / 2 / info.height;
  587. config.tailWatermark = [UGCKitWatermark watermarkWithImage:tailWatermarkImage
  588. frame:CGRectMake(x, y, w, 0)
  589. duration:2];
  590. __weak __typeof(self) wself = self;
  591. UGCKitEditViewController *vc = [[UGCKitEditViewController alloc] initWithMedia:media
  592. config:config
  593. theme:nil];
  594. __weak UGCKitEditViewController *weakEditController = vc;
  595. __weak UINavigationController *weakNavigation = nav;
  596. vc.onTapNextButton = ^(void (^finish)(BOOL)) {
  597. // [wself showEditFinishOptionsWithResult:result editController:weakEditController finishBloack:finish];
  598. finish(YES);
  599. };
  600. vc.completion = ^(UGCKitResult *result) {
  601. __strong __typeof(wself) self = wself; if (self == nil) { return; }
  602. if (result.cancelled) {
  603. [[AppDelegate sharedAppDelegate]popViewController];
  604. } else {
  605. [_videoDynamicViewC upLoadVideoUrl:vc.videoOutputPath];
  606. [[AppDelegate sharedAppDelegate]popToRootViewController];
  607. [[AppDelegate sharedAppDelegate]pushViewController:_videoDynamicViewC animated:YES];
  608. [self showVideoDynamicViewC];
  609. }
  610. [[NSUserDefaults standardUserDefaults] setObject:nil forKey:CACHE_PATH_LIST];
  611. // [self dismissViewControllerAnimated:YES completion:nil];
  612. };
  613. [[AppDelegate sharedAppDelegate]pushViewController:vc animated:YES];
  614. // [nav pushViewController:vc animated:YES];
  615. }
  616. #pragma mark - 5 - 视频动态页面
  617. -(void)showVideoDynamicViewC
  618. {
  619. _videoDynamicViewC = (VideoDynamicViewC *)[VideoDynamicViewC showSTBaseViewCOnSuperViewC:[AppDelegate sharedAppDelegate].topViewController.tabBarController.selectedViewController
  620. andFrameRect:CGRectMake(0, 0, kScreenW, kScreenH)
  621. andSTViewCTransitionType:STViewCTransitionTypeOfModal
  622. andComplete:^(BOOL finished,
  623. STBaseViewC *stBaseViewC) {
  624. }];
  625. _videoDynamicViewC.recordTabBarC = [AppDelegate sharedAppDelegate].topViewController.tabBarController;
  626. [_videoDynamicViewC videoDynamicView];
  627. [_videoDynamicViewC showPublishDynamic];
  628. // 开启IQ
  629. _videoDynamicViewC.title = ASLocalizedString(@"发布短视频");
  630. _videoDynamicViewC.navigationItem.title = ASLocalizedString(@"发布短视频");
  631. _videoDynamicViewC.navigationController.navigationBar.tintColor =kAppGrayColor1;
  632. self.navigationController.navigationItem.title = ASLocalizedString(@"发布短视频");
  633. //改变颜色 必须跳转后
  634. _videoDynamicViewC.navigationController.navigationBar.hidden = NO;
  635. [_videoDynamicViewC.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:kAppGrayColor1}];
  636. _videoDynamicViewC.isOpenIQKeyboardManager = YES;
  637. [self.navigationController popToRootViewControllerAnimated:YES];
  638. }
  639. //是否已认证
  640. -(void)showAuthView{
  641. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:ASLocalizedString(@"您当前还未实名认证,需要认证后才能开始直播")preferredStyle:UIAlertControllerStyleAlert];
  642. UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  643. }];
  644. UIAlertAction *actionConfirm = [UIAlertAction actionWithTitle:ASLocalizedString(@"立即认证")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  645. UserModel *userModel = [GlobalVariables sharedInstance].userModel;
  646. SIdentificationVC *identificationVC = [[SIdentificationVC alloc]init];
  647. identificationVC.user_id = userModel.user_id;
  648. identificationVC.sexString = userModel.sex;
  649. identificationVC.nameString = userModel.nick_name;
  650. [[AppDelegate sharedAppDelegate] pushViewController:identificationVC animated:YES];
  651. }];
  652. [alertController addAction:actionCacel];
  653. [alertController addAction:actionConfirm];
  654. [[AppDelegate sharedAppDelegate].topViewController presentViewController:alertController animated:YES completion:nil];
  655. }
  656. - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(nonnull UIViewController *)viewController
  657. {
  658. NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
  659. // [self showNesBarRedNum];
  660. // if (index == 2) {//点击直播
  661. // [self onClickedCenterTabBar];
  662. //// IMALoginParam *loginParam = [IMALoginParam loadFromLocal];
  663. //// if (loginParam.isAgree ==1)
  664. //// {
  665. //// PublishLivestViewController *pvc = [[PublishLivestViewController alloc] init];
  666. //// [[AppDelegate sharedAppDelegate] presentViewController:pvc animated:YES completion:^{
  667. ////
  668. //// }];
  669. //// }
  670. //// else
  671. //// {
  672. //// AgreementViewController *agreeVC = [AgreementViewController webControlerWithUrlStr:[GlobalVariables sharedInstance].appModel.agreement_link isShowIndicator:YES isShowNavBar:YES];
  673. //// [[AppDelegate sharedAppDelegate] presentViewController:agreeVC animated:YES completion:^{
  674. ////
  675. //// }];
  676. //// }
  677. // return NO;
  678. // }
  679. #if kSupportH5Shopping
  680. NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
  681. if (index == 0)
  682. {
  683. [APP_DELEGATE beginEnterMianUI];
  684. return NO;
  685. }
  686. return YES;
  687. #else
  688. return YES;
  689. #endif
  690. }
  691. -(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
  692. // [self showNesBarRedNum];
  693. // switch (item.tag) {
  694. // case 1:
  695. // NSLog(@"tab bar: 1");
  696. // break;
  697. //
  698. // case 2:
  699. // NSLog(@"tab bar: 2");
  700. // break;
  701. // }
  702. }
  703. -(BogoYounthModePopView *)youthView{
  704. if (!_youthView) {
  705. _youthView = [[BogoYounthModePopView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(331))];
  706. WeakSelf
  707. _youthView.clickInYounthBlock = ^(BOOL isComeIn) {
  708. // BogoYouthModeViewController *vc = [BogoYouthModeViewController new];
  709. //
  710. // [[AppDelegate sharedAppDelegate]pushViewController:vc animated:YES];
  711. //// [weakSelf.navigationController pushViewController:vc animated:YES];
  712. // [weakSelf.youthView hide];
  713. };
  714. }
  715. return _youthView;
  716. }
  717. - (void)clickLiveBtn
  718. {
  719. [self startLive];
  720. }
  721. #pragma mark - 语音视频通话
  722. - (void)IMChatMsgNotfication:(NSNotification *)notifcation {
  723. if (![NSThread isMainThread])
  724. {
  725. [self performSelectorOnMainThread:@selector(IMChatMsgNotfication:) withObject:notifcation waitUntilDone:NO];
  726. return;
  727. }
  728. [AudioChatTool.shareInstance receiveCallWithNotification:notifcation];
  729. SIMMsgObj *thatmsg = (SIMMsgObj *) notifcation.object;
  730. if (thatmsg.mMsgType == MSG_PRIVATE_CallAudio || thatmsg.mMsgType == MSG_PRIVATE_CallVideo) {
  731. } else {
  732. //并且还要清除 未读
  733. // [self.mChatFriend ignoreThisUnReadCount];
  734. // [self addOneMsg:thatmsg];
  735. [[AppDelegate sharedAppDelegate] showNesBarRedNum];
  736. }
  737. }
  738. - (void)viewDidAppear:(BOOL)animated {
  739. [super viewDidAppear:animated];
  740. [self judjeAppLaunchSuccess];
  741. }
  742. - (void)judjeAppLaunchSuccess {
  743. if (BGIMLoginManager.sharedInstance.isIMSDKOK && self.adShowFinished) {
  744. AppDelegate.sharedAppDelegate.isLaunchSuccess = YES;
  745. return;
  746. }
  747. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  748. [self judjeAppLaunchSuccess];
  749. });
  750. }
  751. @end