RQHomePageSubjectOneOrFourViewController.m 15 KB

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