123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- //
- // RQVideoDetailViewController.m
- // JSJP
- //
- // Created by 张嵘 on 2021/10/25.
- // 视频详情页面
- #import "RQVideoDetailViewController.h"
- @interface RQVideoDetailViewController () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate>
- /// 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 <NSString *> *titles;
- @property (nonatomic, readwrite, strong) NSArray <NSString *> *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<JXPagerViewListViewDelegate>)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<JXCategoryViewListContainer>)self.pagerView.listContainerView;
- }
- return _categoryView;
- }
- - (UIView *)headerView {
- if (!_headerView) {
- _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, self.cycleScrollViewHeight)];
- }
- return _headerView;
- }
- - (NSArray<NSString *> *)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
|