// // RQHomePageSubjectOneOrFourViewController.m // JSJP // // Created by 张嵘 on 2021/7/29. // #import "RQHomePageSubjectOneOrFourViewController.h" @interface RQHomePageSubjectOneOrFourViewController () /// viewModel @property (nonatomic, readonly, strong) RQHomePageSubjectOneOrFourViewModel *viewModel; @end @implementation RQHomePageSubjectOneOrFourViewController @dynamic viewModel; #pragma mark - SystemMethod - (void)viewDidLoad { [super viewDidLoad]; /// 初始化 [self rq_setup]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; self.view.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT); } #pragma mark - PrivateMethods /// 初始化 - (void)rq_setup { /// set up ... self.collectionView.bounces = NO; self.collectionView.backgroundColor = UIColor.clearColor; } #pragma mark - OverrideMethods /// 配置tableView的区域 - (UIEdgeInsets)contentInset { 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); } /// RQHomePageSectionZeroGroupViewModel - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath { RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section]; RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row]; if ([itemViewModel isKindOfClass:[RQHomePageADItemViewModel class]]) { RQHomePageADCell *cell = [RQHomePageADCell cellWithCollectionView:collectionView forIndexPath:indexPath]; return cell; } else if ([itemViewModel isKindOfClass:[RQHomeSubPageVideoScrollItemViewModel class]]) { RQHomeSubPageVideoScrollCell *cell = [RQHomeSubPageVideoScrollCell cellWithCollectionView:collectionView forIndexPath:indexPath]; cell.superCollectionView = self.collectionView; return cell; } else if ([itemViewModel isKindOfClass:[RQHomeSubPageVideoItemViewModel class]]) { return [RQHomeSubPageVideoCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } else if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourBigItemViewModel class]]) { return [RQHomePageOneOrFourBigCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } else if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourSmallItemViewModel class]]) { return [RQHomePageOneOrFourSmallCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } else if ([itemViewModel isKindOfClass:[RQHomePageSimulationExamItemViewModel class]]) { return [RQHomePageSimulationExamCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } else if ([itemViewModel isKindOfClass:[RQHomePageJiaoGuan12123ItemViewModel class]]) { return [RQHomePageJiaoGuan12123Cell cellWithCollectionView:collectionView forIndexPath:indexPath]; } else if ([itemViewModel isKindOfClass:[RQHomePageDriveMethodItemViewModel class]]) { return [RQHomePageDriveMethodCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } else if ([itemViewModel isKindOfClass:[RQHomePageSubjectModuleItemViewModel class]]) { return [RQHomePageSubjectModuleCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } else if ([itemViewModel isKindOfClass:[RQHomeSubPageNormalItemViewModel class]]) { return [RQHomeSubPageNormalCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } else if ([itemViewModel isKindOfClass:[RQTeachSchoolVideoItemViewModel class]]) { return [RQTeachSchoolVideoCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } else { return [super collectionView:collectionView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath]; } } - (void)configureCell:(UICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object { RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section]; RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row]; if ([itemViewModel isKindOfClass:[RQHomePageADItemViewModel class]]) { RQHomePageADCell *homePageADCell = (RQHomePageADCell *)cell; [homePageADCell bindViewModel:object]; } else if ([itemViewModel isKindOfClass:[RQHomeSubPageVideoScrollItemViewModel class]]) { RQHomeSubPageVideoScrollCell *homeSubPageVideoScrollCell = (RQHomeSubPageVideoScrollCell *)cell; [homeSubPageVideoScrollCell bindViewModel:object]; } else if ([itemViewModel isKindOfClass:[RQHomeSubPageVideoItemViewModel class]]) { RQHomeSubPageVideoCell *homeSubPageVideoCell = (RQHomeSubPageVideoCell *)cell; [homeSubPageVideoCell bindViewModel:object]; } else if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourBigItemViewModel class]]) { RQHomePageOneOrFourBigCell *homePageOneOrFourBigCell = (RQHomePageOneOrFourBigCell *)cell; [homePageOneOrFourBigCell bindViewModel:object]; } else if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourSmallItemViewModel class]]) { RQHomePageOneOrFourSmallCell *homePageOneOrFourSmallCell = (RQHomePageOneOrFourSmallCell *)cell; [homePageOneOrFourSmallCell bindViewModel:object]; } else if ([itemViewModel isKindOfClass:[RQHomePageSimulationExamItemViewModel class]]) { RQHomePageSimulationExamCell *homePageSimulationExamCell = (RQHomePageSimulationExamCell *)cell; [homePageSimulationExamCell bindViewModel:object]; } else if ([itemViewModel isKindOfClass:[RQHomePageJiaoGuan12123ItemViewModel class]]) { RQHomePageJiaoGuan12123Cell *homePageJiaoGuan12123Cell = (RQHomePageJiaoGuan12123Cell *)cell; [homePageJiaoGuan12123Cell bindViewModel:object]; } else if ([itemViewModel isKindOfClass:[RQHomePageDriveMethodItemViewModel class]]) { RQHomePageDriveMethodCell *homePageDriveMethodCell = (RQHomePageDriveMethodCell *)cell; [homePageDriveMethodCell bindViewModel:object]; } else if ([itemViewModel isKindOfClass:[RQHomePageSubjectModuleItemViewModel class]]) { RQHomePageSubjectModuleCell *homePageSubjectModuleCell = (RQHomePageSubjectModuleCell *)cell; [homePageSubjectModuleCell bindViewModel:object]; } else if ([itemViewModel isKindOfClass:[RQHomeSubPageNormalItemViewModel class]]) { RQHomeSubPageNormalCell *homeSubPageNormalCell = (RQHomeSubPageNormalCell *)cell; [homeSubPageNormalCell bindViewModel:object]; } else if ([itemViewModel isKindOfClass:[RQTeachSchoolVideoItemViewModel class]]) { RQTeachSchoolVideoCell *teachSchoolVideoCell = (RQTeachSchoolVideoCell *)cell; [teachSchoolVideoCell bindViewModel:object]; } else { [super configureCell:cell atIndexPath:indexPath withObject:object]; } } - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section]; RQCommonCollectionItemViewModel *itemViewModel = (groupViewModel.itemViewModels.count > 0)? groupViewModel.itemViewModels.firstObject : nil; if (itemViewModel) { if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]] || [self.viewModel.dataSource[section] isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) { return UIEdgeInsetsMake(0, 16, 0, 16); } else { if ([itemViewModel isKindOfClass:[RQHomePageOneOrFourBigItemViewModel class]]) { return UIEdgeInsetsMake(0, 16, 0, 16); } else { return UIEdgeInsetsZero; } } } else { return UIEdgeInsetsZero; } } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return 8.f; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 8.f; } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { @weakify(self) RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section]; // 如果是头视图 if (kind == UICollectionElementKindSectionHeader) { if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) { RQHomeSubPageVideoHeaderCollectionReusableView *headerView = [RQHomeSubPageVideoHeaderCollectionReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath]; RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section]; [headerView bindViewModel:groupViewModel]; headerView.headerContentLabel.hidden = NO; headerView.footerContentLabel.hidden = YES; return headerView; } else if ([groupViewModel isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) { RQCommonReusableView *homePageSectionOneHeaderView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath]; RQHomePageSectionOneGroupViewModel *homePageSectionOneGroupViewModel = self.viewModel.dataSource[indexPath.section]; [homePageSectionOneHeaderView bindViewModel:homePageSectionOneGroupViewModel]; homePageSectionOneHeaderView.headerContentLabel.hidden = YES; homePageSectionOneHeaderView.footerContentLabel.hidden = YES; homePageSectionOneHeaderView.backgroundColor = UIColor.whiteColor; return homePageSectionOneHeaderView; } else { RQCommonReusableView *headerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath]; RQCommonReusableView *groupViewModel = self.viewModel.dataSource[indexPath.section]; [headerView bindViewModel:groupViewModel]; headerView.headerContentLabel.hidden = YES; headerView.footerContentLabel.hidden = YES; return headerView; } } else { if ([groupViewModel isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) { RQCommonReusableView *footerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath]; RQHomeSubPageVideoHeaderGroupViewModel *homeSubPageVideoHeaderGroupViewModel = self.viewModel.dataSource[indexPath.section]; [footerView bindViewModel:homeSubPageVideoHeaderGroupViewModel]; footerView.headerContentLabel.hidden = YES; if ([homeSubPageVideoHeaderGroupViewModel.footer isEqualToString:@"查看更多 >"]) { footerView.footerContentLabel.textAlignment = NSTextAlignmentCenter; [footerView setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) RQDspVideoDetailViewModel *viewModel = [[RQDspVideoDetailViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewCommonValueKey: [NSIndexPath indexPathForRow:6 inSection:0], }]; [self.viewModel.services pushViewModel:viewModel animated:YES]; }]; footerView.backgroundColor = UIColor.whiteColor; footerView.footerContentLabel.hidden = NO; } else { footerView.footerContentLabel.hidden = YES; } return footerView; } else if ([groupViewModel isKindOfClass:[RQHomePageSectionOneGroupViewModel class]]) { RQCommonReusableView *homePageSectionOneFooterView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath]; RQHomePageSectionOneGroupViewModel *homePageSectionOneGroupViewModel = self.viewModel.dataSource[indexPath.section]; [homePageSectionOneFooterView bindViewModel:homePageSectionOneGroupViewModel]; homePageSectionOneFooterView.headerContentLabel.hidden = YES; homePageSectionOneFooterView.footerContentLabel.hidden = YES; homePageSectionOneFooterView.backgroundColor = UIColor.whiteColor; return homePageSectionOneFooterView; } else { RQCommonReusableView *commonFooterView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath]; RQCommonGroupViewModel *commonFooterGroupViewModel = self.viewModel.dataSource[indexPath.section]; [commonFooterView bindViewModel:commonFooterGroupViewModel]; commonFooterView.headerContentLabel.hidden = YES; commonFooterView.footerContentLabel.hidden = YES; return commonFooterView; } } } #pragma mark - UITableViewDelegate & UITableViewDataSource - (void)scrollViewDidScroll:(UIScrollView *)scrollView { !self.scrollCallback ?: self.scrollCallback(scrollView); } #pragma mark - JXPagerViewListViewDelegate - (UIView *)listView { return self.view; } - (UIScrollView *)listScrollView { return self.collectionView; } - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback { self.scrollCallback = callback; } #pragma mark - LazyLoad @end