123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- //
- // YMMineCommonFunctionsTwoView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/15.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMMineCommonFunctionsTwoView.h"
- #import "YMMineViewModel.h"
- @interface YMMineCommonFunctionsTwoView ()<UITableViewDataSource, UITableViewDelegate>
- /// 我的VM
- @property (nonatomic, strong) YMMineViewModel *viewModel;
- /// 常用功能宫格视图
- @property (nonatomic, strong) UITableView *commonFunctionsListView;
- @end
- @implementation YMMineCommonFunctionsTwoView
- - (void)ym_setupViews{
- self.backgroundColor = UIColor.clearColor;
-
- [self addSubview:self.commonFunctionsListView];
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
-
- [self.commonFunctionsListView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(adapt(0));
- make.left.equalTo(self).offset(adapt(0));
- make.right.equalTo(self).offset(adapt(0));
- make.bottom.equalTo(self).offset(adapt(0));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMMineViewModel *)viewModel{
- if (!viewModel) {
- return;
- }
-
- _viewModel = viewModel;
-
- @weakify(self)
- [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
- @strongify(self)
- [self.commonFunctionsListView reloadData];
- [self.commonFunctionsListView layoutIfNeeded];
- //刷新高度
- CGFloat commonFunctionsListViewHeight = self.commonFunctionsListView.contentSize.height;
- [self.commonFunctionsListView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(commonFunctionsListViewHeight + adapt(10));
- }];
- }];
-
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.viewModel.commonFunctionsTwoListDataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- YMCommonFunctionsListCell *cell = [[YMCommonFunctionsListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMCommonFunctionsListCell class])];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.contentView.backgroundColor = UIColor.clearColor;
- __weak typeof(self) weakSelf = self;
- cell.callBlock = ^(YMCommonFunctionsType functionsType) {
- [weakSelf.viewModel.commonFunctionsOperationSubject sendNext:@(functionsType)];
- };
- [cell ym_bindViewModel:self.viewModel.commonFunctionsTwoListDataArray[indexPath.item]];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
- if ([cell isKindOfClass:[YMCommonFunctionsListCell class]]) {
- YMCommonFunctionsListCell *myCell = (YMCommonFunctionsListCell *)cell;
- NSDictionary *viewModel = self.viewModel.commonFunctionsTwoListDataArray[indexPath.row];
- NSString *title = [viewModel stringValueForKey:@"title" defaultValue:@""];
- if ([title isEqualToString:@"视频开关"]) {
- UIView *bgv = myCell.bgv;
- [bgv addRectCorner:(UIRectCornerTopLeft | UIRectCornerTopRight) radius:12];
- }
- if ([title isEqualToString:@"私信音效"]) {
- UIView *bgv = myCell.bgv;
- [bgv addRectCorner:(UIRectCornerBottomLeft | UIRectCornerBottomRight) radius:12];
- }
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return adapt(60);
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- }
- - (UITableView *)commonFunctionsListView{
- if (!_commonFunctionsListView) {
- _commonFunctionsListView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
- _commonFunctionsListView.delegate = self;
- _commonFunctionsListView.dataSource = self;
- _commonFunctionsListView.estimatedRowHeight = 0;
- _commonFunctionsListView.estimatedSectionHeaderHeight = 0;
- _commonFunctionsListView.estimatedSectionFooterHeight = 0;
- _commonFunctionsListView.showsVerticalScrollIndicator = NO;
- _commonFunctionsListView.showsHorizontalScrollIndicator = NO;
- _commonFunctionsListView.scrollEnabled = NO;
- _commonFunctionsListView.separatorColor = UIColor.clearColor;
- _commonFunctionsListView.backgroundColor = UIColor.clearColor;
- [_commonFunctionsListView registerClass:[YMCommonFunctionsListCell class] forCellReuseIdentifier:NSStringFromClass([YMCommonFunctionsListCell class])];
- //_commonFunctionsListView.layer.cornerRadius = adapt(8);
- //_commonFunctionsListView.layer.masksToBounds = YES;
- }
- return _commonFunctionsListView;
- }
- @end
- @interface YMCommonFunctionsListCell ()
- @end
- @implementation YMCommonFunctionsListCell
- - (void)ym_setupViews{
- self.backgroundColor = UIColor.clearColor;
- self.contentView.backgroundColor = UIColor.clearColor;
-
- [self.contentView addSubview:self.bgv];
- [self.contentView addSubview:self.functionsIcon];
- [self.contentView addSubview:self.functionsLb];
- [self.contentView addSubview:self.switchBtn];
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
-
- [self.bgv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(UIEdgeInsetsMake(0, adapt(15), 0, adapt(15)));
- make.height.mas_equalTo(adapt(60) - 8);
- }];
-
- [self.functionsIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.contentView.mas_centerY);
- make.left.equalTo(self.bgv).offset(20);
- }];
-
- [self.functionsLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.contentView.mas_centerY);
- make.left.equalTo(self.bgv.mas_left).offset(adapt(14));
- }];
-
- [self.switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.contentView.mas_centerY);
- make.right.equalTo(self.bgv).offset(-22);
- make.width.mas_equalTo(adapt(48));
- make.height.mas_equalTo(adapt(30));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(NSDictionary*)viewModel{
- //self.functionsIcon.image = ImageByName([viewModel stringValueForKey:@"icon" defaultValue:@""]);
- self.functionsLb.text = [viewModel stringValueForKey:@"title" defaultValue:@""];
- self.switchBtn.tag = [viewModel integerValueForKey:ParamsCategoryType defaultValue:YMCommonFunctionsTypePrivateLetterChat];
- BOOL isOpen = [viewModel boolValueForKey:@"isOpen" defaultValue:NO];
- if (isOpen) {
- [self.switchBtn setImage:ImageByName(@"ym_mine_switch_selected_icon") forState:UIControlStateNormal];
- } else {
- [self.switchBtn setImage:ImageByName(@"ym_mine_switch_normal_icon") forState:UIControlStateNormal];
- }
- }
- - (UIView *)bgv {
- if (!_bgv) {
- _bgv = [[UIView alloc]init];
- _bgv.backgroundColor = HexColorFromRGB(0xFFFFFF);
- // _bgv.layer.cornerRadius = adapt(8);
- // _bgv.layer.masksToBounds = YES;
- }
- return _bgv;
- }
- - (UIImageView *)functionsIcon{
- if(!_functionsIcon){
- _functionsIcon = [[UIImageView alloc]init];
- _functionsIcon.hidden = YES;
- }
- return _functionsIcon;
- }
- - (UILabel *)functionsLb{
- if (!_functionsLb) {
- _functionsLb = [[UILabel alloc]init];
- _functionsLb.font = LCFont(16);
- _functionsLb.textColor = HexColorFromRGB(0x171A1D);
- _functionsLb.textAlignment = NSTextAlignmentLeft;
- _functionsLb.text = @"******";
- }
- return _functionsLb;
- }
- - (UIButton *)switchBtn{
- if (!_switchBtn) {
- _switchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_switchBtn setImage:ImageByName(@"ym_mine_switch_normal_icon") forState:UIControlStateNormal];
- WS(weakSelf)
- [[[_switchBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
- if (weakSelf.callBlock) {
- weakSelf.callBlock(sender.tag);
- }
- }];
- }
- return _switchBtn;
- }
- @end
|