RQHomePageSubjectOneOrFourViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. //
  2. // RQHomePageSubjectOneOrFourViewController.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2021/7/29.
  6. //
  7. #import "RQHomePageSubjectOneOrFourViewController.h"
  8. @interface RQHomePageSubjectOneOrFourViewController () <SDCycleScrollViewDelegate>
  9. /// viewModel
  10. @property (nonatomic, readonly, strong) RQHomePageSubjectOneOrFourViewModel *viewModel;
  11. @property (nonatomic, readwrite, strong) SDCycleScrollView *cycleScrollView;
  12. @property (nonatomic, readwrite, strong) NSArray *adArray;
  13. @end
  14. @implementation RQHomePageSubjectOneOrFourViewController
  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. #pragma mark - PrivateMethods
  27. /// 初始化
  28. - (void)rq_setup {
  29. /// set up ...
  30. self.collectionView.bounces = NO;
  31. self.collectionView.backgroundColor = UIColor.clearColor;
  32. }
  33. #pragma mark - OverrideMethods
  34. /// 配置tableView的区域
  35. - (UIEdgeInsets)contentInset {
  36. return UIEdgeInsetsMake((self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree)? 0 : 0, 0, RQ_APPLICATION_TOP_BAR_HEIGHT + RQHeightForPinSectionHeaderInPagerView_One + RQHeightForPinSectionHeaderInPagerView_Two + RQ_APPLICATION_TAB_BAR_HEIGHT + (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 0 : RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT), 0);
  37. }
  38. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  39. if ([self.viewModel.dataSource[indexPath.section] isKindOfClass:[RQHomeSubPageToolBarGroupViewModel class]] || [self.viewModel.dataSource[indexPath.section] isKindOfClass:[RQHomeSubPageToolBarOneGroupViewModel class]]) {
  40. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) {
  41. RQHomeSubPageVideoScrollCell *cell = [RQHomeSubPageVideoScrollCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  42. cell.superCollectionView = self.collectionView;
  43. return cell;
  44. } else {
  45. return [RQHomeSubPageCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  46. }
  47. } else if ([self.viewModel.dataSource[indexPath.section] isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) {
  48. return [RQHomeSubPageVideoCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  49. } else {
  50. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) {
  51. return [RQHomeSubPageNormalCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  52. } else {
  53. return [super collectionView:collectionView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
  54. }
  55. }
  56. switch (indexPath.section) {
  57. case 0: {
  58. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) {
  59. RQHomeSubPageVideoScrollCell *cell = [RQHomeSubPageVideoScrollCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  60. cell.superCollectionView = self.collectionView;
  61. return cell;
  62. } else {
  63. return [RQHomeSubPageCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  64. }
  65. }
  66. case 1: {
  67. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) {
  68. return [RQHomeSubPageNormalCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  69. } else {
  70. return [RQHomeSubPageVideoCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  71. }
  72. return [RQHomeSubPageVideoCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  73. }
  74. case 2: {
  75. return [RQHomeSubPageNormalCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  76. }
  77. default: {
  78. return [super collectionView:collectionView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
  79. }
  80. }
  81. }
  82. - (void)configureCell:(UICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  83. if ([self.viewModel.dataSource[indexPath.section] isKindOfClass:[RQHomeSubPageToolBarGroupViewModel class]] || [self.viewModel.dataSource[indexPath.section] isKindOfClass:[RQHomeSubPageToolBarOneGroupViewModel class]]) {
  84. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) {
  85. RQHomeSubPageVideoScrollCell *homeSubPageVideoScrollCell = (RQHomeSubPageVideoScrollCell *)cell;
  86. [homeSubPageVideoScrollCell bindViewModel:object];
  87. } else {
  88. RQHomeSubPageCell *homeSubPageCell = (RQHomeSubPageCell *)cell;
  89. [homeSubPageCell bindViewModel:object];
  90. }
  91. } else if ([self.viewModel.dataSource[indexPath.section] isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) {
  92. RQHomeSubPageVideoCell *homeSubPageVideoCell = (RQHomeSubPageVideoCell *)cell;
  93. [homeSubPageVideoCell bindViewModel:object];
  94. } else {
  95. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) {
  96. RQHomeSubPageNormalCell *homeSubPageNormalCell = (RQHomeSubPageNormalCell *)cell;
  97. [homeSubPageNormalCell bindViewModel:object];
  98. } else {
  99. [super configureCell:cell atIndexPath:indexPath withObject:object];
  100. }
  101. }
  102. return;
  103. switch (indexPath.section) {
  104. case 0: {
  105. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) {
  106. RQHomeSubPageVideoScrollCell *homeSubPageVideoScrollCell = (RQHomeSubPageVideoScrollCell *)cell;
  107. [homeSubPageVideoScrollCell bindViewModel:object];
  108. break;
  109. } else {
  110. RQHomeSubPageCell *homeSubPageCell = (RQHomeSubPageCell *)cell;
  111. [homeSubPageCell bindViewModel:object];
  112. }
  113. }
  114. case 1: {
  115. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) {
  116. RQHomeSubPageNormalCell *homeSubPageNormalCell = (RQHomeSubPageNormalCell *)cell;
  117. [homeSubPageNormalCell bindViewModel:object];
  118. break;
  119. } else {
  120. RQHomeSubPageVideoCell *homeSubPageVideoCell = (RQHomeSubPageVideoCell *)cell;
  121. [homeSubPageVideoCell bindViewModel:object];
  122. break;
  123. }
  124. }
  125. case 2: {
  126. RQHomeSubPageNormalCell *homeSubPageNormalCell = (RQHomeSubPageNormalCell *)cell;
  127. [homeSubPageNormalCell bindViewModel:object];
  128. break;
  129. }
  130. default: {
  131. [super configureCell:cell atIndexPath:indexPath withObject:object];
  132. break;
  133. }
  134. }
  135. }
  136. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  137. if ([self.viewModel.dataSource[section] isKindOfClass:[RQHomeSubPageToolBarGroupViewModel class]] || [self.viewModel.dataSource[section] isKindOfClass:[RQHomeSubPageToolBarOneGroupViewModel class]]) {
  138. return UIEdgeInsetsZero;
  139. } else if ([self.viewModel.dataSource[section] isKindOfClass:[RQHomeSubPageVideoHeaderGroupViewModel class]]) {
  140. return UIEdgeInsetsMake(0, 16, 0, 16);
  141. } else {
  142. return UIEdgeInsetsZero;
  143. }
  144. switch (section) {
  145. case 0: {
  146. return UIEdgeInsetsZero;
  147. }
  148. case 1: {
  149. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree) {
  150. return UIEdgeInsetsZero;
  151. } else {
  152. return UIEdgeInsetsMake(0, 16, 0, 16);
  153. }
  154. }
  155. default: {
  156. return UIEdgeInsetsZero;
  157. }
  158. }
  159. }
  160. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  161. // 如果是头视图
  162. if (kind == UICollectionElementKindSectionHeader) {
  163. if (indexPath.section == 0) {
  164. RQCommonReusableView *headerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  165. RQCommonReusableView *groupViewModel = self.viewModel.dataSource[indexPath.section];
  166. [headerView bindViewModel:groupViewModel];
  167. headerView.headerContentLabel.hidden = YES;
  168. headerView.footerContentLabel.hidden = YES;
  169. [headerView addSubview:self.cycleScrollView];
  170. if (self.adArray.count > 0) {
  171. NSMutableArray *myArr = [self.adArray.rac_sequence map:^id _Nullable(NSDictionary *dic) {
  172. return dic[@"IMG"];
  173. }].array.mutableCopy;
  174. if (RQ_COMMON_MANAGER.YYXC_AD_OPEN && RQ_COMMON_MANAGER.YYXC_NATIVE_AD_OPEN) {
  175. [myArr addObject:@"RQ-AD"];
  176. }
  177. self.cycleScrollView.imageURLStringsGroup = myArr.copy;
  178. } else {
  179. }
  180. return headerView;
  181. } else {
  182. RQHomeSubPageVideoHeaderCollectionReusableView *headerView = [RQHomeSubPageVideoHeaderCollectionReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  183. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  184. [headerView bindViewModel:groupViewModel];
  185. headerView.headerContentLabel.hidden = NO;
  186. headerView.footerContentLabel.hidden = YES;
  187. return headerView;
  188. }
  189. } else {
  190. if (indexPath.section == 0) {
  191. if ((self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo)) {
  192. RQHomeSubPageToolBarOneView *footerView = [RQHomeSubPageToolBarOneView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  193. RQHomeSubPageToolBarOneGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  194. [footerView bindViewModel:groupViewModel];
  195. footerView.headerContentLabel.hidden = YES;
  196. footerView.footerContentLabel.hidden = NO;
  197. return footerView;
  198. } else {
  199. RQHomeSubPageToolBarView *footerView = [RQHomeSubPageToolBarView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  200. RQHomeSubPageToolBarGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  201. [footerView bindViewModel:groupViewModel];
  202. footerView.headerContentLabel.hidden = YES;
  203. footerView.footerContentLabel.hidden = NO;
  204. return footerView;
  205. }
  206. } else {
  207. RQCommonReusableView *footerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  208. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  209. [footerView bindViewModel:groupViewModel];
  210. footerView.headerContentLabel.hidden = YES;
  211. footerView.footerContentLabel.hidden = NO;
  212. return footerView;
  213. }
  214. }
  215. }
  216. #pragma mark - UITableViewDelegate & UITableViewDataSource
  217. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  218. !self.scrollCallback ?: self.scrollCallback(scrollView);
  219. }
  220. #pragma mark - JXPagerViewListViewDelegate
  221. - (UIView *)listView {
  222. return self.view;
  223. }
  224. - (UIScrollView *)listScrollView {
  225. return self.collectionView;
  226. }
  227. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  228. self.scrollCallback = callback;
  229. }
  230. #pragma mark - SDCycleScrollViewDelegate
  231. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  232. // NSDictionary *dic = self.adArray[index];
  233. // [RQ_SHARE_FUNCTION saveObjectWithObject:dic ForKey:@"currentSelectDic"];
  234. // NSString *skipType = dic[@"OPENTYPE"];
  235. //
  236. // if ([skipType isEqualToString:@"1"]) {
  237. // [RQ_SHARE_FUNCTION gotoWebViewWithUrlStr:dic[@"URL"]];
  238. // }else{
  239. // if ([dic[@"ADTYPE"] isEqualToString:@"2"]) {
  240. // [RQ_SHARE_FUNCTION miniwithUserName:dic[@"URL"] path:dic[@"AI_XCX_URL"]? : @""];
  241. // } else if ([dic[@"ADTYPE"] isEqualToString:@"1"]) {
  242. // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dic[@"URL"]] options:nil completionHandler:^(BOOL success) {
  243. //
  244. // }];
  245. // } else if ([dic[@"ADTYPE"] isEqualToString:@"3"]) {
  246. // WXSubscribeMsgReq *req = [[WXSubscribeMsgReq alloc] init];
  247. // req.scene = 1;
  248. // req.templateId = @"1iZwYeI2QtSXZ3rTRkQ42wgRkd7NSINzem8R-LvtHYw";
  249. // req.reserved = @"";
  250. // [WXApi sendReq:req completion:nil];
  251. // }
  252. // }
  253. }
  254. #pragma mark - LazyLoad
  255. - (SDCycleScrollView *)cycleScrollView {
  256. if (!_cycleScrollView) {
  257. _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SHARE_FUNCTION.RQADViewHeight) imageNamesGroup:RQ_COMMON_MANAGER.YYXC_AD_OPEN? (RQ_COMMON_MANAGER.YYXC_NATIVE_AD_OPEN? @[@"subject_main_banner",@"RQ-AD"] : @[@"subject_main_banner"]) : @[@"subject_main_banner"]];
  258. _cycleScrollView.autoScrollTimeInterval = 5;
  259. _cycleScrollView.placeholderImage = RQImageNamed(@"未开发");
  260. _cycleScrollView.delegate = self;
  261. _cycleScrollView.backgroundColor = UIColor.whiteColor;
  262. }
  263. return _cycleScrollView;
  264. }
  265. - (NSArray *)adArray {
  266. //广告
  267. NSMutableArray *newAD = [NSMutableArray array];
  268. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectOne){
  269. for (NSDictionary *dic in myDelegate.adArray) {
  270. if ([dic[@"LOCATION"] isEqualToString:@"3"]) {
  271. [newAD addObject:dic];
  272. }
  273. }
  274. }else{
  275. for (NSDictionary *dic in myDelegate.adArray) {
  276. if ([dic[@"LOCATION"] isEqualToString:@"6"]) {
  277. [newAD addObject:dic];
  278. }
  279. }
  280. }
  281. return newAD.copy;
  282. }
  283. @end