NYLIVideoDetailViewController.m 13 KB

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