RQMainTabBarViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // RQMainTabBarViewController.m
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/21.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. // 主界面控制器
  8. #import "RQMainTabBarViewController.h"
  9. #import "RQBaseNavigationController.h"
  10. #import <ZFPlayer/ZFLandscapeRotationManager.h>
  11. @interface RQMainTabBarViewController ()
  12. @property (nonatomic, readonly, strong) RQMainTabBarViewModel *viewModel;
  13. @end
  14. @implementation RQMainTabBarViewController
  15. @dynamic viewModel;
  16. /// 在这里写支持的旋转方向,为了防止横屏方向,应用启动时候界面变为横屏模式
  17. - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
  18. ZFInterfaceOrientationMask orientationMask = [ZFLandscapeRotationManager supportedInterfaceOrientationsForWindow:window];
  19. if (orientationMask != ZFInterfaceOrientationMaskUnknow) {
  20. return (UIInterfaceOrientationMask)orientationMask;
  21. }
  22. UIViewController *current_VC = RQControllerHelper.currentViewController;
  23. if([current_VC isKindOfClass:[NYExaminationViewController class]]||
  24. [current_VC isKindOfClass:[NYExaminationRoomViewController class]]){
  25. return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskPortrait;
  26. }
  27. /// 这里是非播放器VC支持的方向
  28. return UIInterfaceOrientationMaskPortrait;
  29. }
  30. #pragma mark - System
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. // 初始化所有的子控制器
  34. [self rq_setupAllChildViewController];
  35. // set delegate
  36. self.tabBarController.delegate = self;
  37. [self performSelector:@selector(takeExistFreeSch) withObject:nil afterDelay:20];
  38. if(myDelegate.isLogin){
  39. [RQ_VIP_Module isVipWithSubject:0 complete:^(BOOL isVip) {
  40. }];
  41. }
  42. }
  43. - (void)takeExistFreeSch{
  44. if (RQ_USER_MANAGER.isLogin&&![RQ_USER_MANAGER.currentUser.userName containsString:@"游客"]) {
  45. NSLog(@"%@====%@",RQ_COMMON_MANAGER.JSJP_FREE_VIP,RQ_USER_MANAGER.currentUser.city);
  46. //判断地区编号,判断是否已经开通vip,判断这个api是否满足开通
  47. if ([RQ_COMMON_MANAGER.JSJP_FREE_VIP rangeOfString:RQ_USER_MANAGER.currentUser.city].location != NSNotFound) {
  48. // &&!RQStringIsNotEmpty(RQ_VIP_Module.videoVipModel.subject1)&&!RQStringIsNotEmpty(RQ_VIP_Module.videoVipModel.subject4)
  49. [RQ_VIP_Module isVipWithSubject:0 complete:^(BOOL isVip) {
  50. if(!RQStringIsNotEmpty(RQ_VIP_Module.videoVipModel.subject1)&&!RQStringIsNotEmpty(RQ_VIP_Module.videoVipModel.subject4)){
  51. NSString *jxbh = RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.school)? RQ_USER_MANAGER.currentUser.school : @"";
  52. [[RQ_HTTP_Service getExistFreeSch:jxbh] subscribeNext:^(id prepareOrderModel) {
  53. NSLog(@"%@",prepareOrderModel);
  54. [RQ_ALERTVIEW_MANAGER showAlertWithAlertType:RQAlertType_AD_SONG title:@"" message:@"车管所实题,观看一次广告,即可正常使用。点击观看无反应。请稍等5到10秒。" confirmTitle:@"充值使用" cancelTitle:@"看广告解锁" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  55. [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full];
  56. } cancelAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  57. RQ_VIP_Module.type=1;
  58. [RQ_AD_Module loadRewardvodAd];
  59. }];
  60. } error:^(NSError * _Nullable error) {
  61. }];
  62. }
  63. }];
  64. }
  65. }
  66. }
  67. #pragma mark - Private Method
  68. - (void)rq_setupAllChildViewController {
  69. NSArray *titlesArray = @[@"考试", @"社区", @"计时",@"真人讲解", @"我的"];
  70. NSArray *imageNamesArray = @[@"考试灰",
  71. @"tabbarImg2",
  72. @"计时灰",
  73. @"真人讲解灰",
  74. @"我的灰"
  75. ];
  76. NSArray *selectedImageNamesArray = @[@"考试蓝",
  77. @"tabbarImg2",
  78. @"计时蓝",
  79. @"真人讲解蓝",
  80. @"我的蓝"
  81. ];
  82. /// 首页-考试
  83. RQBaseNavigationController *homePageNavigationController = ({
  84. RQHomePageViewController *homePageViewController = [[RQHomePageViewController alloc] initWithViewModel:self.viewModel.homePageViewModel];
  85. RQTabBarItemTagType tagType = RQTabBarItemTagTypeHomePage;
  86. /// 配置
  87. [self rq_configViewController:homePageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
  88. /// 添加到导航栏的栈底控制器
  89. homePageViewController.hidesBottomBarWhenPushed = NO;
  90. [[RQBaseNavigationController alloc] initWithRootViewController:homePageViewController];
  91. });
  92. /// 计时
  93. RQBaseNavigationController *timePageNavigationController = ({
  94. // TimingBaseVC *timePageViewController = [[TimingBaseVC alloc] initWithViewModel:self.viewModel.timeViewModel];
  95. RQTimeViewController *timePageViewController = [[RQTimeViewController alloc] initWithViewModel:self.viewModel.timeViewModel];
  96. RQTabBarItemTagType tagType = RQTabBarItemTagTypeTime;
  97. /// 配置
  98. [self rq_configViewController:timePageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
  99. /// 添加到导航栏的栈底控制器
  100. timePageViewController.hidesBottomBarWhenPushed = NO;
  101. [[RQBaseNavigationController alloc] initWithRootViewController:timePageViewController];
  102. });
  103. ///真人讲解
  104. RQBaseNavigationController *livideoNavigationController = ({
  105. NSIndexPath *indexPath = [NSIndexPath indexPathWithIndex:0];
  106. NYLIVideoDetailViewModel *videoDetailViewModel = [[NYLIVideoDetailViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  107. RQVideoItemIndexKey : @(0),
  108. RQVideoItemIndexPathKey : indexPath,
  109. RQHomePageSubjectTypeKey : @(RQHomePageSubjectType_SubjectOne_LI),
  110. }];
  111. NYLIVideoDetailViewController *livideoDetailViewController = [[NYLIVideoDetailViewController alloc] initWithViewModel:videoDetailViewModel];
  112. livideoDetailViewController.tagTyp = RQTabBarItemTagTypeLi;
  113. RQTabBarItemTagType tagType = RQTabBarItemTagTypeLi;
  114. /// 配置
  115. [self rq_configViewController:livideoDetailViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
  116. /// 添加到导航栏的栈底控制器
  117. livideoDetailViewController.hidesBottomBarWhenPushed = NO;
  118. [[RQBaseNavigationController alloc] initWithRootViewController:livideoDetailViewController];
  119. });
  120. /// 我的
  121. RQBaseNavigationController *profileNavigationController = ({
  122. //#if DEBUG
  123. RQProfileViewController *profileViewController = [[RQProfileViewController alloc] initWithViewModel:self.viewModel.profileViewModel];
  124. //#else
  125. // FunctionVC *profileViewController = [[FunctionVC alloc] initWithViewModel:self.viewModel.profileViewModel];
  126. //#endif
  127. RQTabBarItemTagType tagType = RQTabBarItemTagTypeProfile;
  128. /// 配置
  129. [self rq_configViewController:profileViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
  130. profileViewController.hidesBottomBarWhenPushed = NO;
  131. [[RQBaseNavigationController alloc] initWithRootViewController:profileViewController];
  132. });
  133. /// 添加到tabBarController的子视图
  134. // self.tabBarController.viewControllers = @[homePageNavigationController, profileNavigationController];
  135. self.tabBarController.viewControllers = @[homePageNavigationController, timePageNavigationController,livideoNavigationController, profileNavigationController];//开启计时tab
  136. // if(RQ_USER_MANAGER.currentUser.stuNum){
  137. // NSLog(@"%@",RQ_USER_MANAGER.currentUser.stuNum);
  138. // if ((RQ_USER_MANAGER.isLogin&&![RQ_USER_MANAGER.currentUser.stuNum isEqualToString:@""])||
  139. // [RQ_USER_MANAGER.currentUser.loginCode isEqualToString:@"350881199205290949"]) {//已经,登录并且stunum不为空
  140. // self.tabBarController.viewControllers = @[homePageNavigationController, timePageNavigationController, profileNavigationController];//开启计时tab
  141. // }
  142. // }
  143. /// 配置栈底
  144. [RQSharedAppDelegate.navigationControllerStack pushNavigationController:homePageNavigationController];
  145. }
  146. - (void)rq_configViewController:(UIViewController *)viewController imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName title:(NSString *)title itemTag:(RQTabBarItemTagType)tagType {
  147. UIImage *image = [[UIImage imageNamed:imageName] tint:[UIColor grayColor]];
  148. image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  149. viewController.tabBarItem.image = image;
  150. viewController.tabBarItem.tag = tagType;
  151. UIImage *selectedImage = [[UIImage imageNamed:selectedImageName] tint:RQ_MAIN_COLOR];
  152. selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  153. viewController.tabBarItem.selectedImage = selectedImage;
  154. viewController.tabBarItem.title = title;
  155. NSDictionary *normalAttr = @{NSForegroundColorAttributeName:RQ_MAIN_TEXT_COLOR_2,
  156. NSFontAttributeName:RQRegularFont_15};
  157. NSDictionary *selectedAttr = @{NSForegroundColorAttributeName:RQ_MAIN_COLOR,
  158. NSFontAttributeName:RQRegularFont_15};
  159. [viewController.tabBarItem setTitleTextAttributes:normalAttr forState:UIControlStateNormal];
  160. [viewController.tabBarItem setTitleTextAttributes:selectedAttr forState:UIControlStateSelected];
  161. [viewController.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, 0)];
  162. [viewController.tabBarItem setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  163. }
  164. #pragma mark - UITabBarControllerDelegate
  165. - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
  166. if ([viewController.tabBarItem.title isEqualToString:@"我的"] || [viewController.tabBarItem.title isEqualToString:@"计时"]) {
  167. return RQ_USER_MANAGER.isShouldLogin;
  168. } else {
  169. return YES;
  170. }
  171. }
  172. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  173. NSLog(@"viewController %@ %zd",viewController,viewController.tabBarItem.tag);
  174. [RQSharedAppDelegate.navigationControllerStack popNavigationController];
  175. [RQSharedAppDelegate.navigationControllerStack pushNavigationController:(UINavigationController *)viewController];
  176. if ([viewController.tabBarItem.title isEqualToString:@"计时"] && [RQ_USER_MANAGER isQzVideo] && !RQ_COMMON_MANAGER.isQzLook) {
  177. RQNewFeatureViewModel *newFeatureViewModel = [[RQNewFeatureViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewCommonValueKey : @"quanzhou"}];
  178. [RQ_APPDELEGATE.services presentViewModel:newFeatureViewModel animated:YES completion:^{
  179. }];
  180. }
  181. }
  182. @end