NYLIVideoDetailViewController.m 14 KB

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