// // RQVideoDetailViewController.m // JSJP // // Created by 张嵘 on 2021/10/25. // 视频详情页面 #import "RQVideoDetailViewController.h" @interface RQVideoDetailViewController () /// viewModel @property (nonatomic, readonly, strong) RQVideoDetailViewModel *viewModel; @property (nonatomic, readwrite, strong) JXPagerView *pagerView; @property (nonatomic, readwrite, strong) JXCategoryTitleBackgroundView *categoryView; @property (nonatomic, readwrite, strong) UIView *headerView; @property (nonatomic, readwrite, strong) NSArray *titles; @property (nonatomic, readwrite, strong) NSArray *imagesArr; @property (nonatomic, readonly, assign) float cycleScrollViewHeight; @property (nonatomic, readonly, assign) float cellWeight; @end @implementation RQVideoDetailViewController @dynamic viewModel; #pragma mark - SystemMethod - (void)viewDidLoad { [super viewDidLoad]; /// 初始化 [self rq_setup]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; self.pagerView.frame = CGRectMake(0, RQ_APPLICATION_STATUS_BAR_HEIGHT, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_STATUS_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT); } - (void)dealloc { [RQ_Video_Module.playerController stop]; if (self.headerView) { [self.headerView removeFromSuperview]; self.headerView = nil; } } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; RQ_Video_Module.playerController.viewControllerDisappear = NO; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; RQ_Video_Module.playerController.viewControllerDisappear = YES; } - (BOOL)shouldAutorotate { return NO; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations { if (RQ_Video_Module.playerController.player.isFullScreen) { return UIInterfaceOrientationMaskLandscape; } return UIInterfaceOrientationMaskPortrait; } #pragma mark - PrivateMethods /// 初始化 - (void)rq_setup { NSMutableArray *typeNameStrArr = @[].mutableCopy; __block NSArray *typeNameArr = @[]; @weakify(self) if (!RQObjectIsNil(self.viewModel.treeListModel)) { [[self.viewModel.treeListModel.children.rac_sequence.signal deliverOnMainThread] subscribeNext:^(ChildrenItem *childrenItem) { @strongify(self) if (childrenItem.videos.count > 0) { [typeNameStrArr addObject:[self lineFeedWithStr:childrenItem.typeName]]; } else { if (childrenItem.children.count > 0) { typeNameArr = [childrenItem.children.rac_sequence map:^id _Nullable(ChildrenItem *childrenItemA) { @strongify(self) if (childrenItemA.videos.count > 0) { return [self lineFeedWithStr:childrenItemA.typeName]; } else { return nil; } }].array; } } } completed:^{ @strongify(self) if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) { ChildrenItem *childrenItem = self.viewModel.treeListModel.children[self.viewModel.indexPath.section]; if ([childrenItem.typeName isEqualToString:@"基础操作"]) { self.titles = typeNameStrArr.copy; } else { self.titles = typeNameArr; } } else { self.titles = typeNameStrArr.copy; } [self.pagerView setDefaultSelectedIndex:self.viewModel.index]; [self.categoryView setDefaultSelectedIndex:self.viewModel.index]; [self.categoryView reloadData]; /// set up ... [self.view addSubview:self.pagerView]; }]; } if (!RQObjectIsNil(self.viewModel.placeVideoListModel)) { self.titles = @[@""]; [self.pagerView setDefaultSelectedIndex:0]; [self.categoryView setDefaultSelectedIndex:0]; [self.categoryView reloadData]; /// set up ... [self.view addSubview:self.pagerView]; } [RQNotificationCenter removeObserver:self name:RQPlayVideoUrlNotification object:nil]; /// 播放 WeakSelf(weakSelf) [RQ_Video_Module.playerController stop]; RQ_Video_Module.videoDetailViewController = self; // [[RQNotificationCenter rac_addObserverForName:RQPlayVideoUrlNotification object:nil] subscribeNext:^(NSNotification *note) { // [weakSelf myVideoUrlNotification:note]; // }]; [[[[RQNotificationCenter rac_addObserverForName:RQPlayVideoUrlNotification object:nil] takeUntil:self.rac_willDeallocSignal] deliverOnMainThread] subscribeNext:^(NSNotification * note) { [weakSelf myVideoUrlNotification:note]; //@strongify(self) // NSLog(@"RQNotificationCenter-----播放"); // VideosItem *videosItem = note.object[RQPlayVideoItemKey]; // NSArray *videoItemArr = note.object[RQPlayVideoItemArrKey]; // RQVideoDetailSubPageViewController *videoDetailSubPageViewController = (RQVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(self.pagerView.listContainerView.currentIndex)]; // if ([RQ_Video_Module isCanWatchWithVideosItem:videosItem]) { // [RQ_Video_Module playVideoWithVideosItem:videosItem videosItemArr:videoItemArr playView:self.headerView scrollView:videoDetailSubPageViewController.tableView]; // } }]; } - (void)myVideoUrlNotification:(NSNotification *)note{ NSLog(@"RQNotificationCenter-----播放---AD-广告"); VideosItem *videosItem = note.object[RQPlayVideoItemKey]; NSArray *videoItemArr = note.object[RQPlayVideoItemArrKey]; RQVideoDetailSubPageViewController *videoDetailSubPageViewController = (RQVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(self.pagerView.listContainerView.currentIndex)]; if ([RQ_Video_Module isCanWatchWithVideosItem:videosItem]) { [RQ_Video_Module playVideoWithVideosItem:videosItem videosItemArr:videoItemArr playView:self.headerView scrollView:videoDetailSubPageViewController.tableView]; } } - (NSString *)lineFeedWithStr:(NSString *)str { if (str.length > 8) { NSMutableString *strs = [[NSMutableString alloc] initWithString:str]; [strs insertString:@"\n" atIndex:8]; return strs.copy; } else { return str; } } #pragma mark - JXPagerViewDelegate - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView { return self.headerView; } - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView { return self.cycleScrollViewHeight; } - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return self.titles.count > 1? self.cellWeight * ((37.f + (4.3f * 2)) / 80.f) : 0; } - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return self.categoryView; } - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView { //和categoryView的item数量一致 return self.categoryView.titles.count; } - (id)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index { if (!RQObjectIsNil(self.viewModel.treeListModel)) { ChildrenItem *childrenItemA = self.viewModel.treeListModel.children[self.viewModel.indexPath.section]; ChildrenItem *childrenItem = (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree)? (childrenItemA.children.count > 0? childrenItemA.children[index] : childrenItemA) : self.viewModel.treeListModel.children[index]; RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = [[RQVideoDetailSubPageViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelTitleKey : childrenItem.typeName, RQViewModelIDKey : childrenItem.typeDescribe? : @"", RQViewModelUtilKey : childrenItem.videos, RQViewCommonValueKey: self.viewModel.indexPath, RQHomeSubPageTypeKey: @(self.viewModel.homePageSubjectType), }]; RQVideoDetailSubPageViewController *videoDetailSubPageViewController = [[RQVideoDetailSubPageViewController alloc] initWithViewModel:videoDetailSubPageViewModel]; return videoDetailSubPageViewController; } else { if (!RQObjectIsNil(self.viewModel.placeVideoListModel)) { NSArray *videosItemArr = [self.viewModel.placeVideoListModel.items.rac_sequence.signal map:^id _Nullable(RQPlaceVideoListModel *placeVideoListModel) { VideosItem *videosItem = [[VideosItem alloc] init]; videosItem.videoType = RQVideoType_KaoChang; videosItem.video_url = placeVideoListModel.videoUrl; videosItem.coverFileUrl = placeVideoListModel.videoCover; videosItem.title = placeVideoListModel.videoName; videosItem.permission = [placeVideoListModel.permission integerValue]; videosItem.placeVideoListModel = self.viewModel.placeVideoListModel; return videosItem; }].toArray; RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = [[RQVideoDetailSubPageViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelTitleKey : self.viewModel.placeVideoListModel.examName, RQViewModelIDKey : @"", RQViewModelUtilKey : videosItemArr, RQViewCommonValueKey: self.viewModel.indexPath, RQHomeSubPageTypeKey: @(self.viewModel.homePageSubjectType), }]; RQVideoDetailSubPageViewController *videoDetailSubPageViewController = [[RQVideoDetailSubPageViewController alloc] initWithViewModel:videoDetailSubPageViewModel]; return videoDetailSubPageViewController; } else { RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = [[RQVideoDetailSubPageViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelTitleKey : @"", RQViewModelIDKey : @"", RQViewModelUtilKey : @[], RQViewCommonValueKey: [NSIndexPath indexPathForRow:0 inSection:0], RQHomeSubPageTypeKey: @(self.viewModel.homePageSubjectType), }]; RQVideoDetailSubPageViewController *videoDetailSubPageViewController = [[RQVideoDetailSubPageViewController alloc] initWithViewModel:videoDetailSubPageViewModel]; return videoDetailSubPageViewController; } } } #pragma mark - JXCategoryViewDelegate - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index { self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0); } - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index { RQVideoDetailSubPageViewController *videoDetailSubPageViewController = (RQVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(index)]; RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = (RQVideoDetailSubPageViewModel *)videoDetailSubPageViewController.viewModel; [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{ RQPlayVideoItemKey : videoDetailSubPageViewModel.videoArr.firstObject, RQPlayVideoItemArrKey : videoDetailSubPageViewModel.videoArr, }]; } - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index { RQVideoDetailSubPageViewController *videoDetailSubPageViewController = (RQVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(index)]; RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = (RQVideoDetailSubPageViewModel *)videoDetailSubPageViewController.viewModel; [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{ RQPlayVideoItemKey : videoDetailSubPageViewModel.videoArr.firstObject, RQPlayVideoItemArrKey : videoDetailSubPageViewModel.videoArr, }]; } #pragma mark - JXPagerMainTableViewGestureDelegate - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if ([self checkIsNestContentScrollView:(UIScrollView *)gestureRecognizer.view] || [self checkIsNestContentScrollView:(UIScrollView *)otherGestureRecognizer.view]) { //如果交互的是嵌套的contentScrollView,证明在左右滑动,就不允许同时响应 return NO; } return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]; } - (BOOL)checkIsNestContentScrollView:(UIScrollView *)scrollView { for (RQHomeSubPageViewController *list in self.pagerView.validListDict.allValues) { if (list.tableView == scrollView) { return YES; } } return NO; } #pragma mark - LazyLoad - (JXPagerView *)pagerView { if (!_pagerView) { _pagerView = [[JXPagerView alloc] initWithDelegate:self]; _pagerView.mainTableView.gestureDelegate = self; _pagerView.mainTableView.bounces = NO; _pagerView.pinSectionHeaderVerticalOffset = self.cycleScrollViewHeight; _pagerView.isMirror = YES; } return _pagerView; } - (JXCategoryTitleBackgroundView *)categoryView { if (!_categoryView) { _categoryView = [[JXCategoryTitleBackgroundView alloc] init]; _categoryView.delegate = self; _categoryView.titles = self.titles; _categoryView.titleSelectedColor = UIColor.whiteColor; _categoryView.titleColor = RQ_MAIN_TEXT_COLOR_2; _categoryView.titleFont = RQMediumFont(11); _categoryView.titleNumberOfLines = 0; _categoryView.titleSelectedFont = RQMediumFont(11); _categoryView.titleColorGradientEnabled = YES; _categoryView.contentEdgeInsetLeft = 16; _categoryView.contentEdgeInsetRight = 16; _categoryView.cellWidth = self.cellWeight; _categoryView.cellSpacing = 8; _categoryView.backgroundColor = RQ_BACKGROUNDCOLOR_1; _categoryView.backgroundHeight = self.cellWeight * (37.f / 80.f); JXCategoryIndicatorImageView *indicatorImageView1 = [[JXCategoryIndicatorImageView alloc] init]; indicatorImageView1.componentPosition = JXCategoryComponentPosition_Top; indicatorImageView1.indicatorImageView.image = RQImageNamed(@"arrowUP"); indicatorImageView1.indicatorImageViewSize = CGSizeMake(self.cellWeight * (11 / 80.f), self.cellWeight * (11 / 80.f) * (4.3f / 11.f)); _categoryView.indicators = @[indicatorImageView1]; _categoryView.defaultSelectedIndex = 0; /// !!!: 将列表容器视图关联到 categoryView _categoryView.listContainer = (id)self.pagerView.listContainerView; } return _categoryView; } - (UIView *)headerView { if (!_headerView) { _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, self.cycleScrollViewHeight)]; } return _headerView; } - (NSArray *)titles { if (!_titles) { _titles = @[@"侧方停车", @"倒车入库", @"坡道定点\n停车与起步", @"曲线行驶"]; } return _titles; } - (float)cycleScrollViewHeight { return RQ_FIT_HORIZONTAL(210.f); } - (float)cellWeight { return (RQ_SCREEN_WIDTH - (8 * 3) - (16 * 2)) / 4.f; } @end