NYLIVideoDetailViewController.m 13 KB

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