RQSpecialPractiseViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // RQSpecialPractiseViewController.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/6/21.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQSpecialPractiseViewController.h"
  9. @interface RQSpecialPractiseViewController ()
  10. /// viewModel
  11. @property (nonatomic, readonly, strong) RQHoursBeforeExamHomeViewModel *viewModel;
  12. @end
  13. @implementation RQSpecialPractiseViewController
  14. @dynamic viewModel;
  15. #pragma mark - SystemMethod
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. /// 初始化
  19. [self rq_setup];
  20. }
  21. - (void)viewDidLayoutSubviews {
  22. [super viewDidLayoutSubviews];
  23. self.view.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT);
  24. }
  25. #pragma mark - PrivateMethods
  26. /// 初始化
  27. - (void)rq_setup {
  28. /// set up ...
  29. self.collectionView.bounces = NO;
  30. self.collectionView.backgroundColor = UIColor.clearColor;
  31. if(RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne && !RQ_VIP_Module.isSubject1Vip){
  32. [RQ_AD_MANAGER loadAdWithAdType:RQADType_InterstitialSplash customView:nil];//广告
  33. }
  34. if(RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectFour && !RQ_VIP_Module.isSubject4Vip){
  35. [RQ_AD_MANAGER loadAdWithAdType:RQADType_InterstitialSplash customView:nil];//广告
  36. }
  37. }
  38. #pragma mark - OverrideMethods
  39. /// 配置tableView的区域
  40. - (UIEdgeInsets)contentInset {
  41. return UIEdgeInsetsMake((RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT), 0, RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT, 0);
  42. }
  43. /// RQHomePageSectionZeroGroupViewModel
  44. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  45. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  46. RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  47. if ([itemViewModel isKindOfClass:[RQSpecialPracticeItemViewModel class]]) {
  48. RQSpecialPracticeCell *cell = [RQSpecialPracticeCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  49. return cell;
  50. } else if ([itemViewModel isKindOfClass:[RQSpecialAddItemViewModel class]]) {
  51. RQSpecialAddCell *cell = [RQSpecialAddCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  52. return cell;
  53. } else if ([itemViewModel isKindOfClass:[RQSpecialQuestionItemViewModel class]]) {
  54. RQSpecialQuestionCell *cell = [RQSpecialQuestionCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  55. return cell;
  56. } else if ([itemViewModel isKindOfClass:[RQSpecialPointItemViewModel class]]) {
  57. RQSpecialPointCell *cell = [RQSpecialPointCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  58. return cell;
  59. } else {
  60. return [super collectionView:collectionView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
  61. }
  62. }
  63. - (void)configureCell:(UICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  64. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  65. RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  66. if ([itemViewModel isKindOfClass:[RQSpecialPracticeItemViewModel class]]) {
  67. RQSpecialPracticeCell *specialPracticeCell = (RQSpecialPracticeCell *)cell;
  68. [specialPracticeCell bindViewModel:object];
  69. } else if ([itemViewModel isKindOfClass:[RQSpecialAddItemViewModel class]]) {
  70. RQSpecialAddCell *specialAddCell = (RQSpecialAddCell *)cell;
  71. [specialAddCell bindViewModel:object];
  72. } else if ([itemViewModel isKindOfClass:[RQSpecialQuestionItemViewModel class]]) {
  73. RQSpecialQuestionCell *specialQuestionCell = (RQSpecialQuestionCell *)cell;
  74. [specialQuestionCell bindViewModel:object];
  75. } else if ([itemViewModel isKindOfClass:[RQSpecialPointItemViewModel class]]) {
  76. RQSpecialPointCell *specialPointCell = (RQSpecialPointCell *)cell;
  77. [specialPointCell bindViewModel:object];
  78. } else {
  79. [super configureCell:cell atIndexPath:indexPath withObject:object];
  80. }
  81. }
  82. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  83. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
  84. RQCommonCollectionItemViewModel *itemViewModel = (groupViewModel.itemViewModels.count > 0)? groupViewModel.itemViewModels.firstObject : nil;
  85. if (itemViewModel) {
  86. if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]] || [self.viewModel.dataSource[section] isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) {
  87. return UIEdgeInsetsMake(0, 16, 0, 16);
  88. } else {
  89. if ([itemViewModel isKindOfClass:[RQSpecialPracticeItemViewModel class]]) {
  90. return UIEdgeInsetsMake(16, 16, 8, 16);
  91. } else if ([itemViewModel isKindOfClass:[RQSpecialAddItemViewModel class]]) {
  92. return UIEdgeInsetsMake(0, 16, 16, 16);
  93. } else if ([itemViewModel isKindOfClass:[RQSpecialQuestionItemViewModel class]]) {
  94. return UIEdgeInsetsMake(0, 16, 16, 16);
  95. } else {
  96. return UIEdgeInsetsZero;
  97. }
  98. }
  99. } else {
  100. return UIEdgeInsetsZero;
  101. }
  102. }
  103. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  104. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
  105. if ([groupViewModel.groupModel.header isEqualToString:@"考点练习"]) {
  106. return 0.f;
  107. } else {
  108. return 8.f;
  109. }
  110. }
  111. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  112. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
  113. if ([groupViewModel.groupModel.header isEqualToString:@"考点练习"]) {
  114. return 0.f;
  115. } else {
  116. return 8.f;
  117. }
  118. }
  119. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  120. @weakify(self)
  121. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  122. // 如果是头视图
  123. if (kind == UICollectionElementKindSectionHeader) {
  124. if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) {
  125. RQHomeSubPageVideoHeaderCollectionReusableView *headerView = [RQHomeSubPageVideoHeaderCollectionReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  126. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  127. [headerView bindViewModel:groupViewModel];
  128. headerView.headerContentLabel.hidden = NO;
  129. headerView.footerContentLabel.hidden = YES;
  130. return headerView;
  131. } else if ([groupViewModel isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) {
  132. RQCommonReusableView *homePageSectionOneHeaderView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  133. RQHomePageSectionOneGroupViewModel *homePageSectionOneGroupViewModel = self.viewModel.dataSource[indexPath.section];
  134. [homePageSectionOneHeaderView bindViewModel:homePageSectionOneGroupViewModel];
  135. homePageSectionOneHeaderView.headerContentLabel.hidden = YES;
  136. homePageSectionOneHeaderView.footerContentLabel.hidden = YES;
  137. homePageSectionOneHeaderView.backgroundColor = UIColor.whiteColor;
  138. return homePageSectionOneHeaderView;
  139. } else {
  140. RQCommonReusableView *headerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  141. RQCommonReusableView *groupViewModel = self.viewModel.dataSource[indexPath.section];
  142. [headerView bindViewModel:groupViewModel];
  143. return headerView;
  144. }
  145. } else {
  146. if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) {
  147. RQCommonReusableView *footerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  148. RQHomeSubPageVideoHeaderGroupViewModel *homeSubPageVideoHeaderGroupViewModel = self.viewModel.dataSource[indexPath.section];
  149. [footerView bindViewModel:homeSubPageVideoHeaderGroupViewModel];
  150. footerView.headerContentLabel.hidden = YES;
  151. if ([homeSubPageVideoHeaderGroupViewModel.footer isEqualToString:@"查看更多 >"]) {
  152. footerView.footerContentLabel.textAlignment = NSTextAlignmentCenter;
  153. [footerView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  154. @strongify(self)
  155. RQDspVideoDetailViewModel *viewModel = [[RQDspVideoDetailViewModel alloc] initWithServices:self.viewModel.services params:@{
  156. RQViewCommonValueKey: [NSIndexPath indexPathForRow:6 inSection:0],
  157. }];
  158. [self.viewModel.services pushViewModel:viewModel animated:YES];
  159. }];
  160. footerView.backgroundColor = UIColor.whiteColor;
  161. footerView.footerContentLabel.hidden = NO;
  162. } else {
  163. footerView.footerContentLabel.hidden = YES;
  164. }
  165. return footerView;
  166. } else if ([groupViewModel isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) {
  167. RQCommonReusableView *homePageSectionOneFooterView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  168. RQHomePageSectionOneGroupViewModel *homePageSectionOneGroupViewModel = self.viewModel.dataSource[indexPath.section];
  169. [homePageSectionOneFooterView bindViewModel:homePageSectionOneGroupViewModel];
  170. homePageSectionOneFooterView.headerContentLabel.hidden = YES;
  171. homePageSectionOneFooterView.footerContentLabel.hidden = YES;
  172. homePageSectionOneFooterView.backgroundColor = UIColor.whiteColor;
  173. return homePageSectionOneFooterView;
  174. } else {
  175. RQCommonReusableView *commonFooterView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  176. RQCommonGroupViewModel *commonFooterGroupViewModel = self.viewModel.dataSource[indexPath.section];
  177. [commonFooterView bindViewModel:commonFooterGroupViewModel];
  178. return commonFooterView;
  179. }
  180. }
  181. }
  182. @end