RQHomePageSubjectOneOrFourViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //
  2. // RQHomePageSubjectOneOrFourViewController.m
  3. // JSJP
  4. //
  5. // Created by 张嵘 on 2021/7/29.
  6. //
  7. #import "RQHomePageSubjectOneOrFourViewController.h"
  8. @interface RQHomePageSubjectOneOrFourViewController () <SDCycleScrollViewDelegate>
  9. /// viewModel
  10. @property (nonatomic, readonly, strong) RQHomePageSubjectOneOrFourViewModel *viewModel;
  11. @end
  12. @implementation RQHomePageSubjectOneOrFourViewController
  13. @dynamic viewModel;
  14. #pragma mark - SystemMethod
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. /// 初始化
  18. [self rq_setup];
  19. }
  20. - (void)viewDidLayoutSubviews {
  21. [super viewDidLayoutSubviews];
  22. self.view.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT);
  23. }
  24. #pragma mark - PrivateMethods
  25. /// 初始化
  26. - (void)rq_setup {
  27. /// set up ...
  28. self.collectionView.bounces = NO;
  29. self.collectionView.backgroundColor = UIColor.clearColor;
  30. }
  31. #pragma mark - OverrideMethods
  32. /// 配置tableView的区域
  33. - (UIEdgeInsets)contentInset {
  34. return UIEdgeInsetsMake((self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree)? 0 : 0, 0, (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT) + RQHeightForPinSectionHeaderInPagerView_One + RQHeightForPinSectionHeaderInPagerView_Two + RQ_APPLICATION_TAB_BAR_HEIGHT + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT, 0);
  35. }
  36. /// RQHomePageSectionZeroGroupViewModel
  37. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  38. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  39. RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  40. if ([itemViewModel isKindOfClass:[RQHomePageADItemViewModel class]]) {
  41. RQHomePageADCell *cell = [RQHomePageADCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  42. return cell;
  43. } else if ([itemViewModel isKindOfClass:[RQHomeSubPageVideoScrollItemViewModel class]]) {
  44. RQHomeSubPageVideoScrollCell *cell = [RQHomeSubPageVideoScrollCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  45. cell.superCollectionView = self.collectionView;
  46. return cell;
  47. } else if ([itemViewModel isKindOfClass:[RQHomeSubPageVideoItemViewModel class]]) {
  48. return [RQHomeSubPageVideoCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  49. } else if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourBigItemViewModel class]]) {
  50. return [RQHomePageOneOrFourBigCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  51. } else if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourSmallItemViewModel class]]) {
  52. return [RQHomePageOneOrFourSmallCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  53. } else if ([itemViewModel isKindOfClass:[RQHomePageSimulationExamItemViewModel class]]) {
  54. return [RQHomePageSimulationExamCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  55. } else if ([itemViewModel isKindOfClass:[RQHomePageJiaoGuan12123ItemViewModel class]]) {
  56. return [RQHomePageJiaoGuan12123Cell cellWithCollectionView:collectionView forIndexPath:indexPath];
  57. } else if ([itemViewModel isKindOfClass:[RQHomePageDriveMethodItemViewModel class]]) {
  58. return [RQHomePageDriveMethodCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  59. } else if ([itemViewModel isKindOfClass:[RQHomePageSubjectModuleItemViewModel class]]) {
  60. return [RQHomePageSubjectModuleCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  61. } else if ([itemViewModel isKindOfClass:[RQHomeSubPageNormalItemViewModel class]]) {
  62. return [RQHomeSubPageNormalCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  63. } else if ([itemViewModel isKindOfClass:[RQTeachSchoolVideoItemViewModel class]]) {
  64. return [RQTeachSchoolVideoCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  65. } else {
  66. return [super collectionView:collectionView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
  67. }
  68. }
  69. - (void)configureCell:(UICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  70. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  71. RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  72. if ([itemViewModel isKindOfClass:[RQHomePageADItemViewModel class]]) {
  73. RQHomePageADCell *homePageADCell = (RQHomePageADCell *)cell;
  74. [homePageADCell bindViewModel:object];
  75. } else if ([itemViewModel isKindOfClass:[RQHomeSubPageVideoScrollItemViewModel class]]) {
  76. RQHomeSubPageVideoScrollCell *homeSubPageVideoScrollCell = (RQHomeSubPageVideoScrollCell *)cell;
  77. [homeSubPageVideoScrollCell bindViewModel:object];
  78. } else if ([itemViewModel isKindOfClass:[RQHomeSubPageVideoItemViewModel class]]) {
  79. RQHomeSubPageVideoCell *homeSubPageVideoCell = (RQHomeSubPageVideoCell *)cell;
  80. [homeSubPageVideoCell bindViewModel:object];
  81. } else if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourBigItemViewModel class]]) {
  82. RQHomePageOneOrFourBigCell *homePageOneOrFourBigCell = (RQHomePageOneOrFourBigCell *)cell;
  83. [homePageOneOrFourBigCell bindViewModel:object];
  84. } else if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourSmallItemViewModel class]]) {
  85. RQHomePageOneOrFourSmallCell *homePageOneOrFourSmallCell = (RQHomePageOneOrFourSmallCell *)cell;
  86. [homePageOneOrFourSmallCell bindViewModel:object];
  87. } else if ([itemViewModel isKindOfClass:[RQHomePageSimulationExamItemViewModel class]]) {
  88. RQHomePageSimulationExamCell *homePageSimulationExamCell = (RQHomePageSimulationExamCell *)cell;
  89. [homePageSimulationExamCell bindViewModel:object];
  90. } else if ([itemViewModel isKindOfClass:[RQHomePageJiaoGuan12123ItemViewModel class]]) {
  91. RQHomePageJiaoGuan12123Cell *homePageJiaoGuan12123Cell = (RQHomePageJiaoGuan12123Cell *)cell;
  92. [homePageJiaoGuan12123Cell bindViewModel:object];
  93. } else if ([itemViewModel isKindOfClass:[RQHomePageDriveMethodItemViewModel class]]) {
  94. RQHomePageDriveMethodCell *homePageDriveMethodCell = (RQHomePageDriveMethodCell *)cell;
  95. [homePageDriveMethodCell bindViewModel:object];
  96. } else if ([itemViewModel isKindOfClass:[RQHomePageSubjectModuleItemViewModel class]]) {
  97. RQHomePageSubjectModuleCell *homePageSubjectModuleCell = (RQHomePageSubjectModuleCell *)cell;
  98. [homePageSubjectModuleCell bindViewModel:object];
  99. } else if ([itemViewModel isKindOfClass:[RQHomeSubPageNormalItemViewModel class]]) {
  100. RQHomeSubPageNormalCell *homeSubPageNormalCell = (RQHomeSubPageNormalCell *)cell;
  101. [homeSubPageNormalCell bindViewModel:object];
  102. } else if ([itemViewModel isKindOfClass:[RQTeachSchoolVideoItemViewModel class]]) {
  103. RQTeachSchoolVideoCell *teachSchoolVideoCell = (RQTeachSchoolVideoCell *)cell;
  104. [teachSchoolVideoCell bindViewModel:object];
  105. } else {
  106. [super configureCell:cell atIndexPath:indexPath withObject:object];
  107. }
  108. }
  109. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  110. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
  111. RQCommonCollectionItemViewModel *itemViewModel = (groupViewModel.itemViewModels.count > 0)? groupViewModel.itemViewModels.firstObject : nil;
  112. if (itemViewModel) {
  113. if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]] || [self.viewModel.dataSource[section] isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) {
  114. return UIEdgeInsetsMake(0, 16, 0, 16);
  115. } else {
  116. if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourBigItemViewModel class]]) {
  117. return UIEdgeInsetsMake(0, 16, 0, 16);
  118. } else {
  119. return UIEdgeInsetsZero;
  120. }
  121. }
  122. } else {
  123. return UIEdgeInsetsZero;
  124. }
  125. }
  126. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  127. return 8.f;
  128. }
  129. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  130. return 8.f;
  131. }
  132. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  133. @weakify(self)
  134. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  135. // 如果是头视图
  136. if (kind == UICollectionElementKindSectionHeader) {
  137. if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) {
  138. RQHomeSubPageVideoHeaderCollectionReusableView *headerView = [RQHomeSubPageVideoHeaderCollectionReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  139. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  140. [headerView bindViewModel:groupViewModel];
  141. headerView.headerContentLabel.hidden = NO;
  142. headerView.footerContentLabel.hidden = YES;
  143. return headerView;
  144. } else if ([groupViewModel isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) {
  145. RQCommonReusableView *homePageSectionOneHeaderView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  146. RQHomePageSectionOneGroupViewModel *homePageSectionOneGroupViewModel = self.viewModel.dataSource[indexPath.section];
  147. [homePageSectionOneHeaderView bindViewModel:homePageSectionOneGroupViewModel];
  148. homePageSectionOneHeaderView.headerContentLabel.hidden = YES;
  149. homePageSectionOneHeaderView.footerContentLabel.hidden = YES;
  150. homePageSectionOneHeaderView.backgroundColor = UIColor.whiteColor;
  151. return homePageSectionOneHeaderView;
  152. } else {
  153. RQCommonReusableView *headerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  154. RQCommonReusableView *groupViewModel = self.viewModel.dataSource[indexPath.section];
  155. [headerView bindViewModel:groupViewModel];
  156. headerView.headerContentLabel.hidden = YES;
  157. headerView.footerContentLabel.hidden = YES;
  158. return headerView;
  159. }
  160. } else {
  161. if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) {
  162. RQCommonReusableView *footerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  163. RQHomeSubPageVideoHeaderGroupViewModel *homeSubPageVideoHeaderGroupViewModel = self.viewModel.dataSource[indexPath.section];
  164. [footerView bindViewModel:homeSubPageVideoHeaderGroupViewModel];
  165. footerView.headerContentLabel.hidden = YES;
  166. if ([homeSubPageVideoHeaderGroupViewModel.footer isEqualToString:@"查看更多 >"]) {
  167. footerView.footerContentLabel.textAlignment = NSTextAlignmentCenter;
  168. [footerView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  169. @strongify(self)
  170. RQDspVideoDetailViewModel *viewModel = [[RQDspVideoDetailViewModel alloc] initWithServices:self.viewModel.services params:@{
  171. RQViewCommonValueKey: [NSIndexPath indexPathForRow:6 inSection:0],
  172. }];
  173. [self.viewModel.services pushViewModel:viewModel animated:YES];
  174. }];
  175. footerView.backgroundColor = UIColor.whiteColor;
  176. footerView.footerContentLabel.hidden = NO;
  177. } else {
  178. footerView.footerContentLabel.hidden = YES;
  179. }
  180. return footerView;
  181. } else if ([groupViewModel isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) {
  182. RQCommonReusableView *homePageSectionOneFooterView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  183. RQHomePageSectionOneGroupViewModel *homePageSectionOneGroupViewModel = self.viewModel.dataSource[indexPath.section];
  184. [homePageSectionOneFooterView bindViewModel:homePageSectionOneGroupViewModel];
  185. homePageSectionOneFooterView.headerContentLabel.hidden = YES;
  186. homePageSectionOneFooterView.footerContentLabel.hidden = YES;
  187. homePageSectionOneFooterView.backgroundColor = UIColor.whiteColor;
  188. return homePageSectionOneFooterView;
  189. } else {
  190. RQCommonReusableView *commonFooterView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  191. RQCommonGroupViewModel *commonFooterGroupViewModel = self.viewModel.dataSource[indexPath.section];
  192. [commonFooterView bindViewModel:commonFooterGroupViewModel];
  193. commonFooterView.headerContentLabel.hidden = YES;
  194. commonFooterView.footerContentLabel.hidden = YES;
  195. return commonFooterView;
  196. }
  197. }
  198. }
  199. #pragma mark - UITableViewDelegate & UITableViewDataSource
  200. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  201. !self.scrollCallback ?: self.scrollCallback(scrollView);
  202. }
  203. #pragma mark - JXPagerViewListViewDelegate
  204. - (UIView *)listView {
  205. return self.view;
  206. }
  207. - (UIScrollView *)listScrollView {
  208. return self.collectionView;
  209. }
  210. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  211. self.scrollCallback = callback;
  212. }
  213. #pragma mark - LazyLoad
  214. @end