RQHomePageSubjectOneOrFourViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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:[NYHomePageOneBigItemViewModel class]]) {
  52. return [NYHomePageOneBigCell cellWithCollectionView:collectionView forIndexPath:indexPath]; /// 新
  53. } else if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourSmallItemViewModel class]]) {
  54. return [RQHomePageOneOrFourSmallCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  55. } else if ([itemViewModel isKindOfClass:[NYLIHomePageSimulationExamItemViewModel class]]) {
  56. return [NYLIHomePageSimulationExamCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  57. } else if ([itemViewModel isKindOfClass:[RQHomePageJiaoGuan12123ItemViewModel class]]) {
  58. return [RQHomePageJiaoGuan12123Cell cellWithCollectionView:collectionView forIndexPath:indexPath];
  59. } else if ([itemViewModel isKindOfClass:[RQHomePageDriveMethodItemViewModel class]]) {
  60. return [RQHomePageDriveMethodCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  61. } else if ([itemViewModel isKindOfClass:[RQHomePageSubjectModuleItemViewModel class]]) {
  62. return [RQHomePageSubjectModuleCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  63. } else if ([itemViewModel isKindOfClass:[RQHomeSubPageNormalItemViewModel class]]) {
  64. return [RQHomeSubPageNormalCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  65. } else if ([itemViewModel isKindOfClass:[RQTeachSchoolVideoItemViewModel class]]) {
  66. return [RQTeachSchoolVideoCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  67. } else {
  68. return [super collectionView:collectionView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
  69. }
  70. }
  71. - (void)configureCell:(UICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  72. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  73. RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  74. if ([itemViewModel isKindOfClass:[RQHomePageADItemViewModel class]]) {
  75. RQHomePageADCell *homePageADCell = (RQHomePageADCell *)cell;
  76. [homePageADCell bindViewModel:object];
  77. } else if ([itemViewModel isKindOfClass:[RQHomeSubPageVideoScrollItemViewModel class]]) {
  78. RQHomeSubPageVideoScrollCell *homeSubPageVideoScrollCell = (RQHomeSubPageVideoScrollCell *)cell;
  79. [homeSubPageVideoScrollCell bindViewModel:object];
  80. } else if ([itemViewModel isKindOfClass:[RQHomeSubPageVideoItemViewModel class]]) {
  81. RQHomeSubPageVideoCell *homeSubPageVideoCell = (RQHomeSubPageVideoCell *)cell;
  82. [homeSubPageVideoCell bindViewModel:object];
  83. } else if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourBigItemViewModel class]]) {
  84. RQHomePageOneOrFourBigCell *homePageOneOrFourBigCell = (RQHomePageOneOrFourBigCell *)cell;
  85. [homePageOneOrFourBigCell bindViewModel:object];
  86. } else if ([itemViewModel isKindOfClass:[NYHomePageOneBigItemViewModel class]]) {
  87. NYHomePageOneBigCell *nyhomePageOneBigCell = (NYHomePageOneBigCell *)cell;
  88. [nyhomePageOneBigCell bindViewModel:object];
  89. } else if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourSmallItemViewModel class]]) {
  90. RQHomePageOneOrFourSmallCell *homePageOneOrFourSmallCell = (RQHomePageOneOrFourSmallCell *)cell;
  91. [homePageOneOrFourSmallCell bindViewModel:object];
  92. } else if ([itemViewModel isKindOfClass:[NYLIHomePageSimulationExamItemViewModel class]]) {
  93. NYLIHomePageSimulationExamCell *homePageSimulationExamCell = (NYLIHomePageSimulationExamCell *)cell;
  94. [homePageSimulationExamCell bindViewModel:object];
  95. } else if ([itemViewModel isKindOfClass:[RQHomePageJiaoGuan12123ItemViewModel class]]) {
  96. RQHomePageJiaoGuan12123Cell *homePageJiaoGuan12123Cell = (RQHomePageJiaoGuan12123Cell *)cell;
  97. [homePageJiaoGuan12123Cell bindViewModel:object];
  98. } else if ([itemViewModel isKindOfClass:[RQHomePageDriveMethodItemViewModel class]]) {
  99. RQHomePageDriveMethodCell *homePageDriveMethodCell = (RQHomePageDriveMethodCell *)cell;
  100. [homePageDriveMethodCell bindViewModel:object];
  101. } else if ([itemViewModel isKindOfClass:[RQHomePageSubjectModuleItemViewModel class]]) {
  102. RQHomePageSubjectModuleCell *homePageSubjectModuleCell = (RQHomePageSubjectModuleCell *)cell;
  103. [homePageSubjectModuleCell bindViewModel:object];
  104. } else if ([itemViewModel isKindOfClass:[RQHomeSubPageNormalItemViewModel class]]) {
  105. RQHomeSubPageNormalCell *homeSubPageNormalCell = (RQHomeSubPageNormalCell *)cell;
  106. [homeSubPageNormalCell bindViewModel:object];
  107. } else if ([itemViewModel isKindOfClass:[RQTeachSchoolVideoItemViewModel class]]) {
  108. RQTeachSchoolVideoCell *teachSchoolVideoCell = (RQTeachSchoolVideoCell *)cell;
  109. [teachSchoolVideoCell bindViewModel:object];
  110. } else {
  111. [super configureCell:cell atIndexPath:indexPath withObject:object];
  112. }
  113. }
  114. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  115. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
  116. RQCommonCollectionItemViewModel *itemViewModel = (groupViewModel.itemViewModels.count > 0)? groupViewModel.itemViewModels.firstObject : nil;
  117. if (itemViewModel) {
  118. if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]] || [self.viewModel.dataSource[section] isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) {
  119. return UIEdgeInsetsMake(0, 16, 0, 16);
  120. } else {
  121. if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourBigItemViewModel class]]) {
  122. return UIEdgeInsetsMake(0, 16, 0, 16);
  123. } else {
  124. return UIEdgeInsetsZero;
  125. }
  126. }
  127. } else {
  128. return UIEdgeInsetsZero;
  129. }
  130. }
  131. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  132. return 8.f;
  133. }
  134. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  135. return 8.f;
  136. }
  137. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  138. @weakify(self)
  139. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  140. // 如果是头视图
  141. if (kind == UICollectionElementKindSectionHeader) {
  142. if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) {
  143. RQHomeSubPageVideoHeaderCollectionReusableView *headerView = [RQHomeSubPageVideoHeaderCollectionReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  144. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  145. [headerView bindViewModel:groupViewModel];
  146. headerView.headerContentLabel.hidden = NO;
  147. headerView.footerContentLabel.hidden = YES;
  148. return headerView;
  149. } else if ([groupViewModel isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) {
  150. RQCommonReusableView *homePageSectionOneHeaderView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  151. RQHomePageSectionOneGroupViewModel *homePageSectionOneGroupViewModel = self.viewModel.dataSource[indexPath.section];
  152. [homePageSectionOneHeaderView bindViewModel:homePageSectionOneGroupViewModel];
  153. homePageSectionOneHeaderView.headerContentLabel.hidden = YES;
  154. homePageSectionOneHeaderView.footerContentLabel.hidden = YES;
  155. homePageSectionOneHeaderView.backgroundColor = UIColor.whiteColor;
  156. return homePageSectionOneHeaderView;
  157. } else {
  158. RQCommonReusableView *headerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  159. RQCommonReusableView *groupViewModel = self.viewModel.dataSource[indexPath.section];
  160. [headerView bindViewModel:groupViewModel];
  161. headerView.headerContentLabel.hidden = YES;
  162. headerView.footerContentLabel.hidden = YES;
  163. return headerView;
  164. }
  165. } else {
  166. if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) {
  167. RQCommonReusableView *footerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  168. RQHomeSubPageVideoHeaderGroupViewModel *homeSubPageVideoHeaderGroupViewModel = self.viewModel.dataSource[indexPath.section];
  169. [footerView bindViewModel:homeSubPageVideoHeaderGroupViewModel];
  170. footerView.headerContentLabel.hidden = YES;
  171. if ([homeSubPageVideoHeaderGroupViewModel.footer isEqualToString:@"查看更多 >"]) {
  172. footerView.footerContentLabel.textAlignment = NSTextAlignmentCenter;
  173. [footerView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  174. @strongify(self)
  175. RQDspVideoDetailViewModel *viewModel = [[RQDspVideoDetailViewModel alloc] initWithServices:self.viewModel.services params:@{
  176. RQViewCommonValueKey: [NSIndexPath indexPathForRow:6 inSection:0],
  177. }];
  178. [self.viewModel.services pushViewModel:viewModel animated:YES];
  179. }];
  180. footerView.backgroundColor = UIColor.whiteColor;
  181. footerView.footerContentLabel.hidden = NO;
  182. } else {
  183. footerView.footerContentLabel.hidden = YES;
  184. }
  185. return footerView;
  186. } else if ([groupViewModel isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) {
  187. RQCommonReusableView *homePageSectionOneFooterView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  188. RQHomePageSectionOneGroupViewModel *homePageSectionOneGroupViewModel = self.viewModel.dataSource[indexPath.section];
  189. [homePageSectionOneFooterView bindViewModel:homePageSectionOneGroupViewModel];
  190. homePageSectionOneFooterView.headerContentLabel.hidden = YES;
  191. homePageSectionOneFooterView.footerContentLabel.hidden = YES;
  192. homePageSectionOneFooterView.backgroundColor = UIColor.whiteColor;
  193. return homePageSectionOneFooterView;
  194. } else {
  195. RQCommonReusableView *commonFooterView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  196. RQCommonGroupViewModel *commonFooterGroupViewModel = self.viewModel.dataSource[indexPath.section];
  197. [commonFooterView bindViewModel:commonFooterGroupViewModel];
  198. commonFooterView.headerContentLabel.hidden = YES;
  199. commonFooterView.footerContentLabel.hidden = YES;
  200. return commonFooterView;
  201. }
  202. }
  203. }
  204. #pragma mark - UITableViewDelegate & UITableViewDataSource
  205. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  206. !self.scrollCallback ?: self.scrollCallback(scrollView);
  207. }
  208. #pragma mark - JXPagerViewListViewDelegate
  209. - (UIView *)listView {
  210. return self.view;
  211. }
  212. - (UIScrollView *)listScrollView {
  213. return self.collectionView;
  214. }
  215. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  216. self.scrollCallback = callback;
  217. }
  218. #pragma mark - LazyLoad
  219. @end