RQVideoDetailViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. //
  2. // RQVideoDetailViewController.m
  3. // JSJP
  4. //
  5. // Created by 张嵘 on 2021/10/25.
  6. // 视频详情页面
  7. #import "RQVideoDetailViewController.h"
  8. @interface RQVideoDetailViewController () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate>
  9. /// viewModel
  10. @property (nonatomic, readonly, strong) RQVideoDetailViewModel *viewModel;
  11. @property (nonatomic, readwrite, strong) JXPagerView *pagerView;
  12. @property (nonatomic, readwrite, strong) JXCategoryTitleBackgroundView *categoryView;
  13. @property (nonatomic, readwrite, strong) UIView *headerView;
  14. @property (nonatomic, readwrite, strong) NSArray <NSString *> *titles;
  15. @property (nonatomic, readwrite, strong) NSArray <NSString *> *imagesArr;
  16. @property (nonatomic, readonly, assign) float cycleScrollViewHeight;
  17. @property (nonatomic, readonly, assign) float cellWeight;
  18. @end
  19. @implementation RQVideoDetailViewController
  20. @dynamic viewModel;
  21. #pragma mark - SystemMethod
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. /// 初始化
  25. [self rq_setup];
  26. }
  27. - (void)viewDidLayoutSubviews {
  28. [super viewDidLayoutSubviews];
  29. 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);
  30. }
  31. - (void)dealloc {
  32. [RQ_Video_Module.playerController stop];
  33. if (self.headerView) {
  34. [self.headerView removeFromSuperview];
  35. self.headerView = nil;
  36. }
  37. }
  38. - (void)viewWillAppear:(BOOL)animated {
  39. [super viewWillAppear:animated];
  40. RQ_Video_Module.playerController.viewControllerDisappear = NO;
  41. }
  42. - (void)viewWillDisappear:(BOOL)animated {
  43. [super viewWillDisappear:animated];
  44. RQ_Video_Module.playerController.viewControllerDisappear = YES;
  45. }
  46. - (BOOL)shouldAutorotate {
  47. return NO;
  48. }
  49. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  50. if (RQ_Video_Module.playerController.player.isFullScreen) {
  51. return UIInterfaceOrientationMaskLandscape;
  52. }
  53. return UIInterfaceOrientationMaskPortrait;
  54. }
  55. #pragma mark - PrivateMethods
  56. /// 初始化
  57. - (void)rq_setup {
  58. NSMutableArray *typeNameStrArr = @[].mutableCopy;
  59. __block NSArray *typeNameArr = @[];
  60. @weakify(self)
  61. if (!RQObjectIsNil(self.viewModel.treeListModel)) {
  62. [[self.viewModel.treeListModel.children.rac_sequence.signal deliverOnMainThread] subscribeNext:^(ChildrenItem *childrenItem) {
  63. @strongify(self)
  64. if (childrenItem.videos.count > 0) {
  65. [typeNameStrArr addObject:[self lineFeedWithStr:childrenItem.typeName]];
  66. } else {
  67. if (childrenItem.children.count > 0) {
  68. typeNameArr = [childrenItem.children.rac_sequence map:^id _Nullable(ChildrenItem *childrenItemA) {
  69. @strongify(self)
  70. if (childrenItemA.videos.count > 0) {
  71. return [self lineFeedWithStr:childrenItemA.typeName];
  72. } else {
  73. return nil;
  74. }
  75. }].array;
  76. }
  77. }
  78. } completed:^{
  79. @strongify(self)
  80. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) {
  81. ChildrenItem *childrenItem = self.viewModel.treeListModel.children[self.viewModel.indexPath.section];
  82. if ([childrenItem.typeName isEqualToString:@"基础操作"]) {
  83. self.titles = typeNameStrArr.copy;
  84. } else {
  85. self.titles = typeNameArr;
  86. }
  87. } else {
  88. self.titles = typeNameStrArr.copy;
  89. }
  90. [self.pagerView setDefaultSelectedIndex:self.viewModel.index];
  91. [self.categoryView setDefaultSelectedIndex:self.viewModel.index];
  92. [self.categoryView reloadData];
  93. /// set up ...
  94. [self.view addSubview:self.pagerView];
  95. }];
  96. }
  97. if (!RQObjectIsNil(self.viewModel.placeVideoListModel)) {
  98. self.titles = @[@""];
  99. [self.pagerView setDefaultSelectedIndex:0];
  100. [self.categoryView setDefaultSelectedIndex:0];
  101. [self.categoryView reloadData];
  102. /// set up ...
  103. [self.view addSubview:self.pagerView];
  104. }
  105. [RQNotificationCenter removeObserver:self name:RQPlayVideoUrlNotification object:nil];
  106. /// 播放
  107. WeakSelf(weakSelf)
  108. [RQ_Video_Module.playerController stop];
  109. RQ_Video_Module.videoDetailViewController = self;
  110. // [[RQNotificationCenter rac_addObserverForName:RQPlayVideoUrlNotification object:nil] subscribeNext:^(NSNotification *note) {
  111. // [weakSelf myVideoUrlNotification:note];
  112. // }];
  113. [[[[RQNotificationCenter rac_addObserverForName:RQPlayVideoUrlNotification object:nil] takeUntil:self.rac_willDeallocSignal] deliverOnMainThread] subscribeNext:^(NSNotification * note) {
  114. [weakSelf myVideoUrlNotification:note];
  115. //@strongify(self)
  116. // NSLog(@"RQNotificationCenter-----播放");
  117. // VideosItem *videosItem = note.object[RQPlayVideoItemKey];
  118. // NSArray *videoItemArr = note.object[RQPlayVideoItemArrKey];
  119. // RQVideoDetailSubPageViewController *videoDetailSubPageViewController = (RQVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(self.pagerView.listContainerView.currentIndex)];
  120. // if ([RQ_Video_Module isCanWatchWithVideosItem:videosItem]) {
  121. // [RQ_Video_Module playVideoWithVideosItem:videosItem videosItemArr:videoItemArr playView:self.headerView scrollView:videoDetailSubPageViewController.tableView];
  122. // }
  123. }];
  124. }
  125. - (void)myVideoUrlNotification:(NSNotification *)note{
  126. NSLog(@"RQNotificationCenter-----播放---AD-广告");
  127. VideosItem *videosItem = note.object[RQPlayVideoItemKey];
  128. NSArray *videoItemArr = note.object[RQPlayVideoItemArrKey];
  129. RQVideoDetailSubPageViewController *videoDetailSubPageViewController = (RQVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(self.pagerView.listContainerView.currentIndex)];
  130. if ([RQ_Video_Module isCanWatchWithVideosItem:videosItem]) {
  131. [RQ_Video_Module playVideoWithVideosItem:videosItem videosItemArr:videoItemArr playView:self.headerView scrollView:videoDetailSubPageViewController.tableView];
  132. }
  133. }
  134. - (NSString *)lineFeedWithStr:(NSString *)str {
  135. if (str.length > 8) {
  136. NSMutableString *strs = [[NSMutableString alloc] initWithString:str];
  137. [strs insertString:@"\n" atIndex:8];
  138. return strs.copy;
  139. } else {
  140. return str;
  141. }
  142. }
  143. #pragma mark - JXPagerViewDelegate
  144. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  145. return self.headerView;
  146. }
  147. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  148. return self.cycleScrollViewHeight;
  149. }
  150. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  151. return self.titles.count > 1? self.cellWeight * ((37.f + (4.3f * 2)) / 80.f) : 0;
  152. }
  153. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  154. return self.categoryView;
  155. }
  156. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  157. //和categoryView的item数量一致
  158. return self.categoryView.titles.count;
  159. }
  160. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  161. if (!RQObjectIsNil(self.viewModel.treeListModel)) {
  162. ChildrenItem *childrenItemA = self.viewModel.treeListModel.children[self.viewModel.indexPath.section];
  163. 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];
  164. RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = [[RQVideoDetailSubPageViewModel alloc] initWithServices:self.viewModel.services params:@{
  165. RQViewModelTitleKey : childrenItem.typeName,
  166. RQViewModelIDKey : childrenItem.typeDescribe? : @"",
  167. RQViewModelUtilKey : childrenItem.videos,
  168. RQViewCommonValueKey: self.viewModel.indexPath,
  169. RQHomeSubPageTypeKey: @(self.viewModel.homePageSubjectType),
  170. }];
  171. RQVideoDetailSubPageViewController *videoDetailSubPageViewController = [[RQVideoDetailSubPageViewController alloc] initWithViewModel:videoDetailSubPageViewModel];
  172. return videoDetailSubPageViewController;
  173. } else {
  174. if (!RQObjectIsNil(self.viewModel.placeVideoListModel)) {
  175. NSArray *videosItemArr = [self.viewModel.placeVideoListModel.items.rac_sequence.signal map:^id _Nullable(RQPlaceVideoListModel *placeVideoListModel) {
  176. VideosItem *videosItem = [[VideosItem alloc] init];
  177. videosItem.videoType = RQVideoType_KaoChang;
  178. videosItem.video_url = placeVideoListModel.videoUrl;
  179. videosItem.coverFileUrl = placeVideoListModel.videoCover;
  180. videosItem.title = placeVideoListModel.videoName;
  181. videosItem.permission = [placeVideoListModel.permission integerValue];
  182. videosItem.placeVideoListModel = self.viewModel.placeVideoListModel;
  183. return videosItem;
  184. }].toArray;
  185. RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = [[RQVideoDetailSubPageViewModel alloc] initWithServices:self.viewModel.services params:@{
  186. RQViewModelTitleKey : self.viewModel.placeVideoListModel.examName,
  187. RQViewModelIDKey : @"",
  188. RQViewModelUtilKey : videosItemArr,
  189. RQViewCommonValueKey: self.viewModel.indexPath,
  190. RQHomeSubPageTypeKey: @(self.viewModel.homePageSubjectType),
  191. }];
  192. RQVideoDetailSubPageViewController *videoDetailSubPageViewController = [[RQVideoDetailSubPageViewController alloc] initWithViewModel:videoDetailSubPageViewModel];
  193. return videoDetailSubPageViewController;
  194. } else {
  195. RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = [[RQVideoDetailSubPageViewModel alloc] initWithServices:self.viewModel.services params:@{
  196. RQViewModelTitleKey : @"",
  197. RQViewModelIDKey : @"",
  198. RQViewModelUtilKey : @[],
  199. RQViewCommonValueKey: [NSIndexPath indexPathForRow:0 inSection:0],
  200. RQHomeSubPageTypeKey: @(self.viewModel.homePageSubjectType),
  201. }];
  202. RQVideoDetailSubPageViewController *videoDetailSubPageViewController = [[RQVideoDetailSubPageViewController alloc] initWithViewModel:videoDetailSubPageViewModel];
  203. return videoDetailSubPageViewController;
  204. }
  205. }
  206. }
  207. #pragma mark - JXCategoryViewDelegate
  208. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  209. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  210. }
  211. - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
  212. RQVideoDetailSubPageViewController *videoDetailSubPageViewController = (RQVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(index)];
  213. RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = (RQVideoDetailSubPageViewModel *)videoDetailSubPageViewController.viewModel;
  214. [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{
  215. RQPlayVideoItemKey : videoDetailSubPageViewModel.videoArr.firstObject,
  216. RQPlayVideoItemArrKey : videoDetailSubPageViewModel.videoArr,
  217. }];
  218. }
  219. - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
  220. RQVideoDetailSubPageViewController *videoDetailSubPageViewController = (RQVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(index)];
  221. RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = (RQVideoDetailSubPageViewModel *)videoDetailSubPageViewController.viewModel;
  222. [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{
  223. RQPlayVideoItemKey : videoDetailSubPageViewModel.videoArr.firstObject,
  224. RQPlayVideoItemArrKey : videoDetailSubPageViewModel.videoArr,
  225. }];
  226. }
  227. #pragma mark - JXPagerMainTableViewGestureDelegate
  228. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  229. if ([self checkIsNestContentScrollView:(UIScrollView *)gestureRecognizer.view] || [self checkIsNestContentScrollView:(UIScrollView *)otherGestureRecognizer.view]) {
  230. //如果交互的是嵌套的contentScrollView,证明在左右滑动,就不允许同时响应
  231. return NO;
  232. }
  233. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  234. }
  235. - (BOOL)checkIsNestContentScrollView:(UIScrollView *)scrollView {
  236. for (RQHomeSubPageViewController *list in self.pagerView.validListDict.allValues) {
  237. if (list.tableView == scrollView) {
  238. return YES;
  239. }
  240. }
  241. return NO;
  242. }
  243. #pragma mark - LazyLoad
  244. - (JXPagerView *)pagerView {
  245. if (!_pagerView) {
  246. _pagerView = [[JXPagerView alloc] initWithDelegate:self];
  247. _pagerView.mainTableView.gestureDelegate = self;
  248. _pagerView.mainTableView.bounces = NO;
  249. _pagerView.pinSectionHeaderVerticalOffset = self.cycleScrollViewHeight;
  250. _pagerView.isMirror = YES;
  251. }
  252. return _pagerView;
  253. }
  254. - (JXCategoryTitleBackgroundView *)categoryView {
  255. if (!_categoryView) {
  256. _categoryView = [[JXCategoryTitleBackgroundView alloc] init];
  257. _categoryView.delegate = self;
  258. _categoryView.titles = self.titles;
  259. _categoryView.titleSelectedColor = UIColor.whiteColor;
  260. _categoryView.titleColor = RQ_MAIN_TEXT_COLOR_2;
  261. _categoryView.titleFont = RQMediumFont(11);
  262. _categoryView.titleNumberOfLines = 0;
  263. _categoryView.titleSelectedFont = RQMediumFont(11);
  264. _categoryView.titleColorGradientEnabled = YES;
  265. _categoryView.contentEdgeInsetLeft = 16;
  266. _categoryView.contentEdgeInsetRight = 16;
  267. _categoryView.cellWidth = self.cellWeight;
  268. _categoryView.cellSpacing = 8;
  269. _categoryView.backgroundColor = RQ_BACKGROUNDCOLOR_1;
  270. _categoryView.backgroundHeight = self.cellWeight * (37.f / 80.f);
  271. JXCategoryIndicatorImageView *indicatorImageView1 = [[JXCategoryIndicatorImageView alloc] init];
  272. indicatorImageView1.componentPosition = JXCategoryComponentPosition_Top;
  273. indicatorImageView1.indicatorImageView.image = RQImageNamed(@"arrowUP");
  274. indicatorImageView1.indicatorImageViewSize = CGSizeMake(self.cellWeight * (11 / 80.f), self.cellWeight * (11 / 80.f) * (4.3f / 11.f));
  275. _categoryView.indicators = @[indicatorImageView1];
  276. _categoryView.defaultSelectedIndex = 0;
  277. /// !!!: 将列表容器视图关联到 categoryView
  278. _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  279. }
  280. return _categoryView;
  281. }
  282. - (UIView *)headerView {
  283. if (!_headerView) {
  284. _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, self.cycleScrollViewHeight)];
  285. }
  286. return _headerView;
  287. }
  288. - (NSArray<NSString *> *)titles {
  289. if (!_titles) {
  290. _titles = @[@"侧方停车", @"倒车入库", @"坡道定点\n停车与起步", @"曲线行驶"];
  291. }
  292. return _titles;
  293. }
  294. - (float)cycleScrollViewHeight {
  295. return RQ_FIT_HORIZONTAL(210.f);
  296. }
  297. - (float)cellWeight {
  298. return (RQ_SCREEN_WIDTH - (8 * 3) - (16 * 2)) / 4.f;
  299. }
  300. @end