RQHomePageADCell.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // RQHomePageADCell.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/6/20.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQHomePageADCell.h"
  9. @interface RQHomePageADCell () <SDCycleScrollViewDelegate>
  10. @property (nonatomic, readwrite, strong) RQHomePageADItemViewModel *viewModel;
  11. @property (nonatomic, readwrite, strong) SDCycleScrollView *myCycleScrollView;
  12. @property (nonatomic, readwrite, strong) NSArray *adArray;
  13. @property (weak, nonatomic) IBOutlet UIView *myADView;
  14. @end
  15. @implementation RQHomePageADCell
  16. #pragma mark - PublicMethods
  17. + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
  18. static NSString *ID = @"RQHomePageADCell";
  19. [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
  20. RQHomePageADCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
  21. if (!cell) cell = [self rq_viewFromXib];
  22. return cell;
  23. }
  24. - (void)bindViewModel:(RQHomePageADItemViewModel *)viewModel {
  25. _viewModel = viewModel;
  26. if (self.adArray.count > 0) {
  27. NSMutableArray *arr = [self.adArray.rac_sequence map:^id _Nullable(NSDictionary *dic) {
  28. return dic[@"IMG"];
  29. }].array.mutableCopy;
  30. if (arr.count >= 1) {
  31. [arr insertObject:@"RQ-AD" atIndex:1];
  32. } else {
  33. [arr addObject:@"RQ-AD"];
  34. }
  35. self.myCycleScrollView.imageURLStringsGroup = arr.copy;
  36. } else {
  37. }
  38. }
  39. #pragma mark - SystemMethods
  40. - (void)awakeFromNib {
  41. [super awakeFromNib];
  42. [self.myADView addSubview:self.myCycleScrollView];
  43. }
  44. #pragma mark - SDCycleScrollViewDelegate
  45. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  46. if (RQ_COMMON_MANAGER.APP_SWITCH)return;//审核阶段不显示
  47. if (self.adArray.count >= 1) {
  48. if (index == 1) return;
  49. } else {
  50. if (index >= self.adArray.count) return;
  51. }
  52. @try {
  53. NSDictionary *dic = nil;
  54. if (self.adArray.count >= 1) {
  55. dic = self.adArray[index-1];
  56. }else{
  57. dic = self.adArray[index];
  58. }
  59. [RQ_SHARE_FUNCTION saveObjectWithObject:dic ForKey:@"currentSelectDic"];
  60. NSString *skipType = dic[@"OPENTYPE"];
  61. if ([skipType isEqualToString:@"1"]) {
  62. [RQ_SHARE_FUNCTION gotoWebViewWithUrlStr:dic[@"URL"]];
  63. }else{
  64. if ([dic[@"ADTYPE"] isEqualToString:@"2"]) {
  65. [RQ_SHARE_FUNCTION miniwithUserName:dic[@"URL"] path:dic[@"AI_XCX_URL"]? : @""];
  66. } else if ([dic[@"ADTYPE"] isEqualToString:@"1"]) {
  67. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dic[@"URL"]] options:@{} completionHandler:^(BOOL success) {
  68. }];
  69. } else if ([dic[@"ADTYPE"] isEqualToString:@"3"]) {
  70. WXSubscribeMsgReq *req = [[WXSubscribeMsgReq alloc] init];
  71. req.scene = 1;
  72. req.templateId = @"1iZwYeI2QtSXZ3rTRkQ42wgRkd7NSINzem8R-LvtHYw";
  73. req.reserved = @"";
  74. [WXApi sendReq:req completion:nil];
  75. }
  76. }
  77. } @catch (NSException *exception) {
  78. NSLog(@"%@",exception.description);
  79. }
  80. }
  81. - (SDCycleScrollView *)myCycleScrollView {
  82. if (!_myCycleScrollView) {
  83. _myCycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(16, 16, RQ_SCREEN_WIDTH - 32.f, (RQ_SCREEN_WIDTH - 32.f) * (80 / 345.f)) imageNamesGroup:@[@"adPlaceHolder"]];
  84. // _myCycleScrollView.layer.cornerRadius = 10.f;
  85. // _myCycleScrollView.layer.masksToBounds = YES;
  86. _myCycleScrollView.localizationImageNamesGroup = @[@"adPlaceHolder"];
  87. _myCycleScrollView.delegate = self;
  88. _myCycleScrollView.autoScrollTimeInterval = 5;
  89. _myCycleScrollView.placeholderImage = RQImageNamed(@"adPlaceHolder");
  90. _myCycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
  91. }
  92. return _myCycleScrollView;
  93. }
  94. - (NSArray *)adArray {
  95. //广告
  96. NSMutableArray *newAD = [NSMutableArray array];
  97. if (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectOne) {
  98. for (NSDictionary *dic in myDelegate.adArray) {
  99. if ([dic[@"LOCATION"] isEqualToString:@"3"]) {
  100. [newAD addObject:dic];
  101. }
  102. }
  103. }else{
  104. for (NSDictionary *dic in myDelegate.adArray) {
  105. if ([dic[@"LOCATION"] isEqualToString:@"6"]) {
  106. [newAD addObject:dic];
  107. }
  108. }
  109. }
  110. return newAD.copy;
  111. }
  112. @end