RQVideoDetailViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. //
  2. // RQVideoDetailViewController.m
  3. // SDJK
  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. }
  34. - (void)viewWillAppear:(BOOL)animated {
  35. [super viewWillAppear:animated];
  36. RQ_Video_Module.playerController.viewControllerDisappear = NO;
  37. }
  38. - (void)viewWillDisappear:(BOOL)animated {
  39. [super viewWillDisappear:animated];
  40. RQ_Video_Module.playerController.viewControllerDisappear = YES;
  41. }
  42. #pragma mark - PrivateMethods
  43. /// 初始化
  44. - (void)rq_setup {
  45. @weakify(self)
  46. /// 播放
  47. [[[[RQNotificationCenter rac_addObserverForName:RQPlayVideoUrlNotification object:nil] takeUntil:self.rac_willDeallocSignal] deliverOnMainThread] subscribeNext:^(NSNotification * note) {
  48. @strongify(self)
  49. VideosItem *videosItem = note.object[RQPlayVideoItemKey];
  50. NSArray *videoItemArr = note.object[RQPlayVideoItemArrKey];
  51. RQVideoDetailSubPageViewController *videoDetailSubPageViewController = (RQVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(self.pagerView.listContainerView.currentIndex)];
  52. [RQ_Video_Module playVideoWithVideosItem:videosItem videosItemArr:videoItemArr playView:self.headerView scrollView:videoDetailSubPageViewController.tableView];
  53. }];
  54. NSMutableArray *typeNameStrArr = @[].mutableCopy;
  55. __block NSArray *typeNameArr = @[];
  56. if (self.viewModel.treeListModel) {
  57. [[self.viewModel.treeListModel.children.rac_sequence.signal deliverOnMainThread] subscribeNext:^(ChildrenItem *childrenItem) {
  58. @strongify(self)
  59. if (childrenItem.videos.count > 0) {
  60. [typeNameStrArr addObject:[self lineFeedWithStr:childrenItem.typeName]];
  61. } else {
  62. if (childrenItem.children.count > 0) {
  63. typeNameArr = [childrenItem.children.rac_sequence map:^id _Nullable(ChildrenItem *childrenItemA) {
  64. if (childrenItemA.videos.count > 0) {
  65. return [self lineFeedWithStr:childrenItemA.typeName];
  66. } else {
  67. return nil;
  68. }
  69. }].array;
  70. }
  71. }
  72. } completed:^{
  73. @strongify(self)
  74. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) {
  75. ChildrenItem *childrenItem = self.viewModel.treeListModel.children[self.viewModel.indexPath.section];
  76. if ([childrenItem.typeName isEqualToString:@"基础操作"]) {
  77. self.titles = typeNameStrArr.copy;
  78. } else {
  79. self.titles = typeNameArr;
  80. }
  81. } else {
  82. self.titles = typeNameStrArr.copy;
  83. }
  84. [self.pagerView setDefaultSelectedIndex:self.viewModel.index];
  85. [self.categoryView setDefaultSelectedIndex:self.viewModel.index];
  86. [self.categoryView reloadData];
  87. /// set up ...
  88. [self.view addSubview:self.pagerView];
  89. }];
  90. } else if (self.viewModel.currentVideoesArr) {
  91. [self.pagerView setDefaultSelectedIndex:self.viewModel.index];
  92. [self.categoryView setDefaultSelectedIndex:self.viewModel.index];
  93. [self.categoryView reloadData];
  94. self.titles = @[@""];
  95. /// set up ...
  96. [self.view addSubview:self.pagerView];
  97. }
  98. }
  99. - (NSString *)lineFeedWithStr:(NSString *)str {
  100. if (str.length > 8) {
  101. NSMutableString *strs = [[NSMutableString alloc] initWithString:str];
  102. [strs insertString:@"\n" atIndex:8];
  103. return strs.copy;
  104. } else {
  105. return str;
  106. }
  107. }
  108. #pragma mark - JXPagerViewDelegate
  109. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  110. return self.headerView;
  111. }
  112. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  113. return self.cycleScrollViewHeight;
  114. }
  115. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  116. return self.titles.count > 1? self.cellWeight * ((37.f + (4.3f * 2)) / 80.f) : 0;
  117. }
  118. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  119. return self.categoryView;
  120. }
  121. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  122. //和categoryView的item数量一致
  123. return self.categoryView.titles.count;
  124. }
  125. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  126. if (self.viewModel.treeListModel) {
  127. ChildrenItem *childrenItemA = self.viewModel.treeListModel.children[self.viewModel.indexPath.section];
  128. 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];
  129. RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = [[RQVideoDetailSubPageViewModel alloc] initWithServices:self.viewModel.services params:@{
  130. RQViewModelTitleKey : childrenItem.typeName,
  131. RQViewModelIDKey : childrenItem.typeDescribe? : @"",
  132. RQViewModelUtilKey : childrenItem.videos,
  133. RQViewCommonValueKey: self.viewModel.indexPath,
  134. RQVideoSourceTypeKey: @(RQVideoSourceType_Zzxcx),
  135. }];
  136. RQVideoDetailSubPageViewController *videoDetailSubPageViewController = [[RQVideoDetailSubPageViewController alloc] initWithViewModel:videoDetailSubPageViewModel];
  137. return videoDetailSubPageViewController;
  138. } else if (self.viewModel.currentVideoesArr) {
  139. RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = [[RQVideoDetailSubPageViewModel alloc] initWithServices:self.viewModel.services params:@{
  140. RQViewModelTitleKey : self.viewModel.title,
  141. RQViewModelIDKey : @"12580",
  142. RQViewModelUtilKey : self.viewModel.currentVideoesArr,
  143. RQViewCommonValueKey: self.viewModel.indexPath,
  144. RQVideoSourceTypeKey: @(RQVideoSourceType_LnJppt),
  145. }];
  146. RQVideoDetailSubPageViewController *videoDetailSubPageViewController = [[RQVideoDetailSubPageViewController alloc] initWithViewModel:videoDetailSubPageViewModel];
  147. return videoDetailSubPageViewController;
  148. } else {
  149. return nil;
  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. // ChildrenItem *childrenItemA = self.viewModel.treeListModel.children[self.viewModel.indexPath.section];
  158. // 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];
  159. RQVideoDetailSubPageViewController *videoDetailSubPageViewController = (RQVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(index)];
  160. RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = (RQVideoDetailSubPageViewModel *)videoDetailSubPageViewController.viewModel;
  161. [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{
  162. RQPlayVideoItemKey : videoDetailSubPageViewModel.videoArr.firstObject,
  163. RQPlayVideoItemArrKey : videoDetailSubPageViewModel.videoArr,
  164. }];
  165. }
  166. - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
  167. // ChildrenItem *childrenItemA = self.viewModel.treeListModel.children[self.viewModel.indexPath.section];
  168. // 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];
  169. RQVideoDetailSubPageViewController *videoDetailSubPageViewController = (RQVideoDetailSubPageViewController *)self.pagerView.listContainerView.validListDict[@(index)];
  170. RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = (RQVideoDetailSubPageViewModel *)videoDetailSubPageViewController.viewModel;
  171. [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{
  172. RQPlayVideoItemKey : videoDetailSubPageViewModel.videoArr.firstObject,
  173. RQPlayVideoItemArrKey : videoDetailSubPageViewModel.videoArr,
  174. }];
  175. }
  176. #pragma mark - JXPagerMainTableViewGestureDelegate
  177. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  178. if ([self checkIsNestContentScrollView:(UIScrollView *)gestureRecognizer.view] || [self checkIsNestContentScrollView:(UIScrollView *)otherGestureRecognizer.view]) {
  179. //如果交互的是嵌套的contentScrollView,证明在左右滑动,就不允许同时响应
  180. return NO;
  181. }
  182. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  183. }
  184. - (BOOL)checkIsNestContentScrollView:(UIScrollView *)scrollView {
  185. for (RQHomeSubPageViewController *list in self.pagerView.validListDict.allValues) {
  186. if (list.tableView == scrollView) {
  187. return YES;
  188. }
  189. }
  190. return NO;
  191. }
  192. #pragma mark - LazyLoad
  193. - (JXPagerView *)pagerView {
  194. if (!_pagerView) {
  195. _pagerView = [[JXPagerView alloc] initWithDelegate:self];
  196. _pagerView.mainTableView.gestureDelegate = self;
  197. _pagerView.mainTableView.bounces = NO;
  198. _pagerView.pinSectionHeaderVerticalOffset = self.cycleScrollViewHeight;
  199. _pagerView.isMirror = YES;
  200. }
  201. return _pagerView;
  202. }
  203. - (JXCategoryTitleBackgroundView *)categoryView {
  204. if (!_categoryView) {
  205. _categoryView = [[JXCategoryTitleBackgroundView alloc] init];
  206. _categoryView.delegate = self;
  207. _categoryView.titles = self.titles;
  208. _categoryView.titleSelectedColor = UIColor.whiteColor;
  209. _categoryView.titleColor = RQ_MAIN_TEXT_COLOR_2;
  210. _categoryView.titleFont = RQMediumFont(11);
  211. _categoryView.titleNumberOfLines = 0;
  212. _categoryView.titleSelectedFont = RQMediumFont(11);
  213. _categoryView.titleColorGradientEnabled = YES;
  214. _categoryView.contentEdgeInsetLeft = 16;
  215. _categoryView.contentEdgeInsetRight = 16;
  216. _categoryView.cellWidth = self.cellWeight;
  217. _categoryView.cellSpacing = 8;
  218. _categoryView.backgroundColor = RQ_BACKGROUNDCOLOR_1;
  219. _categoryView.backgroundHeight = self.cellWeight * (37.f / 80.f);
  220. JXCategoryIndicatorImageView *indicatorImageView1 = [[JXCategoryIndicatorImageView alloc] init];
  221. indicatorImageView1.componentPosition = JXCategoryComponentPosition_Top;
  222. indicatorImageView1.indicatorImageView.image = RQImageNamed(@"arrowUP");
  223. indicatorImageView1.indicatorImageViewSize = CGSizeMake(self.cellWeight * (11 / 80.f), self.cellWeight * (11 / 80.f) * (4.3f / 11.f));
  224. _categoryView.indicators = @[indicatorImageView1];
  225. _categoryView.defaultSelectedIndex = 0;
  226. /// !!!: 将列表容器视图关联到 categoryView
  227. _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  228. }
  229. return _categoryView;
  230. }
  231. - (UIView *)headerView {
  232. if (!_headerView) {
  233. _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, self.cycleScrollViewHeight)];
  234. }
  235. return _headerView;
  236. }
  237. - (NSArray<NSString *> *)titles {
  238. if (!_titles) {
  239. _titles = @[@"侧方停车", @"倒车入库", @"坡道定点\n停车与起步", @"曲线行驶"];
  240. }
  241. return _titles;
  242. }
  243. - (float)cycleScrollViewHeight {
  244. return RQ_FIT_HORIZONTAL(210.f);
  245. }
  246. - (float)cellWeight {
  247. return (RQ_SCREEN_WIDTH - (8 * 3) - (16 * 2)) / 4.f;
  248. }
  249. @end