YMMineCommonFunctionsTwoView.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // YMMineCommonFunctionsTwoView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/15.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMMineCommonFunctionsTwoView.h"
  9. #import "YMMineViewModel.h"
  10. @interface YMMineCommonFunctionsTwoView ()<UITableViewDataSource, UITableViewDelegate>
  11. /// 我的VM
  12. @property (nonatomic, strong) YMMineViewModel *viewModel;
  13. /// 常用功能宫格视图
  14. @property (nonatomic, strong) UITableView *commonFunctionsListView;
  15. @end
  16. @implementation YMMineCommonFunctionsTwoView
  17. - (void)ym_setupViews{
  18. self.backgroundColor = UIColor.whiteColor;
  19. [self addSubview:self.commonFunctionsListView];
  20. [self setNeedsUpdateConstraints];
  21. [self updateConstraintsIfNeeded];
  22. }
  23. - (void)updateConstraints{
  24. [self.commonFunctionsListView mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.top.equalTo(self).offset(adapt(0));
  26. make.left.equalTo(self).offset(adapt(0));
  27. make.right.equalTo(self).offset(adapt(0));
  28. make.bottom.equalTo(self).offset(adapt(0));
  29. }];
  30. [super updateConstraints];
  31. }
  32. - (void)ym_bindViewModel:(YMMineViewModel *)viewModel{
  33. if (!viewModel) {
  34. return;
  35. }
  36. _viewModel = viewModel;
  37. @weakify(self)
  38. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  39. @strongify(self)
  40. [self.commonFunctionsListView reloadData];
  41. [self.commonFunctionsListView layoutIfNeeded];
  42. //刷新高度
  43. CGFloat commonFunctionsListViewHeight = self.commonFunctionsListView.contentSize.height;
  44. [self.commonFunctionsListView mas_updateConstraints:^(MASConstraintMaker *make) {
  45. make.height.mas_equalTo(commonFunctionsListViewHeight + adapt(10));
  46. }];
  47. }];
  48. }
  49. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  50. return self.viewModel.commonFunctionsTwoListDataArray.count;
  51. }
  52. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  53. YMCommonFunctionsListCell *cell = [[YMCommonFunctionsListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMCommonFunctionsListCell class])];
  54. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  55. cell.contentView.backgroundColor = UIColor.clearColor;
  56. __weak typeof(self) weakSelf = self;
  57. cell.callBlock = ^(YMCommonFunctionsType functionsType) {
  58. [weakSelf.viewModel.commonFunctionsOperationSubject sendNext:@(functionsType)];
  59. };
  60. [cell ym_bindViewModel:self.viewModel.commonFunctionsTwoListDataArray[indexPath.item]];
  61. return cell;
  62. }
  63. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  64. if ([cell isKindOfClass:[YMCommonFunctionsListCell class]]) {
  65. YMCommonFunctionsListCell *myCell = (YMCommonFunctionsListCell *)cell;
  66. NSDictionary *viewModel = self.viewModel.commonFunctionsTwoListDataArray[indexPath.row];
  67. NSString *title = [viewModel stringValueForKey:@"title" defaultValue:@""];
  68. if ([title isEqualToString:@"视频开关"]) {
  69. UIView *bgv = myCell.bgv;
  70. [bgv addRectCorner:(UIRectCornerTopLeft | UIRectCornerTopRight) radius:20];
  71. }
  72. if ([title isEqualToString:@"私信音效"]) {
  73. UIView *bgv = myCell.bgv;
  74. [bgv addRectCorner:(UIRectCornerBottomLeft | UIRectCornerBottomRight) radius:20];
  75. }
  76. }
  77. }
  78. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  79. return adapt(60);
  80. }
  81. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  82. }
  83. - (UITableView *)commonFunctionsListView{
  84. if (!_commonFunctionsListView) {
  85. _commonFunctionsListView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  86. _commonFunctionsListView.delegate = self;
  87. _commonFunctionsListView.dataSource = self;
  88. _commonFunctionsListView.estimatedRowHeight = 0;
  89. _commonFunctionsListView.estimatedSectionHeaderHeight = 0;
  90. _commonFunctionsListView.estimatedSectionFooterHeight = 0;
  91. _commonFunctionsListView.showsVerticalScrollIndicator = NO;
  92. _commonFunctionsListView.showsHorizontalScrollIndicator = NO;
  93. _commonFunctionsListView.scrollEnabled = NO;
  94. _commonFunctionsListView.separatorColor = UIColor.clearColor;
  95. _commonFunctionsListView.backgroundColor = UIColor.whiteColor;
  96. [_commonFunctionsListView registerClass:[YMCommonFunctionsListCell class] forCellReuseIdentifier:NSStringFromClass([YMCommonFunctionsListCell class])];
  97. _commonFunctionsListView.layer.cornerRadius = adapt(8);
  98. _commonFunctionsListView.layer.masksToBounds = YES;
  99. }
  100. return _commonFunctionsListView;
  101. }
  102. @end
  103. @interface YMCommonFunctionsListCell ()
  104. /// 功能图标
  105. @property (nonatomic, strong) UIImageView *functionsIcon;
  106. /// 功能标签
  107. @property (nonatomic, strong) UILabel *functionsLb;
  108. /// 开关按钮
  109. @property (nonatomic, strong) UIButton *switchBtn;
  110. @end
  111. @implementation YMCommonFunctionsListCell
  112. - (void)ym_setupViews{
  113. self.backgroundColor = UIColor.clearColor;
  114. self.contentView.backgroundColor = UIColor.clearColor;
  115. [self.contentView addSubview:self.bgv];
  116. [self.contentView addSubview:self.functionsIcon];
  117. [self.contentView addSubview:self.functionsLb];
  118. [self.contentView addSubview:self.switchBtn];
  119. [self setNeedsUpdateConstraints];
  120. [self updateConstraintsIfNeeded];
  121. }
  122. - (void)updateConstraints{
  123. [self.bgv mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.edges.equalTo(UIEdgeInsetsMake(0, adapt(15), 0, adapt(15)));
  125. make.height.mas_equalTo(adapt(60) - 8);
  126. }];
  127. [self.functionsIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  128. make.centerY.equalTo(self.contentView.mas_centerY);
  129. make.left.equalTo(self.bgv).offset(20);
  130. }];
  131. [self.functionsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.centerY.equalTo(self.contentView.mas_centerY);
  133. make.left.equalTo(self.functionsIcon.mas_right).offset(11);
  134. }];
  135. [self.switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  136. make.centerY.equalTo(self.contentView.mas_centerY);
  137. make.right.equalTo(self.bgv).offset(-22);
  138. make.width.mas_equalTo(adapt(40));
  139. make.height.mas_equalTo(adapt(20));
  140. }];
  141. [super updateConstraints];
  142. }
  143. - (void)ym_bindViewModel:(NSDictionary*)viewModel{
  144. self.functionsIcon.image = ImageByName([viewModel stringValueForKey:@"icon" defaultValue:@""]);
  145. self.functionsLb.text = [viewModel stringValueForKey:@"title" defaultValue:@""];
  146. self.switchBtn.tag = [viewModel integerValueForKey:ParamsCategoryType defaultValue:YMCommonFunctionsTypePrivateLetterChat];
  147. BOOL isOpen = [viewModel boolValueForKey:@"isOpen" defaultValue:NO];
  148. if (isOpen) {
  149. [self.switchBtn setImage:ImageByName(@"ym_mine_switch_selected_icon") forState:UIControlStateNormal];
  150. } else {
  151. [self.switchBtn setImage:ImageByName(@"ym_mine_switch_normal_icon") forState:UIControlStateNormal];
  152. }
  153. }
  154. - (UIView *)bgv {
  155. if (!_bgv) {
  156. _bgv = [[UIView alloc]init];
  157. _bgv.backgroundColor = HexColorFromRGB(0xF9F9FB);
  158. // _bgv.layer.cornerRadius = adapt(8);
  159. // _bgv.layer.masksToBounds = YES;
  160. }
  161. return _bgv;
  162. }
  163. - (UIImageView *)functionsIcon{
  164. if(!_functionsIcon){
  165. _functionsIcon = [[UIImageView alloc]init];
  166. }
  167. return _functionsIcon;
  168. }
  169. - (UILabel *)functionsLb{
  170. if (!_functionsLb) {
  171. _functionsLb = [[UILabel alloc]init];
  172. _functionsLb.font = LCFont(16);
  173. _functionsLb.textColor = HexColorFromRGB(0x171A1D);
  174. _functionsLb.textAlignment = NSTextAlignmentLeft;
  175. _functionsLb.text = @"******";
  176. }
  177. return _functionsLb;
  178. }
  179. - (UIButton *)switchBtn{
  180. if (!_switchBtn) {
  181. _switchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  182. [_switchBtn setImage:ImageByName(@"ym_mine_switch_normal_icon") forState:UIControlStateNormal];
  183. WS(weakSelf)
  184. [[[_switchBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  185. if (weakSelf.callBlock) {
  186. weakSelf.callBlock(sender.tag);
  187. }
  188. }];
  189. }
  190. return _switchBtn;
  191. }
  192. @end