// // NYLIVideoDetailViewController.m // jiaPei // // Created by Ning.ge on 2025/2/8. // Copyright © 2025 JCZ. All rights reserved. // #import "NYLIVideoDetailViewController.h" @interface NYLIVideoDetailViewController () /// viewModel @property (nonatomic, readwrite, strong) NYLIVideoDetailViewModel *viewModel; @property (nonatomic, readwrite, strong) JXPagerView *pagerView; @property (nonatomic, readwrite, strong) JXCategoryTitleBackgroundView *categoryView; @property (nonatomic, readwrite, strong) NYLIVideoDetailHeaderView *lvheaderView; @property (nonatomic, readwrite, strong) NSArray *titles; @property (nonatomic, readwrite, strong) NSArray *imagesArr; @property (nonatomic, readonly, assign) float cycleScrollViewHeight; @property (nonatomic, readonly, assign) float cellWeight; @property (nonatomic, readwrite, strong) VideosItem *current_videosItem; @end @implementation NYLIVideoDetailViewController @dynamic viewModel; #pragma mark - SystemMethod - (void)viewDidLoad { [super viewDidLoad]; [RQ_VIP_Module isVipWithSubject:self.viewModel.homePageSubjectType+1 complete:^(BOOL isVip) { }]; /// 初始化 [self rq_setup]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; self.pagerView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT); } - (void)dealloc { self.current_videosItem = nil; [RQ_Video_Module.playerController stop]; if (self.lvheaderView) { [self.lvheaderView removeFromSuperview]; self.lvheaderView = nil; } } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; RQ_Video_Module.livideoDetailViewController = self; RQ_YDTQuestion_Module.subject = self.viewModel.homePageSubjectType; 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 { /// 播放 WeakSelf(weakSelf) 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]; RAC(self.lvheaderView.title_label, text) = [[RACObserve(self.viewModel.placeVideoListModel,examName) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal]; }else{ self.lvheaderView.back_btn.hidden = YES; RQHomePageSubjectType subType = RQHomePageSubjectType_SubjectOne_LI; NSString *ftv = @"1"; NSString *examName = @"科一专项精品课"; [MBProgressHUD rq_showProgressHUD:@""]; [[RQ_HTTP_Service getFiveTeachingList:ftv] subscribeNext:^(NSArray *fiveModels) { [MBProgressHUD rq_hideHUD]; RQPlaceVideoListModel *placeVideoListModel = [[RQPlaceVideoListModel alloc] init]; placeVideoListModel.examName = examName; placeVideoListModel.items = fiveModels; NSIndexPath *indexPath = [NSIndexPath indexPathWithIndex:0]; NYLIVideoDetailViewModel *videoDetailViewModel = [[NYLIVideoDetailViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{ RQViewModelUtilKey : placeVideoListModel, RQVideoItemIndexKey : @(0), RQVideoItemIndexPathKey : indexPath, RQHomePageSubjectTypeKey : @(subType), }]; weakSelf.viewModel = videoDetailViewModel; weakSelf.titles = @[@""]; [weakSelf.pagerView setDefaultSelectedIndex:0]; [weakSelf.categoryView setDefaultSelectedIndex:0]; [weakSelf.categoryView reloadData]; /// set up ... [weakSelf.view addSubview:weakSelf.pagerView]; RAC(weakSelf.lvheaderView.title_label, text) = [[RACObserve(weakSelf.viewModel.placeVideoListModel,examName) deliverOnMainThread] takeUntil:weakSelf.rac_willDeallocSignal]; } error:^(NSError * _Nullable error) { [MBProgressHUD rq_hideHUD]; [MBProgressHUD rq_showErrorTips:error]; }]; } [RQNotificationCenter removeObserver:self name:RQPlayVideoUrlNotification object:nil]; [RQ_Video_Module.playerController stop]; [[[[RQNotificationCenter rac_addObserverForName:RQPlayVideoUrlNotification object:nil] takeUntil:self.rac_willDeallocSignal] deliverOnMainThread] subscribeNext:^(NSNotification * note) { [weakSelf myVideoUrlNotification:note]; }]; // RQPlaceVideoListModel [self.lvheaderView.back_btn addTarget:self action:@selector(backActiondo:) forControlEvents:UIControlEventTouchUpInside]; } //返回 - (void)backActiondo:(UIButton *)btn{ [self.navigationController popViewControllerAnimated:YES]; } - (void)myVideoUrlNotification:(NSNotification *)note{ NSLog(@"RQNotificationCenter-----播放---AD-广告"); VideosItem *videosItem = note.object[RQPlayVideoItemKey]; // if(self.current_videosItem){ // self.current_videosItem.isPlaying = false; // } // videosItem.isPlaying = true; // self.current_videosItem = videosItem; NSArray *videoItemArr = note.object[RQPlayVideoItemArrKey]; NYLIVideoDetailSubPageViewController *videoDetailSubPageViewController = (NYLIVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(self.pagerView.listContainerView.currentIndex)]; if ([RQ_Video_Module isCanWatchWithVideosItem:videosItem]) { [RQ_Video_Module playVideoWithVideosItem:videosItem videosItemArr:videoItemArr playView:self.lvheaderView.play_view 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.lvheaderView; } - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView { return self.cycleScrollViewHeight; } - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return 0;//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.placeVideoListModel)) { NSArray *videosItemArr = [self.viewModel.placeVideoListModel.items.rac_sequence.signal map:^id _Nullable(RQPlaceVideoListModel *placeVideoListModel) { VideosItem *videosItem = [[VideosItem alloc] init]; videosItem.videoType = RQVideoType_Default; videosItem.video_url = placeVideoListModel.videoUrl; videosItem.coverFileUrl = placeVideoListModel.videoCover; videosItem.title = placeVideoListModel.videoName; videosItem.subject = self.viewModel.homePageSubjectType; videosItem.permission = [placeVideoListModel.permission integerValue]; videosItem.placeVideoListModel = self.viewModel.placeVideoListModel; videosItem.tryLookSecond = placeVideoListModel.tryLookSecond; return videosItem; }].toArray; NYLIVideoDetailSubPageViewModel *videoDetailSubPageViewModel = [[NYLIVideoDetailSubPageViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelTitleKey : self.viewModel.placeVideoListModel.examName, RQViewModelIDKey : @"", RQViewModelUtilKey : videosItemArr, RQViewCommonValueKey: self.viewModel.indexPath, RQHomeSubPageTypeKey: @(self.viewModel.homePageSubjectType), }]; NYLIVideoDetailSubPageViewController *videoDetailSubPageViewController = [[NYLIVideoDetailSubPageViewController alloc] initWithViewModel:videoDetailSubPageViewModel]; return videoDetailSubPageViewController; } else { NYLIVideoDetailSubPageViewModel *videoDetailSubPageViewModel = [[NYLIVideoDetailSubPageViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelTitleKey : @"", RQViewModelIDKey : @"", RQViewModelUtilKey : @[], RQViewCommonValueKey: [NSIndexPath indexPathForRow:0 inSection:0], RQHomeSubPageTypeKey: @(self.viewModel.homePageSubjectType), }]; NYLIVideoDetailSubPageViewController *videoDetailSubPageViewController = [[NYLIVideoDetailSubPageViewController 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 { NYLIVideoDetailSubPageViewController *videoDetailSubPageViewController = (NYLIVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(index)]; NYLIVideoDetailSubPageViewModel *videoDetailSubPageViewModel = (NYLIVideoDetailSubPageViewModel *)videoDetailSubPageViewController.viewModel; [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{ RQPlayVideoItemKey : videoDetailSubPageViewModel.videoArr.firstObject, RQPlayVideoItemArrKey : videoDetailSubPageViewModel.videoArr, }]; } - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index { NYLIVideoDetailSubPageViewController *videoDetailSubPageViewController = (NYLIVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(index)]; NYLIVideoDetailSubPageViewModel *videoDetailSubPageViewModel = (NYLIVideoDetailSubPageViewModel *)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 = 0; JXCategoryIndicatorImageView *indicatorImageView1 = [[JXCategoryIndicatorImageView alloc] init]; indicatorImageView1.componentPosition = JXCategoryComponentPosition_Top; indicatorImageView1.indicatorImageView.image = RQImageNamed(@"arrowUP"); indicatorImageView1.indicatorImageViewSize = CGSizeMake(self.cellWeight * (11 / 80.f), 0); _categoryView.indicators = @[indicatorImageView1]; _categoryView.defaultSelectedIndex = 0; /// !!!: 将列表容器视图关联到 categoryView _categoryView.listContainer = (id)self.pagerView.listContainerView; } return _categoryView; } - (NYLIVideoDetailHeaderView *)lvheaderView { if (!_lvheaderView) { _lvheaderView = [NYLIVideoDetailHeaderView liVideoDetailHeaderView]; } return _lvheaderView; } - (NSArray *)titles { if (!_titles) { _titles = @[@"侧方停车", @"倒车入库", @"坡道定点\n停车与起步", @"曲线行驶"]; } return _titles; } - (float)cycleScrollViewHeight { return RQ_FIT_HORIZONTAL(280.f); } - (float)cellWeight { return (RQ_SCREEN_WIDTH - (8 * 3) - (16 * 2)) / 4.f; } @end