// // RQHomePageSubjectOneOrFourViewController.m // SDJK // // Created by 张嵘 on 2021/7/29. // #import "RQHomePageSubjectOneOrFourViewController.h" @interface RQHomePageSubjectOneOrFourViewController () /// viewModel @property (nonatomic, readonly, strong) RQHomePageSubjectOneOrFourViewModel *viewModel; @property (nonatomic, readwrite, strong) SDCycleScrollView *cycleScrollView; @property (nonatomic, readwrite, strong) NSArray *adArray; @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_TOP_BAR_HEIGHT + RQHeightForPinSectionHeaderInPagerView_One + RQHeightForPinSectionHeaderInPagerView_Two + RQ_APPLICATION_TAB_BAR_HEIGHT + (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 0 : RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT), 0); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath { if ([self.viewModel.dataSource[indexPath.section] isKindOfClass:[RQHomeSubPageToolBarGroupViewModel class]] || [self.viewModel.dataSource[indexPath.section] isKindOfClass:[RQHomeSubPageToolBarOneGroupViewModel class]]) { if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) { RQHomeSubPageVideoScrollCell *cell = [RQHomeSubPageVideoScrollCell cellWithCollectionView:collectionView forIndexPath:indexPath]; cell.superCollectionView = self.collectionView; return cell; } else { return [RQHomeSubPageCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } } else if ([self.viewModel.dataSource[indexPath.section] isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) { return [RQHomeSubPageVideoCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } else { if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) { return [RQHomeSubPageNormalCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } else { return [super collectionView:collectionView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath]; } } switch (indexPath.section) { case 0: { if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) { RQHomeSubPageVideoScrollCell *cell = [RQHomeSubPageVideoScrollCell cellWithCollectionView:collectionView forIndexPath:indexPath]; cell.superCollectionView = self.collectionView; return cell; } else { return [RQHomeSubPageCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } } case 1: { if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) { return [RQHomeSubPageNormalCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } else { return [RQHomeSubPageVideoCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } return [RQHomeSubPageVideoCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } case 2: { return [RQHomeSubPageNormalCell cellWithCollectionView:collectionView forIndexPath:indexPath]; } default: { return [super collectionView:collectionView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath]; } } } - (void)configureCell:(UICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object { if ([self.viewModel.dataSource[indexPath.section] isKindOfClass:[RQHomeSubPageToolBarGroupViewModel class]] || [self.viewModel.dataSource[indexPath.section] isKindOfClass:[RQHomeSubPageToolBarOneGroupViewModel class]]) { if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) { RQHomeSubPageVideoScrollCell *homeSubPageVideoScrollCell = (RQHomeSubPageVideoScrollCell *)cell; [homeSubPageVideoScrollCell bindViewModel:object]; } else { RQHomeSubPageCell *homeSubPageCell = (RQHomeSubPageCell *)cell; [homeSubPageCell bindViewModel:object]; } } else if ([self.viewModel.dataSource[indexPath.section] isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) { RQHomeSubPageVideoCell *homeSubPageVideoCell = (RQHomeSubPageVideoCell *)cell; [homeSubPageVideoCell bindViewModel:object]; } else { if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) { RQHomeSubPageNormalCell *homeSubPageNormalCell = (RQHomeSubPageNormalCell *)cell; [homeSubPageNormalCell bindViewModel:object]; } else { [super configureCell:cell atIndexPath:indexPath withObject:object]; } } return; switch (indexPath.section) { case 0: { if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) { RQHomeSubPageVideoScrollCell *homeSubPageVideoScrollCell = (RQHomeSubPageVideoScrollCell *)cell; [homeSubPageVideoScrollCell bindViewModel:object]; break; } else { RQHomeSubPageCell *homeSubPageCell = (RQHomeSubPageCell *)cell; [homeSubPageCell bindViewModel:object]; } } case 1: { if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) { RQHomeSubPageNormalCell *homeSubPageNormalCell = (RQHomeSubPageNormalCell *)cell; [homeSubPageNormalCell bindViewModel:object]; break; } else { RQHomeSubPageVideoCell *homeSubPageVideoCell = (RQHomeSubPageVideoCell *)cell; [homeSubPageVideoCell bindViewModel:object]; break; } } case 2: { RQHomeSubPageNormalCell *homeSubPageNormalCell = (RQHomeSubPageNormalCell *)cell; [homeSubPageNormalCell bindViewModel:object]; break; } default: { [super configureCell:cell atIndexPath:indexPath withObject:object]; break; } } } - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { if ([self.viewModel.dataSource[section] isKindOfClass:[RQHomeSubPageToolBarGroupViewModel class]] || [self.viewModel.dataSource[section] isKindOfClass:[RQHomeSubPageToolBarOneGroupViewModel class]]) { return UIEdgeInsetsZero; } else if ([self.viewModel.dataSource[section] isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) { return UIEdgeInsetsMake(0, 16, 0, 16); } else { return UIEdgeInsetsZero; } switch (section) { case 0: { return UIEdgeInsetsZero; } case 1: { if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) { return UIEdgeInsetsZero; } else { return UIEdgeInsetsMake(0, 16, 0, 16); } } default: { return UIEdgeInsetsZero; } } } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { // 如果是头视图 if (kind == UICollectionElementKindSectionHeader) { if (indexPath.section == 0) { 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; [headerView addSubview:self.cycleScrollView]; if (self.adArray.count > 0) { NSMutableArray *myArr = [self.adArray.rac_sequence map:^id _Nullable(NSDictionary *dic) { return dic[@"IMG"]; }].array.mutableCopy; if (RQ_COMMON_MANAGER.YYXC_AD_OPEN && RQ_COMMON_MANAGER.YYXC_NATIVE_AD_OPEN) { [myArr addObject:@"RQ-AD"]; } self.cycleScrollView.imageURLStringsGroup = myArr.copy; } else { } return headerView; } else { 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 (indexPath.section == 0) { if ((self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo)) { RQHomeSubPageToolBarOneView *footerView = [RQHomeSubPageToolBarOneView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath]; RQHomeSubPageToolBarOneGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section]; [footerView bindViewModel:groupViewModel]; footerView.headerContentLabel.hidden = YES; footerView.footerContentLabel.hidden = NO; return footerView; } else { RQHomeSubPageToolBarView *footerView = [RQHomeSubPageToolBarView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath]; RQHomeSubPageToolBarGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section]; [footerView bindViewModel:groupViewModel]; footerView.headerContentLabel.hidden = YES; footerView.footerContentLabel.hidden = NO; return footerView; } } 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; 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; } #pragma mark - SDCycleScrollViewDelegate - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index { // NSDictionary *dic = self.adArray[index]; // [RQ_SHARE_FUNCTION saveObjectWithObject:dic ForKey:@"currentSelectDic"]; // NSString *skipType = dic[@"OPENTYPE"]; // // if ([skipType isEqualToString:@"1"]) { // [RQ_SHARE_FUNCTION gotoWebViewWithUrlStr:dic[@"URL"]]; // }else{ // if ([dic[@"ADTYPE"] isEqualToString:@"2"]) { // [RQ_SHARE_FUNCTION miniwithUserName:dic[@"URL"] path:dic[@"AI_XCX_URL"]? : @""]; // } else if ([dic[@"ADTYPE"] isEqualToString:@"1"]) { // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dic[@"URL"]] options:nil completionHandler:^(BOOL success) { // // }]; // } else if ([dic[@"ADTYPE"] isEqualToString:@"3"]) { // WXSubscribeMsgReq *req = [[WXSubscribeMsgReq alloc] init]; // req.scene = 1; // req.templateId = @"1iZwYeI2QtSXZ3rTRkQ42wgRkd7NSINzem8R-LvtHYw"; // req.reserved = @""; // [WXApi sendReq:req completion:nil]; // } // } } #pragma mark - LazyLoad - (SDCycleScrollView *)cycleScrollView { if (!_cycleScrollView) { _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SHARE_FUNCTION.RQADViewHeight) imageNamesGroup:RQ_COMMON_MANAGER.YYXC_AD_OPEN? (RQ_COMMON_MANAGER.YYXC_NATIVE_AD_OPEN? @[@"subject_main_banner",@"RQ-AD"] : @[@"subject_main_banner"]) : @[@"subject_main_banner"]]; _cycleScrollView.autoScrollTimeInterval = 5; _cycleScrollView.placeholderImage = RQImageNamed(@"未开发"); _cycleScrollView.delegate = self; _cycleScrollView.backgroundColor = UIColor.whiteColor; } return _cycleScrollView; } - (NSArray *)adArray { //广告 NSMutableArray *newAD = [NSMutableArray array]; if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectOne){ for (NSDictionary *dic in myDelegate.adArray) { if ([dic[@"LOCATION"] isEqualToString:@"3"]) { [newAD addObject:dic]; } } }else{ for (NSDictionary *dic in myDelegate.adArray) { if ([dic[@"LOCATION"] isEqualToString:@"6"]) { [newAD addObject:dic]; } } } return newAD.copy; } @end