NYFailSpecialExerciseDetailsViewController.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // NYFailSpecialExerciseDetailsViewController.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2024/12/12.
  6. // Copyright © 2024 JCZ. All rights reserved.
  7. //
  8. #import "NYFailSpecialExerciseDetailsViewController.h"
  9. @interface NYFailSpecialExerciseDetailsViewController ()
  10. /// viewModel
  11. @property (nonatomic, readonly, strong) NYFailSpecialExerciseDetailsViewModel *viewModel;
  12. @property (nonatomic, strong) UIView *headerView;
  13. @end
  14. @implementation NYFailSpecialExerciseDetailsViewController
  15. @dynamic viewModel;
  16. #pragma mark - SystemMethod
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. /// 初始化
  20. [self rq_setup];
  21. }
  22. - (void)viewDidLayoutSubviews {
  23. [super viewDidLayoutSubviews];
  24. self.view.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT);
  25. }
  26. - (void)dealloc {
  27. [RQ_Video_Module.playerController stop];
  28. if (self.headerView) {
  29. [self.headerView removeFromSuperview];
  30. self.headerView = nil;
  31. }
  32. }
  33. - (void)viewWillAppear:(BOOL)animated {
  34. [super viewWillAppear:animated];
  35. RQ_Video_Module.playerController.viewControllerDisappear = NO;
  36. }
  37. - (void)viewWillDisappear:(BOOL)animated {
  38. [super viewWillDisappear:animated];
  39. RQ_Video_Module.playerController.viewControllerDisappear = YES;
  40. }
  41. - (BOOL)shouldAutorotate {
  42. return NO;
  43. }
  44. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  45. if (RQ_Video_Module.playerController.player.isFullScreen) {
  46. return UIInterfaceOrientationMaskLandscape;
  47. }
  48. return UIInterfaceOrientationMaskPortrait;
  49. }
  50. #pragma mark - PrivateMethods
  51. /// 初始化
  52. - (void)rq_setup {
  53. /// set up ...
  54. self.collectionView.bounces = NO;
  55. self.collectionView.backgroundColor = UIColorHex(0xF2F8FF);
  56. [RQNotificationCenter removeObserver:self name:RQPlayVideoUrlNotification object:nil];
  57. /// 播放
  58. WeakSelf(weakSelf)
  59. [RQ_Video_Module.playerController stop];
  60. [[[[RQNotificationCenter rac_addObserverForName:RQPlayVideoUrlNotification object:nil] takeUntil:self.rac_willDeallocSignal] deliverOnMainThread] subscribeNext:^(NSNotification * note) {
  61. [weakSelf myVideoUrlNotification:note];
  62. }];
  63. }
  64. - (void)myVideoUrlNotification:(NSNotification *)note{
  65. NSLog(@"RQNotificationCenter-----播放---AD-广告");
  66. VideosItem *videosItem = note.object[RQPlayVideoItemKey];
  67. NSArray *videoItemArr = note.object[RQPlayVideoItemArrKey];
  68. if ([RQ_Video_Module isCanWatchWithVideosItem:videosItem]) {
  69. [RQ_Video_Module playVideoWithVideosItem:videosItem videosItemArr:videoItemArr playView:self.headerView scrollView:self.collectionView];
  70. }
  71. }
  72. #pragma mark - OverrideMethods
  73. /// 配置collectionView的区域
  74. - (UIEdgeInsets)contentInset {
  75. return UIEdgeInsetsMake(RQ_APPLICATION_STATUS_BAR_HEIGHT + RQ_APPLICATION_NAV_BAR_HEIGHT, 0, 0, 0);
  76. }
  77. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  78. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  79. RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  80. UICollectionViewCell *cell = [NSClassFromString(itemViewModel.itemClassName) cellWithCollectionView:collectionView forIndexPath:indexPath];
  81. return cell;
  82. }
  83. - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  84. NSLog(@"configureCell=====%@",indexPath);
  85. [cell bindViewModel:object];
  86. }
  87. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  88. return UIEdgeInsetsMake(0, 0, 0, 0);
  89. }
  90. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  91. // @weakify(self)
  92. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  93. // 如果是头视图
  94. if (kind == UICollectionElementKindSectionHeader) {
  95. if ([groupViewModel isKindOfClass:[NYFailSpecialVideoGroupViewModel class]]) {
  96. NYFailSpecialVideoHeaderView *headerView = [NYFailSpecialVideoHeaderView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  97. self.headerView = headerView.palyerView;
  98. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  99. [headerView bindViewModel:groupViewModel];
  100. headerView.headerContentLabel.hidden = YES;
  101. headerView.footerContentLabel.hidden = YES;
  102. return headerView;
  103. }
  104. }
  105. RQCommonReusableView *headerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  106. [headerView bindViewModel:groupViewModel];
  107. headerView.headerContentLabel.hidden = YES;
  108. headerView.footerContentLabel.hidden = YES;
  109. return headerView;
  110. }
  111. @end