RQSpecialPractiseViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. [RQ_AD_MANAGER loadAdWithAdType:RQADType_InterstitialSplash customView:nil];
  32. }
  33. #pragma mark - OverrideMethods
  34. /// 配置tableView的区域
  35. - (UIEdgeInsets)contentInset {
  36. return UIEdgeInsetsMake((RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT), 0, RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT, 0);
  37. }
  38. /// RQHomePageSectionZeroGroupViewModel
  39. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  40. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  41. RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  42. if ([itemViewModel isKindOfClass:[RQSpecialPracticeItemViewModel class]]) {
  43. RQSpecialPracticeCell *cell = [RQSpecialPracticeCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  44. return cell;
  45. } else if ([itemViewModel isKindOfClass:[RQSpecialAddItemViewModel class]]) {
  46. RQSpecialAddCell *cell = [RQSpecialAddCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  47. return cell;
  48. } else if ([itemViewModel isKindOfClass:[RQSpecialQuestionItemViewModel class]]) {
  49. RQSpecialQuestionCell *cell = [RQSpecialQuestionCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  50. return cell;
  51. } else if ([itemViewModel isKindOfClass:[RQSpecialPointItemViewModel class]]) {
  52. RQSpecialPointCell *cell = [RQSpecialPointCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  53. return cell;
  54. } else {
  55. return [super collectionView:collectionView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
  56. }
  57. }
  58. - (void)configureCell:(UICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  59. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  60. RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  61. if ([itemViewModel isKindOfClass:[RQSpecialPracticeItemViewModel class]]) {
  62. RQSpecialPracticeCell *specialPracticeCell = (RQSpecialPracticeCell *)cell;
  63. [specialPracticeCell bindViewModel:object];
  64. } else if ([itemViewModel isKindOfClass:[RQSpecialAddItemViewModel class]]) {
  65. RQSpecialAddCell *specialAddCell = (RQSpecialAddCell *)cell;
  66. [specialAddCell bindViewModel:object];
  67. } else if ([itemViewModel isKindOfClass:[RQSpecialQuestionItemViewModel class]]) {
  68. RQSpecialQuestionCell *specialQuestionCell = (RQSpecialQuestionCell *)cell;
  69. [specialQuestionCell bindViewModel:object];
  70. } else if ([itemViewModel isKindOfClass:[RQSpecialPointItemViewModel class]]) {
  71. RQSpecialPointCell *specialPointCell = (RQSpecialPointCell *)cell;
  72. [specialPointCell bindViewModel:object];
  73. } else {
  74. [super configureCell:cell atIndexPath:indexPath withObject:object];
  75. }
  76. }
  77. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  78. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
  79. RQCommonCollectionItemViewModel *itemViewModel = (groupViewModel.itemViewModels.count > 0)? groupViewModel.itemViewModels.firstObject : nil;
  80. if (itemViewModel) {
  81. if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]] || [self.viewModel.dataSource[section] isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) {
  82. return UIEdgeInsetsMake(0, 16, 0, 16);
  83. } else {
  84. if ([itemViewModel isKindOfClass:[RQSpecialPracticeItemViewModel class]]) {
  85. return UIEdgeInsetsMake(16, 16, 8, 16);
  86. } else if ([itemViewModel isKindOfClass:[RQSpecialAddItemViewModel class]]) {
  87. return UIEdgeInsetsMake(0, 16, 16, 16);
  88. } else if ([itemViewModel isKindOfClass:[RQSpecialQuestionItemViewModel class]]) {
  89. return UIEdgeInsetsMake(0, 16, 16, 16);
  90. } else {
  91. return UIEdgeInsetsZero;
  92. }
  93. }
  94. } else {
  95. return UIEdgeInsetsZero;
  96. }
  97. }
  98. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  99. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
  100. if ([groupViewModel.groupModel.header isEqualToString:@"考点练习"]) {
  101. return 0.f;
  102. } else {
  103. return 8.f;
  104. }
  105. }
  106. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  107. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
  108. if ([groupViewModel.groupModel.header isEqualToString:@"考点练习"]) {
  109. return 0.f;
  110. } else {
  111. return 8.f;
  112. }
  113. }
  114. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  115. @weakify(self)
  116. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  117. // 如果是头视图
  118. if (kind == UICollectionElementKindSectionHeader) {
  119. if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) {
  120. RQHomeSubPageVideoHeaderCollectionReusableView *headerView = [RQHomeSubPageVideoHeaderCollectionReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  121. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  122. [headerView bindViewModel:groupViewModel];
  123. headerView.headerContentLabel.hidden = NO;
  124. headerView.footerContentLabel.hidden = YES;
  125. return headerView;
  126. } else if ([groupViewModel isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) {
  127. RQCommonReusableView *homePageSectionOneHeaderView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  128. RQHomePageSectionOneGroupViewModel *homePageSectionOneGroupViewModel = self.viewModel.dataSource[indexPath.section];
  129. [homePageSectionOneHeaderView bindViewModel:homePageSectionOneGroupViewModel];
  130. homePageSectionOneHeaderView.headerContentLabel.hidden = YES;
  131. homePageSectionOneHeaderView.footerContentLabel.hidden = YES;
  132. homePageSectionOneHeaderView.backgroundColor = UIColor.whiteColor;
  133. return homePageSectionOneHeaderView;
  134. } else {
  135. RQCommonReusableView *headerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  136. RQCommonReusableView *groupViewModel = self.viewModel.dataSource[indexPath.section];
  137. [headerView bindViewModel:groupViewModel];
  138. return headerView;
  139. }
  140. } else {
  141. if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) {
  142. RQCommonReusableView *footerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  143. RQHomeSubPageVideoHeaderGroupViewModel *homeSubPageVideoHeaderGroupViewModel = self.viewModel.dataSource[indexPath.section];
  144. [footerView bindViewModel:homeSubPageVideoHeaderGroupViewModel];
  145. footerView.headerContentLabel.hidden = YES;
  146. if ([homeSubPageVideoHeaderGroupViewModel.footer isEqualToString:@"查看更多 >"]) {
  147. footerView.footerContentLabel.textAlignment = NSTextAlignmentCenter;
  148. [footerView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  149. @strongify(self)
  150. RQDspVideoDetailViewModel *viewModel = [[RQDspVideoDetailViewModel alloc] initWithServices:self.viewModel.services params:@{
  151. RQViewCommonValueKey: [NSIndexPath indexPathForRow:6 inSection:0],
  152. }];
  153. [self.viewModel.services pushViewModel:viewModel animated:YES];
  154. }];
  155. footerView.backgroundColor = UIColor.whiteColor;
  156. footerView.footerContentLabel.hidden = NO;
  157. } else {
  158. footerView.footerContentLabel.hidden = YES;
  159. }
  160. return footerView;
  161. } else if ([groupViewModel isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) {
  162. RQCommonReusableView *homePageSectionOneFooterView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  163. RQHomePageSectionOneGroupViewModel *homePageSectionOneGroupViewModel = self.viewModel.dataSource[indexPath.section];
  164. [homePageSectionOneFooterView bindViewModel:homePageSectionOneGroupViewModel];
  165. homePageSectionOneFooterView.headerContentLabel.hidden = YES;
  166. homePageSectionOneFooterView.footerContentLabel.hidden = YES;
  167. homePageSectionOneFooterView.backgroundColor = UIColor.whiteColor;
  168. return homePageSectionOneFooterView;
  169. } else {
  170. RQCommonReusableView *commonFooterView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  171. RQCommonGroupViewModel *commonFooterGroupViewModel = self.viewModel.dataSource[indexPath.section];
  172. [commonFooterView bindViewModel:commonFooterGroupViewModel];
  173. return commonFooterView;
  174. }
  175. }
  176. }
  177. @end