NYLIVideoDetailViewController.m 12 KB

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