BGTabBarController.m 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  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>
  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. // 创建自定义TabBar,高度为80
  307. CGFloat tabBarHeight = 80;
  308. CGFloat safeAreaBottom = 0;
  309. if (@available(iOS 11.0, *)) {
  310. safeAreaBottom = self.view.safeAreaInsets.bottom;
  311. }
  312. self.customTabBar = [[CustomTabbarView alloc] initWithFrame:CGRectMake(0,
  313. self.view.frame.size.height - tabBarHeight - safeAreaBottom,
  314. self.view.frame.size.width,
  315. tabBarHeight + safeAreaBottom)];
  316. self.customTabBar.delegate = self;
  317. // 根据BGTabBarController中setUpChildViewControllers方法添加TabBar项
  318. // 注意:这里使用的图片名称需要与原项目中的图片资源匹配
  319. // 首页
  320. [self.customTabBar addTabBarItemWithTitle:@"首页"
  321. normalImage:@"ic_tab_live_normal"
  322. selectedImage:@"ic_tab_live_selected"];
  323. // 派对
  324. [self.customTabBar addTabBarItemWithTitle:@"派对"
  325. normalImage:@"ic_tab_party_normal"
  326. selectedImage:@"ic_tab_party_sel"];
  327. // 动态
  328. [self.customTabBar addTabBarItemWithTitle:@"动态"
  329. normalImage:@"ic_tab_moment_normal"
  330. selectedImage:@"ic_tab_moment_sel"];
  331. // 消息
  332. [self.customTabBar addTabBarItemWithTitle:@"消息"
  333. normalImage:@"ic_tab_message_normal"
  334. selectedImage:@"ic_tab_message_sel"];
  335. // 我的
  336. [self.customTabBar addTabBarItemWithTitle:@"我的"
  337. normalImage:@"ic_tab_me_normal"
  338. selectedImage:@"ic_tab_me_sel"];
  339. [self.view addSubview:self.customTabBar];
  340. }
  341. #pragma mark - CustomTabbarViewDelegate
  342. - (void)customTabbarView:(CustomTabbarView *)tabbarView didSelectItemAtIndex:(NSInteger)index {
  343. NSLog(@"选中了第%ld个TabBar项", (long)index);
  344. // 这里可以添加切换视图控制器的逻辑
  345. switch (index) {
  346. case 0:
  347. NSLog(@"切换到首页");
  348. // 例如:[self showHomeViewController];
  349. break;
  350. case 1:
  351. NSLog(@"切换到派对");
  352. // 例如:[self showPartyViewController];
  353. break;
  354. case 2:
  355. NSLog(@"切换到动态");
  356. // 例如:[self showMomentViewController];
  357. break;
  358. case 3:
  359. NSLog(@"切换到消息");
  360. // 例如:[self showMessageViewController];
  361. break;
  362. case 4:
  363. NSLog(@"切换到我的");
  364. // 例如:[self showMineViewController];
  365. break;
  366. default:
  367. break;
  368. }
  369. }
  370. //-(void)showNesBarRedNum{
  371. //
  372. // dispatch_async(dispatch_get_main_queue(), ^{
  373. //
  374. // UITabBarItem *itme = [self.tabBar.items objectAtIndex:3];
  375. // SFriendObj *xxx = nil;
  376. //
  377. // // [SFriendObj getMyFriendMsgList:0
  378. // // lastObj:xxx
  379. // // block:^(SResBase *resb, NSArray *all, int unReadNum) {
  380. // NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  381. // [parmDict setObject:@"dynamic" forKey:@"ctl"];
  382. // [parmDict setObject:@"unread_messages" forKey:@"act"];
  383. //
  384. // [[NetHttpsManager manager]POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  385. //
  386. // if ([[responseJson valueForKey:@"status"]integerValue] == 1) {
  387. //
  388. // BogoNewsTabNumModel *model = [BogoNewsTabNumModel modelWithDictionary:[responseJson valueForKey:@"data"]];
  389. //
  390. //
  391. // // if ((model.bzone_reply + model.bzone_like) == 0) {
  392. // // itme.badgeValue = nil;
  393. // // }else{
  394. // //
  395. // //
  396. // // }
  397. // [SFriendObj getAllUnReadCountComplete:^(int num) {
  398. // if ((model.bzone_reply + model.bzone_like + num) == 0) {
  399. // itme.badgeValue = nil;
  400. // }else{
  401. // itme.badgeValue = [NSString stringWithFormat:@"%ld",model.bzone_reply + model.bzone_like + num + model.msg.count];
  402. // }
  403. //
  404. // }];
  405. // // self.headView.model = model;
  406. //
  407. // }
  408. //
  409. // } FailureBlock:^(NSError *error) {
  410. //
  411. // }];
  412. // });
  413. //
  414. //
  415. //
  416. //}
  417. -(UIImage *)imageResize :(UIImage*)img andResizeTo:(CGSize)newSize withTop:(CGFloat)top
  418. {
  419. CGFloat scale = [[UIScreen mainScreen]scale];
  420. //UIGraphicsBeginImageContext(newSize);
  421. UIGraphicsBeginImageContextWithOptions(newSize, NO, scale);
  422. [img drawInRect:CGRectMake(0,top,newSize.width,newSize.height)];
  423. UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
  424. UIGraphicsEndImageContext();
  425. return newImage;
  426. }
  427. #pragma mark - 添加子控制器
  428. - (UIViewController *)addChildViewController:(UIViewController *)childController image:(NSString *)image seletedImage:(NSString *)selectedImage title:(NSString *)title
  429. {
  430. // if (![BGUtils isBlankString:title])
  431. // {
  432. childController.title = title;
  433. // NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
  434. // normalAttrs[NSForegroundColorAttributeName] = kAppGrayColor3;
  435. // [childController.tabBarItem setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
  436. //
  437. // NSMutableDictionary *selectedAtrrs = [NSMutableDictionary dictionary];
  438. // selectedAtrrs[NSForegroundColorAttributeName] = UIColorFromRGB(0x4BC8FC);
  439. // [childController.tabBarItem setTitleTextAttributes:selectedAtrrs forState:UIControlStateSelected];
  440. // childController.tabBarItem.imageInsets = UIEdgeInsetsMake(12, 12, 12, 12);
  441. // childController.tabBarItem.imageInsets = UIEdgeInsetsMake(-10, 0, -5, 0);
  442. // childController.tabBarItem.imageInsets = UIEdgeInsetsMake(-10, 0, -5, 0);
  443. // }
  444. // else
  445. // {
  446. // childController.tabBarItem.imageInsets = UIEdgeInsetsMake(-16, 0, -5, 0);
  447. // }
  448. // 设置图片
  449. // if ([title isEqualToString:@""]) {
  450. //// UIImage *imageS = [[self imageResize:[UIImage imageNamed:image] andResizeTo:CGSizeMake(50, 50)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  451. //// [childController.tabBarItem setImage:imageS];
  452. //// [imageS drawInRect:CGRectMake(-10,0,50,50)];
  453. // [childController.tabBarItem setImage:[[self imageResize:[UIImage imageNamed:image] andResizeTo:CGSizeMake(kRealValue(45), kRealValue(45)) withTop:0] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  454. // }else{
  455. // UITabBarItem* itm= [[UITabBarItem alloc] initWithTitle:title image:[UIImage imageNamed:image] selectedImage:[UIImage imageNamed:selectedImage]];
  456. // childController.tabBarItem = itm;
  457. // [childController.tabBarItem setImage:[[self imageResize:[UIImage imageNamed:image] andResizeTo:CGSizeMake(20, 20) withTop:0] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  458. // [childController.tabBarItem setSelectedImage:[[self imageResize:[UIImage imageNamed:selectedImage] andResizeTo:CGSizeMake(20, 20) withTop:0] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  459. // }
  460. // 导航条
  461. BGNavigationController *nav = [[BGNavigationController alloc] initWithRootViewController:childController];
  462. [self addChildViewController:nav];
  463. return childController;
  464. }
  465. //- (void)setupTabBar
  466. //{
  467. // BGTabBar *tabbar = [[BGTabBar alloc] init];
  468. // tabbar.backgroundColor = kWhiteColor;
  469. // [self setValue:tabbar forKey:@"tabBar"];
  470. // FWWeakify(self)
  471. // [tabbar setCenterBtnClickBlock:^{
  472. // FWStrongify(self)
  473. // [self onClickedCenterTabBar];
  474. // }];
  475. //}
  476. - (void)startLive {
  477. if ([GlobalVariables sharedInstance].appModel.must_authentication.intValue == 1) {
  478. if ([GlobalVariables sharedInstance].userModel.is_authentication.intValue != 2) {
  479. [self showAuthView];
  480. return;
  481. }
  482. }
  483. IMALoginParam *loginParam = [IMALoginParam loadFromLocal];
  484. if (loginParam.isAgree ==1)
  485. {
  486. if (AppDelegate.sharedAppDelegate.isInAudioVideoChatVc) {
  487. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"通话中,请结束通话后再试")];
  488. return;
  489. }
  490. PublishLivestViewController *pvc = [[PublishLivestViewController alloc] init];
  491. [[AppDelegate sharedAppDelegate] presentViewController:pvc animated:YES completion:^{
  492. }];
  493. }
  494. else
  495. {
  496. AgreementViewController *agreeVC = [AgreementViewController webControlerWithUrlStr:[GlobalVariables sharedInstance].appModel.agreement_link isShowIndicator:YES isShowNavBar:YES];
  497. [[AppDelegate sharedAppDelegate] presentViewController:agreeVC animated:YES completion:^{
  498. }];
  499. }
  500. }
  501. #pragma mark 点击直播
  502. - (void)onClickedCenterTabBar
  503. {
  504. // PopMenuCenter *popMenuCenter = [PopMenuCenter sharePopMenuCenter];
  505. // [popMenuCenter setTabBarC:self];
  506. // [popMenuCenter setStPopMenuShowState:STPopMenuShow];
  507. NSArray *objs = [[NSBundle mainBundle]loadNibNamed:@"HMCenterPopView" owner:nil options:nil];
  508. self.popView = objs.firstObject;
  509. [self setUpLocalizationStringForView:self.popView];
  510. FWWeakify(self)
  511. [self.popView setClickPopViewBtnBlock:^(HMCenterPopViewBtnType type) {
  512. FWStrongify(self)
  513. switch (type) {
  514. case HMCenterPopViewBtnTypeLive:
  515. {
  516. [self startLive];
  517. }
  518. break;
  519. case HMCenterPopViewBtnTypeVideo:
  520. {
  521. [self showDynamicVC];
  522. }
  523. break;
  524. case HMCenterPopViewBtnTypeClose:
  525. break;
  526. default:
  527. break;
  528. }
  529. }];
  530. [self.popView show:[UIApplication sharedApplication].keyWindow];
  531. }
  532. -(void)showDynamicVC{
  533. self.videoDynamicViewC = (VideoDynamicViewC *)[VideoDynamicViewC showSTBaseViewCOnSuperViewC:self.selectedViewController
  534. andFrameRect:CGRectMake(0, 0, kScreenW, kScreenH)
  535. andSTViewCTransitionType:STViewCTransitionTypeOfModal
  536. andComplete:^(BOOL finished,
  537. STBaseViewC *stBaseViewC) {
  538. }];
  539. self.videoDynamicViewC.recordTabBarC = self;
  540. [self.videoDynamicViewC videoDynamicView];
  541. // 开启IQ
  542. self.videoDynamicViewC.isOpenIQKeyboardManager = YES;
  543. // 加载View层
  544. //[videoDynamicViewC graphicDynamicView];
  545. //跳转
  546. //找到当前ViewC
  547. UIViewController *currentViewC = self.selectedViewController.childViewControllers[0];
  548. //TabBarc隐藏
  549. currentViewC.hidesBottomBarWhenPushed=YES;
  550. currentViewC.navigationController.navigationBar.tintColor = kAppGrayColor1;
  551. self.videoDynamicViewC.navigationController.navigationBar.hidden = NO;
  552. self.videoDynamicViewC.title = ASLocalizedString(@"发布短视频");
  553. self.videoDynamicViewC.navigationController.navigationBar.tintColor =kAppGrayColor1;
  554. //改变颜色 必须跳转后
  555. self.videoDynamicViewC.navigationController.navigationBar.hidden = NO;
  556. [self.videoDynamicViewC.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:kAppGrayColor1}];
  557. currentViewC.hidesBottomBarWhenPushed=NO;
  558. UIActionSheet *headImgSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  559. [headImgSheet addButtonWithTitle:ASLocalizedString(@"拍摄视频")];
  560. [headImgSheet addButtonWithTitle:ASLocalizedString(@"相册中获取视频")];
  561. [headImgSheet addButtonWithTitle:ASLocalizedString(@"取消")];
  562. headImgSheet.cancelButtonIndex = headImgSheet.numberOfButtons-1;
  563. headImgSheet.delegate = self;
  564. [headImgSheet showInView:[UIApplication sharedApplication].keyWindow];
  565. }
  566. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger) buttonIndex
  567. {
  568. if (buttonIndex == 0) {
  569. //如果短视频key为空,调本地视频
  570. if ([BGUtils isBlankString:[GlobalVariables sharedInstance].appModel.tencent_video_sdk_key]) {
  571. [[AppDelegate sharedAppDelegate]pushViewController:self.videoDynamicViewC animated:YES];
  572. [self.videoDynamicViewC ceartVideoViewWithType:(int)buttonIndex];
  573. return;
  574. }
  575. #warning 暂时注释
  576. UGCKitRecordViewController *recordViewController = [[UGCKitRecordViewController alloc] initWithConfig:nil theme:nil];
  577. recordViewController.completion = ^(UGCKitResult *result) {
  578. if (result.cancelled) {
  579. [[AppDelegate sharedAppDelegate]popViewController];
  580. // UGCKitEditViewController *vc= [UGCKitEditViewController new];
  581. // [[AppDelegate sharedAppDelegate]pushViewController:vc];
  582. }else{
  583. [self showEditViewController:result rotation:TCEditRotation0 inNavigationController:[AppDelegate sharedAppDelegate].topViewController.navigationController];
  584. // self.navigationController];
  585. }
  586. };
  587. // TCVideoRecordViewController *vc = [[TCVideoRecordViewController alloc] init];
  588. [[AppDelegate sharedAppDelegate] pushViewController:recordViewController animated:YES];
  589. return;
  590. }else if (buttonIndex == 1){
  591. [[AppDelegate sharedAppDelegate]pushViewController:self.videoDynamicViewC animated:YES];
  592. [self.videoDynamicViewC ceartVideoViewWithType:(int)buttonIndex];
  593. }
  594. }
  595. - (void)showEditViewController:(UGCKitResult *)result
  596. rotation:(TCEditRotation)rotation
  597. inNavigationController:(UINavigationController *)nav
  598. {
  599. UGCKitMedia *media = result.media;
  600. UGCKitEditConfig *config = [[UGCKitEditConfig alloc] init];
  601. config.rotation = (TCEditRotation)(rotation / 90);
  602. UIImage *tailWatermarkImage = [UIImage imageNamed:@"tcloud_logo"];
  603. TXVideoInfo *info = [TXVideoInfoReader getVideoInfoWithAsset:media.videoAsset];
  604. float w = 0.15;
  605. float x = (1.0 - w) / 2.0;
  606. float width = w * info.width;
  607. float height = width * tailWatermarkImage.size.height / tailWatermarkImage.size.width;
  608. float y = (info.height - height) / 2 / info.height;
  609. config.tailWatermark = [UGCKitWatermark watermarkWithImage:tailWatermarkImage
  610. frame:CGRectMake(x, y, w, 0)
  611. duration:2];
  612. __weak __typeof(self) wself = self;
  613. UGCKitEditViewController *vc = [[UGCKitEditViewController alloc] initWithMedia:media
  614. config:config
  615. theme:nil];
  616. __weak UGCKitEditViewController *weakEditController = vc;
  617. __weak UINavigationController *weakNavigation = nav;
  618. vc.onTapNextButton = ^(void (^finish)(BOOL)) {
  619. // [wself showEditFinishOptionsWithResult:result editController:weakEditController finishBloack:finish];
  620. finish(YES);
  621. };
  622. vc.completion = ^(UGCKitResult *result) {
  623. __strong __typeof(wself) self = wself; if (self == nil) { return; }
  624. if (result.cancelled) {
  625. [[AppDelegate sharedAppDelegate]popViewController];
  626. } else {
  627. [_videoDynamicViewC upLoadVideoUrl:vc.videoOutputPath];
  628. [[AppDelegate sharedAppDelegate]popToRootViewController];
  629. [[AppDelegate sharedAppDelegate]pushViewController:_videoDynamicViewC animated:YES];
  630. [self showVideoDynamicViewC];
  631. }
  632. [[NSUserDefaults standardUserDefaults] setObject:nil forKey:CACHE_PATH_LIST];
  633. // [self dismissViewControllerAnimated:YES completion:nil];
  634. };
  635. [[AppDelegate sharedAppDelegate]pushViewController:vc animated:YES];
  636. // [nav pushViewController:vc animated:YES];
  637. }
  638. #pragma mark - 5 - 视频动态页面
  639. -(void)showVideoDynamicViewC
  640. {
  641. _videoDynamicViewC = (VideoDynamicViewC *)[VideoDynamicViewC showSTBaseViewCOnSuperViewC:[AppDelegate sharedAppDelegate].topViewController.tabBarController.selectedViewController
  642. andFrameRect:CGRectMake(0, 0, kScreenW, kScreenH)
  643. andSTViewCTransitionType:STViewCTransitionTypeOfModal
  644. andComplete:^(BOOL finished,
  645. STBaseViewC *stBaseViewC) {
  646. }];
  647. _videoDynamicViewC.recordTabBarC = [AppDelegate sharedAppDelegate].topViewController.tabBarController;
  648. [_videoDynamicViewC videoDynamicView];
  649. [_videoDynamicViewC showPublishDynamic];
  650. // 开启IQ
  651. _videoDynamicViewC.title = ASLocalizedString(@"发布短视频");
  652. _videoDynamicViewC.navigationItem.title = ASLocalizedString(@"发布短视频");
  653. _videoDynamicViewC.navigationController.navigationBar.tintColor =kAppGrayColor1;
  654. self.navigationController.navigationItem.title = ASLocalizedString(@"发布短视频");
  655. //改变颜色 必须跳转后
  656. _videoDynamicViewC.navigationController.navigationBar.hidden = NO;
  657. [_videoDynamicViewC.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:kAppGrayColor1}];
  658. _videoDynamicViewC.isOpenIQKeyboardManager = YES;
  659. [self.navigationController popToRootViewControllerAnimated:YES];
  660. }
  661. //是否已认证
  662. -(void)showAuthView{
  663. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:ASLocalizedString(@"您当前还未实名认证,需要认证后才能开始直播")preferredStyle:UIAlertControllerStyleAlert];
  664. UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  665. }];
  666. UIAlertAction *actionConfirm = [UIAlertAction actionWithTitle:ASLocalizedString(@"立即认证")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  667. UserModel *userModel = [GlobalVariables sharedInstance].userModel;
  668. SIdentificationVC *identificationVC = [[SIdentificationVC alloc]init];
  669. identificationVC.user_id = userModel.user_id;
  670. identificationVC.sexString = userModel.sex;
  671. identificationVC.nameString = userModel.nick_name;
  672. [[AppDelegate sharedAppDelegate] pushViewController:identificationVC animated:YES];
  673. }];
  674. [alertController addAction:actionCacel];
  675. [alertController addAction:actionConfirm];
  676. [[AppDelegate sharedAppDelegate].topViewController presentViewController:alertController animated:YES completion:nil];
  677. }
  678. - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(nonnull UIViewController *)viewController
  679. {
  680. NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
  681. // [self showNesBarRedNum];
  682. // if (index == 2) {//点击直播
  683. // [self onClickedCenterTabBar];
  684. //// IMALoginParam *loginParam = [IMALoginParam loadFromLocal];
  685. //// if (loginParam.isAgree ==1)
  686. //// {
  687. //// PublishLivestViewController *pvc = [[PublishLivestViewController alloc] init];
  688. //// [[AppDelegate sharedAppDelegate] presentViewController:pvc animated:YES completion:^{
  689. ////
  690. //// }];
  691. //// }
  692. //// else
  693. //// {
  694. //// AgreementViewController *agreeVC = [AgreementViewController webControlerWithUrlStr:[GlobalVariables sharedInstance].appModel.agreement_link isShowIndicator:YES isShowNavBar:YES];
  695. //// [[AppDelegate sharedAppDelegate] presentViewController:agreeVC animated:YES completion:^{
  696. ////
  697. //// }];
  698. //// }
  699. // return NO;
  700. // }
  701. #if kSupportH5Shopping
  702. NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
  703. if (index == 0)
  704. {
  705. [APP_DELEGATE beginEnterMianUI];
  706. return NO;
  707. }
  708. return YES;
  709. #else
  710. return YES;
  711. #endif
  712. }
  713. -(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
  714. // [self showNesBarRedNum];
  715. // switch (item.tag) {
  716. // case 1:
  717. // NSLog(@"tab bar: 1");
  718. // break;
  719. //
  720. // case 2:
  721. // NSLog(@"tab bar: 2");
  722. // break;
  723. // }
  724. }
  725. -(BogoYounthModePopView *)youthView{
  726. if (!_youthView) {
  727. _youthView = [[BogoYounthModePopView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(331))];
  728. WeakSelf
  729. _youthView.clickInYounthBlock = ^(BOOL isComeIn) {
  730. // BogoYouthModeViewController *vc = [BogoYouthModeViewController new];
  731. //
  732. // [[AppDelegate sharedAppDelegate]pushViewController:vc animated:YES];
  733. //// [weakSelf.navigationController pushViewController:vc animated:YES];
  734. // [weakSelf.youthView hide];
  735. };
  736. }
  737. return _youthView;
  738. }
  739. - (void)clickLiveBtn
  740. {
  741. [self startLive];
  742. }
  743. #pragma mark - 语音视频通话
  744. - (void)IMChatMsgNotfication:(NSNotification *)notifcation {
  745. if (![NSThread isMainThread])
  746. {
  747. [self performSelectorOnMainThread:@selector(IMChatMsgNotfication:) withObject:notifcation waitUntilDone:NO];
  748. return;
  749. }
  750. [AudioChatTool.shareInstance receiveCallWithNotification:notifcation];
  751. SIMMsgObj *thatmsg = (SIMMsgObj *) notifcation.object;
  752. if (thatmsg.mMsgType == MSG_PRIVATE_CallAudio || thatmsg.mMsgType == MSG_PRIVATE_CallVideo) {
  753. } else {
  754. //并且还要清除 未读
  755. // [self.mChatFriend ignoreThisUnReadCount];
  756. // [self addOneMsg:thatmsg];
  757. [[AppDelegate sharedAppDelegate] showNesBarRedNum];
  758. }
  759. }
  760. - (void)viewDidAppear:(BOOL)animated {
  761. [super viewDidAppear:animated];
  762. [self judjeAppLaunchSuccess];
  763. }
  764. - (void)judjeAppLaunchSuccess {
  765. if (BGIMLoginManager.sharedInstance.isIMSDKOK && self.adShowFinished) {
  766. AppDelegate.sharedAppDelegate.isLaunchSuccess = YES;
  767. return;
  768. }
  769. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  770. [self judjeAppLaunchSuccess];
  771. });
  772. }
  773. @end