YMMineCommonFunctionsTwoView.m 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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.clearColor;
  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:12];
  71. }
  72. if ([title isEqualToString:@"私信音效"]) {
  73. UIView *bgv = myCell.bgv;
  74. [bgv addRectCorner:(UIRectCornerBottomLeft | UIRectCornerBottomRight) radius:12];
  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.clearColor;
  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. @end
  105. @implementation YMCommonFunctionsListCell
  106. - (void)ym_setupViews{
  107. self.backgroundColor = UIColor.clearColor;
  108. self.contentView.backgroundColor = UIColor.clearColor;
  109. [self.contentView addSubview:self.bgv];
  110. [self.contentView addSubview:self.functionsIcon];
  111. [self.contentView addSubview:self.functionsLb];
  112. [self.contentView addSubview:self.switchBtn];
  113. [self setNeedsUpdateConstraints];
  114. [self updateConstraintsIfNeeded];
  115. }
  116. - (void)updateConstraints{
  117. [self.bgv mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.edges.equalTo(UIEdgeInsetsMake(0, adapt(15), 0, adapt(15)));
  119. make.height.mas_equalTo(adapt(60) - 8);
  120. }];
  121. [self.functionsIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  122. make.centerY.equalTo(self.contentView.mas_centerY);
  123. make.left.equalTo(self.bgv).offset(20);
  124. }];
  125. [self.functionsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  126. make.centerY.equalTo(self.contentView.mas_centerY);
  127. make.left.equalTo(self.bgv.mas_left).offset(adapt(14));
  128. }];
  129. [self.switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  130. make.centerY.equalTo(self.contentView.mas_centerY);
  131. make.right.equalTo(self.bgv).offset(-22);
  132. make.width.mas_equalTo(adapt(48));
  133. make.height.mas_equalTo(adapt(30));
  134. }];
  135. [super updateConstraints];
  136. }
  137. - (void)ym_bindViewModel:(NSDictionary*)viewModel{
  138. //self.functionsIcon.image = ImageByName([viewModel stringValueForKey:@"icon" defaultValue:@""]);
  139. self.functionsLb.text = [viewModel stringValueForKey:@"title" defaultValue:@""];
  140. self.switchBtn.tag = [viewModel integerValueForKey:ParamsCategoryType defaultValue:YMCommonFunctionsTypePrivateLetterChat];
  141. BOOL isOpen = [viewModel boolValueForKey:@"isOpen" defaultValue:NO];
  142. if (isOpen) {
  143. [self.switchBtn setImage:ImageByName(@"ym_mine_switch_selected_icon") forState:UIControlStateNormal];
  144. } else {
  145. [self.switchBtn setImage:ImageByName(@"ym_mine_switch_normal_icon") forState:UIControlStateNormal];
  146. }
  147. }
  148. - (UIView *)bgv {
  149. if (!_bgv) {
  150. _bgv = [[UIView alloc]init];
  151. _bgv.backgroundColor = HexColorFromRGB(0xFFFFFF);
  152. // _bgv.layer.cornerRadius = adapt(8);
  153. // _bgv.layer.masksToBounds = YES;
  154. }
  155. return _bgv;
  156. }
  157. - (UIImageView *)functionsIcon{
  158. if(!_functionsIcon){
  159. _functionsIcon = [[UIImageView alloc]init];
  160. _functionsIcon.hidden = YES;
  161. }
  162. return _functionsIcon;
  163. }
  164. - (UILabel *)functionsLb{
  165. if (!_functionsLb) {
  166. _functionsLb = [[UILabel alloc]init];
  167. _functionsLb.font = LCFont(16);
  168. _functionsLb.textColor = HexColorFromRGB(0x171A1D);
  169. _functionsLb.textAlignment = NSTextAlignmentLeft;
  170. _functionsLb.text = @"******";
  171. }
  172. return _functionsLb;
  173. }
  174. - (UIButton *)switchBtn{
  175. if (!_switchBtn) {
  176. _switchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  177. [_switchBtn setImage:ImageByName(@"ym_mine_switch_normal_icon") forState:UIControlStateNormal];
  178. WS(weakSelf)
  179. [[[_switchBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  180. if (weakSelf.callBlock) {
  181. weakSelf.callBlock(sender.tag);
  182. }
  183. }];
  184. }
  185. return _switchBtn;
  186. }
  187. @end