RQHomePageADCell.m 4.9 KB

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