// // RQHomePageSubjectOneOrFourViewController.m // SDJK // // 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)? 24 : 0, 0, RQ_APPLICATION_TOP_BAR_HEIGHT + RQHeightForPinSectionHeaderInPagerView_One + RQHeightForPinSectionHeaderInPagerView_Two + RQ_APPLICATION_TAB_BAR_HEIGHT + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT, 0); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath { RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section]; RQCommonCollecttionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row]; return [NSClassFromString(itemViewModel.itemClassName) cellWithCollectionView:collectionView forIndexPath:indexPath]; } - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object { [cell bindViewModel:object]; } - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section]; if (groupViewModel.itemViewModels.count > 0) { if ([groupViewModel.itemViewModels.firstObject isKindOfClass:[RQFreeTryItemViewModel class]]) { return UIEdgeInsetsMake(18, 16, 20, 16); } else if ([groupViewModel.itemViewModels.firstObject isKindOfClass:[RQHomeSubPageItemViewModel class]]) { return UIEdgeInsetsZero; } else if ([groupViewModel.itemViewModels.firstObject isKindOfClass:[RQHomePageJiaoGuan12123ItemViewModel class]]) { return UIEdgeInsetsMake(4, 16, 0, 16); } else { return UIEdgeInsetsMake(0, 16, 0, 16); } } else { return UIEdgeInsetsMake(0, 16, 0, 16); } } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return RQ_APPLICATION_COMMON_SPACE_10; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 11.f; } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { @weakify(self) // 如果是头视图 if (kind == UICollectionElementKindSectionHeader) { 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 { RQCommonReusableView *footerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath]; RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section]; [footerView bindViewModel:groupViewModel]; footerView.headerContentLabel.hidden = YES; footerView.footerContentLabel.hidden = NO; footerView.footerContentLabel.textAlignment = NSTextAlignmentCenter; if ([groupViewModel.groupModel.footer isEqualToString:@"查看更多 >"]) { [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]; }]; } return footerView; } } #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; } @end