Files
peko-ios/YuMi/Modules/YMMine/View/VipSettingViewController.m
2024-10-22 18:46:06 +08:00

371 lines
11 KiB
Objective-C

//
// VipSettingViewController.m
// YuMi
//
// Created by P on 2024/10/22.
//
#import "VipSettingViewController.h"
#import "Api.h"
#import "UserInfoModel.h"
#import "XPNobleCenterProtocol.h"
#import "XPNobleCenterPresenter.h"
@interface VipSettingCell : UITableViewCell
@property (nonatomic, copy) NSString *title;
@property (nonatomic, assign) NSInteger minLevel;
@property (nonatomic, assign) NSInteger maxLevel;
@property (nonatomic, strong) UIStackView *stack;
@property (nonatomic, strong) UIImageView *vip_5;
@property (nonatomic, strong) UIImageView *vip_6;
@property (nonatomic, strong) UIImageView *vip_7;
@property (nonatomic, strong) UIImageView *vip_8;
@property (nonatomic, strong) UIImageView *vip_9;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UISwitch *vipSwitch;
@property (nonatomic, assign) NSInteger index;
@property (nonatomic, assign) BOOL switchStatus;
@property (nonatomic, copy) void(^switchUpdate)(BOOL switchState, NSInteger index);
@end
@implementation VipSettingCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor clearColor];
UIView *container = [[UIView alloc] init];
container.backgroundColor = UIColorFromRGB(0xF2F3F7);
container.layer.cornerRadius = 8;
container.layer.masksToBounds = YES;
[self.contentView addSubview:container];
[container mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.contentView.mas_width).offset(-16);
make.height.mas_equalTo(64);
make.top.mas_equalTo(self.contentView).offset(20);
}];
[self.stack addArrangedSubview:self.vip_5];
[self.stack addArrangedSubview:self.vip_6];
[self.stack addArrangedSubview:self.vip_7];
[self.stack addArrangedSubview:self.vip_8];
[self.stack addArrangedSubview:self.vip_9];
[container addSubview:self.stack];
[self.stack mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.mas_equalTo(10);
make.height.mas_equalTo(20);
}];
[self.vip_5 mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(42, 20));
}];
[self.vip_6 mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(42, 20));
}];
[self.vip_7 mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(42, 20));
}];
[self.vip_8 mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(42, 20));
}];
[self.vip_9 mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(42, 20));
}];
[container addSubview:self.vipSwitch];
[self.vipSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(container);
make.trailing.mas_equalTo(container).offset(-20);
make.size.mas_equalTo(CGSizeMake(34, 20));
}];
[container addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(10);
make.top.mas_equalTo(self.stack.mas_bottom).offset(10);
}];
}
return self;
}
- (void)setMaxLevel:(NSInteger)maxLevel {
_maxLevel = maxLevel;
self.titleLabel.text = self.title;
self.vip_5.hidden = self.minLevel>5;
self.vip_6.hidden = self.minLevel>6;
self.vip_7.hidden = self.minLevel>7;
self.vip_8.hidden = self.minLevel>8;
self.vipSwitch.on = self.switchStatus;
}
- (void)onSwitchChange:(UISwitch *)sender {
if (self.switchUpdate) {
self.switchUpdate(sender.isOn, self.index);
}
}
- (UIStackView *)stack {
if (!_stack) {
_stack = [[UIStackView alloc] init];
_stack.spacing = 5;
_stack.alignment = UIStackViewAlignmentLeading;
}
return _stack;
}
- (UIImageView *)vip_5 {
if (!_vip_5) {
_vip_5 = [[UIImageView alloc] initWithImage:kImage(@"vip_setting_level_5")];
_vip_5.contentMode = UIViewContentModeScaleAspectFill;
}
return _vip_5;
}
- (UIImageView *)vip_6 {
if (!_vip_6) {
_vip_6 = [[UIImageView alloc] initWithImage:kImage(@"vip_setting_level_6")];
_vip_6.contentMode = UIViewContentModeScaleAspectFill;
}
return _vip_6;
}
- (UIImageView *)vip_7 {
if (!_vip_7) {
_vip_7 = [[UIImageView alloc] initWithImage:kImage(@"vip_setting_level_7")];
_vip_7.contentMode = UIViewContentModeScaleAspectFill;
}
return _vip_7;
}
- (UIImageView *)vip_8 {
if (!_vip_8) {
_vip_8 = [[UIImageView alloc] initWithImage:kImage(@"vip_setting_level_8")];
_vip_8.contentMode = UIViewContentModeScaleAspectFill;
}
return _vip_8;
}
- (UIImageView *)vip_9 {
if (!_vip_9) {
_vip_9 = [[UIImageView alloc] initWithImage:kImage(@"vip_setting_level_9")];
_vip_9.contentMode = UIViewContentModeScaleAspectFill;
}
return _vip_9;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [UILabel labelInitWithText:@""
font:kFontMedium(14)
textColor:UIColorFromRGB(0x313131)];
}
return _titleLabel;
}
- (UISwitch *)vipSwitch {
if (!_vipSwitch) {
_vipSwitch = [[UISwitch alloc] init];
_vipSwitch.onTintColor = UIColorFromRGB(0xff8c03);
[_vipSwitch addTarget:self
action:@selector(onSwitchChange:)
forControlEvents:UIControlEventValueChanged];
_vipSwitch.transform = CGAffineTransformMakeScale(0.8, 0.8);
}
return _vipSwitch;
}
@end
@interface VipSettingViewController () <UITableViewDelegate, UITableViewDataSource, XPNobleCenterProtocol>
@property (nonatomic, strong) UserInfoModel *userInfo;
@property (nonatomic, strong) UITableView *tableView;
@end
@implementation VipSettingViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = YMLocalizedString(@"VipSettin_1.0.17_0");
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.tableView];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.view).offset(16);
make.top.trailing.bottom.mas_equalTo(self.view);
}];
[self showLoading];
@kWeakify(self);
[Api getUserInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
if (code == 200) {
[self hideHUD];
self.userInfo = [UserInfoModel modelWithDictionary:data.data];
[self.tableView reloadData];
} else {
[self showErrorToast:msg];
[self dismissViewControllerAnimated:YES completion:nil];
}
} uid:[[AccountInfoStorage instance] getUid]];
}
- (XPNobleCenterPresenter *)createPresenter {
return [[XPNobleCenterPresenter alloc] init];;
}
- (void)handleSwitchUpdate:(BOOL)switchStatus atIndex:(NSInteger)index {
self.tableView.userInteractionEnabled = false;
switch (index) {
case 0:
/// 防关注
[self.presenter changePreventFollow:switchStatus];
break;
case 1:
/// 防跟随
[self.presenter changePreventTrace:switchStatus];
break;
case 2:
/// 隐身
[self.presenter changeEnterHide:switchStatus];
break;
case 3:
/// 防被踢
[self.presenter changePreventKick:switchStatus];
break;
default:
break;
}
}
#pragma mark -
///开关隐身进房成功
- (void)changeEnterHideSuccess:(BOOL)switchStatus {
[self switchUpdateEnd];
// [self.userInfo.userVipInfoVO setEnterHide:<#(BOOL)#>]
}
///开关隐身进房失败
- (void)changeEnterHideFail {
[self switchUpdateEnd];
}
///防关注开关修改成功
- (void)changePreventFollowSuccess:(BOOL)switchStatus {
[self switchUpdateEnd];
}
///防关注开关修改失败
- (void)changePreventFollowFail {
[self switchUpdateEnd];
}
///防跟随开关修改成功
- (void)changePreventTraceSuccess:(BOOL)switchStatus {
[self switchUpdateEnd];
}
///防跟随开关修改失败
- (void)changePreventTraceFail {
[self switchUpdateEnd];
}
///VIP 防被踢开关修改成功
- (void)changePreventKickSuccess:(BOOL)switchStatus {
[self switchUpdateEnd];
}
///VIP 防被踢开关修改失败
- (void)changePreventKickFail {
[self switchUpdateEnd];
}
- (void)switchUpdateEnd {
[self.tableView reloadData];
self.tableView.userInteractionEnabled = YES;
}
#pragma mark -
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 20;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [UILabel labelInitWithText:YMLocalizedString(@"VipSettin_1.0.17_1")
font:kFontSemibold(16)
textColor:UIColorFromRGB(0x313131)];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 84;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
VipSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([VipSettingCell class])];
switch (indexPath.row) {
case 0:
// 关注
cell.title = YMLocalizedString(@"VipSettin_1.0.17_2");
cell.switchStatus = self.userInfo.userVipInfoVO.preventFollow;
cell.minLevel = 5;
break;
case 1:
// 跟随进房
cell.title = YMLocalizedString(@"VipSettin_1.0.17_3");
cell.switchStatus = self.userInfo.userVipInfoVO.preventTrace;
cell.minLevel = 6;
break;
case 2:
// 隐身进房
cell.title = YMLocalizedString(@"VipSettin_1.0.17_4");
cell.switchStatus = self.userInfo.userVipInfoVO.enterHide;
cell.minLevel = 7;
break;
case 3:
// 防被踢
cell.title = YMLocalizedString(@"VipSettin_1.0.17_5");
cell.switchStatus = self.userInfo.userVipInfoVO.preventKick;
cell.minLevel = 8;
break;
default:
break;
}
cell.maxLevel = 9;
cell.index = indexPath.row;
@kWeakify(self);
[cell setSwitchUpdate:^(BOOL switchState, NSInteger index) {
@kStrongify(self);
[self handleSwitchUpdate:switchState atIndex:index];
}];
return cell;
}
#pragma mark -
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero
style:UITableViewStylePlain];
_tableView.scrollEnabled = NO;
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[_tableView registerClass:[VipSettingCell class]
forCellReuseIdentifier:NSStringFromClass([VipSettingCell class])];
}
return _tableView;
}
@end