XYHotGiveRewardSheetViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. //
  2. // XYHotGiveRewardSheetViewController.m
  3. // Timi
  4. //
  5. // Created by 翟玉磊 on 2021/11/16.
  6. //
  7. #import "XYHotGiveRewardSheetViewController.h"
  8. #import "XYHotGiveRewardSheetViewModel.h"
  9. #import "XYHotGiveRewardUserListTableViewCell.h"
  10. #import "XYHotGiveRewardUserListModel.h"
  11. #import "XYUserDynamicListCellModel.h"
  12. typedef void(^SelectedDidBlock)(BOOL success, XYUserDynamicListCellModel *dynamicModel);
  13. @interface XYHotGiveRewardSheetViewController ()<UITableViewDelegate, UITableViewDataSource>
  14. @property (nonatomic, strong) XYHotGiveRewardSheetViewModel *viewModel;
  15. @property (nonatomic, readwrite, strong) UIView *bgView;
  16. @property (nonatomic, readwrite, strong) UIView *infoView;
  17. @property (nonatomic, readwrite, strong) UIView *titleView;
  18. @property (nonatomic, readwrite, strong) UILabel *titleLabel;
  19. @property (nonatomic, readwrite, strong) UIButton *closeButton;
  20. @property (nonatomic, readwrite, strong) UIView *sendGiftView;
  21. @property (nonatomic, readwrite, strong) UIButton *sendGiftButton;
  22. @property (nonatomic, readwrite, strong) XYUserDynamicListCellModel *dynamicModel;
  23. @property (nonatomic, readwrite, copy) SelectedDidBlock selectedDidBlock;
  24. @end
  25. @implementation XYHotGiveRewardSheetViewController
  26. #pragma mark — Public
  27. + (instancetype)showWithDynamicModel:(XYUserDynamicListCellModel *)dynamicModel parentController:(UIViewController *)parentController completeBlock:(void(^)(BOOL success, XYUserDynamicListCellModel *dynamicModel))block {
  28. XYHotGiveRewardSheetViewController *alertVC = XYHotGiveRewardSheetViewController.new;
  29. alertVC.dynamicModel = dynamicModel;
  30. alertVC.selectedDidBlock = block;
  31. alertVC.view.hidden = YES;
  32. // 添加控制器
  33. [parentController addChildViewController:alertVC];
  34. [parentController.view addSubview:alertVC.view];
  35. [alertVC didMoveToParentViewController:parentController];
  36. return alertVC;
  37. }
  38. - (void)show {
  39. self.view.hidden = NO;
  40. [UIView animateWithDuration:.3 animations:^{
  41. self.infoView.frame = CGRectMake(self.infoView.f_x, SCREEN_HEIGHT - self.infoView.f_heigh, self.infoView.f_width, self.infoView.f_heigh);
  42. } completion:^(BOOL finished) {
  43. }];
  44. }
  45. - (void)dismiss {
  46. [UIView animateWithDuration:.3 animations:^{
  47. self.infoView.frame = CGRectMake(self.infoView.f_x, SCREEN_HEIGHT, self.infoView.f_width, self.infoView.f_heigh);
  48. } completion:^(BOOL finished) {
  49. [self willMoveToParentViewController:nil];
  50. [self.view removeFromSuperview];
  51. [self removeFromParentViewController];
  52. }];
  53. }
  54. - (void)viewDidLoad {
  55. [super viewDidLoad];
  56. self.view.backgroundColor = Color_Clear;
  57. /// 设置
  58. [self _setup];
  59. /// 设置导航栏
  60. [self _setupNavigationItem];
  61. /// 设置子控件
  62. [self _setupSubViews];
  63. /// 布局子空间
  64. [self _makeSubViewsConstraints];
  65. [self tableViewDidTriggerHeaderRefresh];
  66. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  67. [self show];
  68. });
  69. }
  70. #pragma mark - Override
  71. - (UIEdgeInsets)contentInset {
  72. return UIEdgeInsetsMake(0, 0, 0, 0);
  73. }
  74. - (void)bindViewModel {
  75. self.viewModel = XYHotGiveRewardSheetViewModel.new;
  76. self.viewModel.dynamicModel = self.dynamicModel;
  77. }
  78. - (void)tableViewDidTriggerHeaderRefresh {
  79. self.viewModel.pullDown = YES;
  80. [self.viewModel loadData:^(id _Nullable responseModel) {
  81. // [self updateViewFrame];
  82. [self tableViewDidFinishTriggerHeader:YES reload:YES];
  83. [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeNoSkillCertification emptyInfo:@"" errorInfo:@"" offsetTop:DefaultOffsetTop-100.0f hasData:self.viewModel.dataSource.count>0 hasError:NO reloadBlock:nil];
  84. } failure:^(ZYLNetworkError * _Nullable error) {
  85. [self tableViewDidFinishTriggerHeader:YES reload:NO];
  86. [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:error.domain offsetTop:DefaultOffsetTop hasData:self.viewModel.dataSource.count>0 hasError:error!=nil reloadBlock:nil];
  87. [self dismiss];
  88. }];
  89. }
  90. - (void)updateViewFrame {
  91. CGFloat infoHeight = 44.0f;
  92. infoHeight += (self.viewModel.dataSource.count * 48.0f);
  93. if ([self.dynamicModel.userId isEqualToString:[XYUserInfoManager nowUser].userId]) {
  94. // 自己
  95. infoHeight += 0.0f;
  96. }else {
  97. // 别人
  98. infoHeight += 64.0f;
  99. }
  100. infoHeight += HOME_INDICATOR_HEIGHT;
  101. // infoView最大高度不能超过半屏
  102. infoHeight = MIN(infoHeight, SCREEN_HEIGHT/2);
  103. self.infoView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, infoHeight);
  104. }
  105. #pragma mark - 事件处理Or辅助方法
  106. - (void)closeButtonAction:(id)sender {
  107. if (self.selectedDidBlock) {
  108. self.selectedDidBlock(NO, self.dynamicModel);
  109. }
  110. [self dismiss];
  111. }
  112. - (void)sendGiftButtonAction:(id)sender {
  113. if (self.selectedDidBlock) {
  114. self.selectedDidBlock(YES, self.dynamicModel);
  115. }
  116. [self dismiss];
  117. }
  118. #pragma mark - UITableViewDelegate
  119. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  120. return self.viewModel.dataSource.count;
  121. }
  122. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  123. return 48.0f;
  124. }
  125. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  126. XYHotGiveRewardUserListTableViewCell *cell = [XYHotGiveRewardUserListTableViewCell cellWithTableView:tableView];
  127. [cell configureModel:self.viewModel.dataSource[indexPath.row]];
  128. return cell;
  129. }
  130. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  131. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  132. // 关闭
  133. [self closeButtonAction:nil];
  134. XYHotGiveRewardUserListModel *model = self.viewModel.dataSource[indexPath.row];
  135. XYUserMainViewController *controller = XYUserMainViewController.new;
  136. controller.targetId = [model.userId copy];
  137. [ApplicationDelegate.getCurrentController.navigationController pushViewController:controller animated:YES];
  138. }
  139. #pragma mark - 初始化
  140. - (void)_setup{
  141. }
  142. #pragma mark - 设置导航栏
  143. - (void)_setupNavigationItem{
  144. }
  145. #pragma mark - 设置子控件
  146. - (void)_setupSubViews{
  147. [self.view addSubview:self.bgView];
  148. [self.view addSubview:self.infoView];
  149. [self.infoView addSubview:self.titleView];
  150. [self.titleView addSubview:self.titleLabel];
  151. [self.titleView addSubview:self.closeButton];
  152. [self.infoView addSubview:self.tableView];
  153. [self.infoView addSubview:self.sendGiftView];
  154. [self.sendGiftView addSubview:self.sendGiftButton];
  155. [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
  156. make.left.top.right.equalTo(self.infoView);
  157. make.height.equalTo(@44.0f);
  158. }];
  159. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  160. make.left.equalTo(self.titleView).offset(16.0f);
  161. make.centerY.equalTo(self.titleView);
  162. }];
  163. [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  164. make.right.equalTo(self.titleView).offset(-10.0f);
  165. make.centerY.equalTo(self.titleView);
  166. make.width.height.equalTo(@44.0f);
  167. }];
  168. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  169. make.left.right.equalTo(self.infoView);
  170. make.top.equalTo(self.titleView.mas_bottom);
  171. make.bottom.equalTo(self.sendGiftView.mas_top);
  172. }];
  173. if ([self.dynamicModel.userId isEqualToString:[XYUserInfoManager nowUser].userId]) {
  174. // 自己则不显示打赏按钮
  175. [self.sendGiftView mas_makeConstraints:^(MASConstraintMaker *make) {
  176. make.left.bottom.right.equalTo(self.infoView);
  177. make.height.equalTo(@(HOME_INDICATOR_HEIGHT));
  178. }];
  179. self.sendGiftButton.hidden = YES;
  180. }else {
  181. [self.sendGiftView mas_makeConstraints:^(MASConstraintMaker *make) {
  182. make.left.bottom.right.equalTo(self.infoView);
  183. make.height.equalTo(@(64.0f + HOME_INDICATOR_HEIGHT));
  184. }];
  185. [self.sendGiftButton mas_makeConstraints:^(MASConstraintMaker *make) {
  186. make.left.equalTo(self.sendGiftView).offset(16.0f);
  187. make.right.equalTo(self.sendGiftView).offset(-16.0f);
  188. make.top.equalTo(self.sendGiftView).offset(8.0f);
  189. make.height.equalTo(@48.0f);
  190. }];
  191. self.sendGiftView.size = CGSizeMake(SCREEN_WIDTH, 64.0f + HOME_INDICATOR_HEIGHT);
  192. self.sendGiftButton.hidden = NO;
  193. [self.sendGiftButton addViewBorder:Color_Clear redian:48/2];
  194. }
  195. [self.infoView addViewBorderWithCorners:UIRectCornerTopLeft|UIRectCornerTopRight color:Color_Clear redian:16];
  196. [self.sendGiftView addViewShadowWithShadowColor:ColorFromHexStringWithAlpha(@"#000000", 0.1f) shadowOffset:CGSizeMake(0, 0) shadowOpacity:1 shadowRadius:4 cornerRadius:0];
  197. }
  198. #pragma mark - 布局子控件
  199. - (void)_makeSubViewsConstraints{
  200. }
  201. #pragma mark - Setter & Getter
  202. - (UIView *)bgView {
  203. if (_bgView == nil) {
  204. _bgView = [[UIView alloc] initWithFrame:SCREEN_BOUNDS];
  205. _bgView.backgroundColor = ColorFromHexStringWithAlpha(@"#1D1C1F", 0.35f);
  206. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeButtonAction:)];
  207. [_bgView addGestureRecognizer:tap];
  208. }
  209. return _bgView;
  210. }
  211. - (UIView *)infoView {
  212. if (_infoView == nil) {
  213. _infoView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT/2)];
  214. _infoView.backgroundColor = Color_White;
  215. }
  216. return _infoView;
  217. }
  218. - (UIView *)titleView {
  219. if (_titleView == nil) {
  220. _titleView = [[UIView alloc] init];
  221. }
  222. return _titleView;
  223. }
  224. - (UILabel *)titleLabel {
  225. if (_titleLabel == nil) {
  226. _titleLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_S(18)];
  227. _titleLabel.text = @"热门打赏";
  228. }
  229. return _titleLabel;
  230. }
  231. - (UIButton *)closeButton {
  232. if (!_closeButton) {
  233. _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
  234. [_closeButton setImage:ImageNamed(@"icon_closex") forState:UIControlStateNormal];
  235. [_closeButton addTarget:self action:@selector(closeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  236. }
  237. return _closeButton;
  238. }
  239. - (UIView *)sendGiftView {
  240. if (!_sendGiftView) {
  241. _sendGiftView = [[UIView alloc] init];
  242. _sendGiftView.backgroundColor = Color_White;
  243. }
  244. return _sendGiftView;
  245. }
  246. - (UIButton *)sendGiftButton {
  247. if (!_sendGiftButton) {
  248. _sendGiftButton = [UIButton createButtonTextColor:Color_White textFont:Font(16)];
  249. [_sendGiftButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[ColorFromHexString(@"#5D26FF"), ColorFromHexString(@"#8359FF")] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake((SCREEN_WIDTH - 16.0f * 2)/2, 48.0f)] forState:UIControlStateNormal];
  250. [_sendGiftButton setTitle:@"打赏一下ta" forState:UIControlStateNormal];
  251. [_sendGiftButton addTarget:self action:@selector(sendGiftButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  252. }
  253. return _sendGiftButton;
  254. }
  255. @end