GromoreDemoLoadAdView.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //
  2. // ABUDemoLoadAdView.m
  3. // ABUDemo
  4. //
  5. // Created by heyinyin on 2021/12/15.
  6. // Copyright © 2021 bytedance. All rights reserved.
  7. //
  8. #import "GromoreDemoLoadAdView.h"
  9. #import "GromoreDemoAdBasicInfoCell.h"
  10. #import "GromoreDemoAdStatusCell.h"
  11. #import "GromoreAdLoadConfig.h"
  12. #import "GromoreDemoAdConsoleView.h"
  13. #import "GromoreDemoAdDisplayView.h"
  14. #import "GromoreDemoDeviceInfoView.h"
  15. static NSString *adBasicCell = @"GROMORE_DEMO_BASIC_CELL";
  16. static NSString *adHandleCell = @"GROMORE_DEMO_HANDLE_CELL";
  17. static NSString *adStatusCell = @"GROMORE_DEMO_STATUS_CELL";
  18. @interface GromoreDemoLoadAdView () <UITableViewDelegate, UITableViewDataSource, GromoreDemoSelectedAdDelegate, GromoreDemoAdHandleDelegate>
  19. @property (nonatomic, strong) UITableView *tableView;
  20. @property (nonatomic, copy) NSString *adType;
  21. @property (nonatomic, strong) GromoreAdLoadConfig *adConfig;
  22. @property (nonatomic, strong) GromoreDemoAdConsoleView *consoleView;
  23. @property (nonatomic, strong) GromoreDemoAdHandleCell *handleCell;
  24. @end
  25. @implementation GromoreDemoLoadAdView
  26. - (instancetype)init {
  27. if (self = [super init]) {
  28. CGRect frame = [UIScreen mainScreen].bounds;
  29. self.frame = frame;
  30. [self initTableviewWithFrame:frame];
  31. [self initBannerBack];
  32. [self initConsoleNoticeView];
  33. }
  34. return self;
  35. }
  36. - (void)initTableviewWithFrame:(CGRect)frame {
  37. if (!_tableView) {
  38. _tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
  39. _tableView.delegate = self;
  40. _tableView.dataSource = self;
  41. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  42. _tableView.showsVerticalScrollIndicator = NO;
  43. _tableView.scrollEnabled = NO;
  44. [_tableView registerClass:[GromoreDemoAdBasicInfoCell class] forCellReuseIdentifier:adBasicCell];
  45. [_tableView registerClass:[GromoreDemoAdHandleCell class] forCellReuseIdentifier:adHandleCell];
  46. [_tableView registerClass:[GromoreDemoAdStatusCell class] forCellReuseIdentifier:adStatusCell];
  47. [self addSubview:_tableView];
  48. }
  49. }
  50. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  51. if (section == 0) {
  52. CGFloat y = 44;
  53. CGFloat width = CGRectGetWidth(self.frame);
  54. UIView *view = [[UIView alloc] initWithFrame:CGRectMake( 0, y, width, 32)];
  55. UILabel *noticeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 6, width, 20)];
  56. noticeLabel.textColor = RQ_MAIN_COLOR;
  57. noticeLabel.font = RQRegularFont(10);
  58. noticeLabel.text = @"点击后选中广告类型及广告位ID";
  59. [view addSubview:noticeLabel];
  60. view.backgroundColor = [UIColor whiteColor];
  61. view.alpha = 0.7;
  62. return view;
  63. } else {
  64. return [UIView new];
  65. }
  66. }
  67. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  68. return [UIView new];
  69. }
  70. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  71. if (indexPath.section == 0) {
  72. GromoreDemoAdBasicInfoCell *cell = (GromoreDemoAdBasicInfoCell *)[tableView dequeueReusableCellWithIdentifier:adBasicCell];
  73. cell.delegate = self;
  74. return cell;
  75. } else if (indexPath.section == 1) {
  76. GromoreDemoAdHandleCell *cell = (GromoreDemoAdHandleCell *)[tableView dequeueReusableCellWithIdentifier:adHandleCell];
  77. cell.delegate = self;
  78. return cell;
  79. } else if (indexPath.section == 2) {
  80. GromoreDemoAdStatusCell *cell = (GromoreDemoAdStatusCell *)[tableView dequeueReusableCellWithIdentifier:adStatusCell];
  81. return cell;
  82. }
  83. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:adHandleCell];
  84. return cell;
  85. }
  86. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  87. return 3;
  88. }
  89. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  90. return 1;
  91. }
  92. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  93. switch (indexPath.section) {
  94. case 0:
  95. return 35 * 3;
  96. case 1:
  97. return 120;
  98. default:
  99. return 220;
  100. }
  101. }
  102. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  103. if (section == 0) {
  104. return 32;
  105. }
  106. return 1.0;
  107. }
  108. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  109. return 7.0;
  110. }
  111. /// 底部banner展位
  112. - (void)initBannerBack {
  113. CGFloat height = CGRectGetWidth([UIScreen mainScreen].bounds) * 180 / 414;
  114. _backView = [[GromoreDemoAdDisplayView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_tableView.frame) - height, CGRectGetWidth(_tableView.frame), height)];
  115. _backView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5];
  116. [self addSubview:_backView];
  117. }
  118. - (void)initConsoleNoticeView {
  119. _consoleView = [[GromoreDemoAdConsoleView alloc] init];
  120. [self addSubview:_consoleView];
  121. }
  122. - (void)adStatusChanged:(GromoreDemoAdStatus)status {
  123. [_handleCell changeAdStatus:status];
  124. }
  125. - (void)showDeviceInfo:(UIButton *)sender {
  126. [sender setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  127. [GromoreDemoDeviceInfoView show];
  128. }
  129. #pragma mark ----- GromoreDemoSelectedAdDelegate -----
  130. - (void)didSelectAdConfig:(GromoreAdLoadConfig *)adConfig {
  131. _adConfig = adConfig;
  132. self.updateTitleAction(adConfig.adDesc);
  133. [self resetCallbackInfo];
  134. }
  135. #pragma mark ----- GromoreDemoAdHandleDelegate -----
  136. - (void)showConsole:(BOOL)ifShowConsole {
  137. self.consoleView.hidden = !ifShowConsole;
  138. }
  139. - (void)showButtonDidClick:(GromoreDemoAdHandleCell *)sender {
  140. if ([self.delegate respondsToSelector:@selector(startShowAd)]) {
  141. [self.delegate startShowAd];
  142. }
  143. }
  144. - (void)loadButtonDidClick:(GromoreDemoAdHandleCell *)sender {
  145. [self resetCallbackInfo];
  146. if ([self.delegate respondsToSelector:@selector(startLoadAdWithConfig:andParam:)]) {
  147. GromoreAdLoadParam *param = [[GromoreAdLoadParam alloc] init];
  148. param.showAfterLoad = sender.showAdAfterLoad;
  149. [self.delegate startLoadAdWithConfig:self.adConfig andParam:param];
  150. _handleCell = sender;
  151. }
  152. }
  153. // 重置回调信息栏
  154. - (void)resetCallbackInfo {
  155. [[NSNotificationCenter defaultCenter] postNotificationName:GromoreDemoAdStatusCellReviceClearNotification object:nil userInfo:nil];
  156. }
  157. @end
  158. /*
  159. 1. option | enable
  160. 2. switch | enable
  161. 3. segment | enable
  162. */