cdts/xdts-ios 3/TreeHole/Code/Features/Settings/ViewController/SettingsViewController.m
2023-08-18 14:05:39 +08:00

416 lines
21 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// SettingsViewController.m
// Youth
//
// Created by mambaxie on 2022/1/2.
//
#import "SettingsViewController.h"
#import <SDImageCache.h>
#import "ChangePhoneViewController.h"
#import "BlackListViewController.h"
#import "PrivacySettingsViewController.h"
#import "InviteCodeViewController.h"
#import "FeedbackViewController.h"
#import "AlertInputView.h"
#import "MTCacheManager.h"
@interface SettingsViewController ()
@property (nonatomic, copy) NSString *statusStr;
@end
@implementation SettingsViewController
- (BOOL)mt_nagationBarTransparent {
return NO;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.alwaysBounceVertical = NO;
UIView *footerView = [[UIView alloc] init];
footerView.width = SCREEN_WIDTH;
footerView.backgroundColor = [UIColor clearColor];
UILabel *versionLabel = [[UILabel alloc] init];
versionLabel.text = [NSString stringWithFormat:@"V%@", [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"]];
versionLabel.textColor = THEME_COLOR;
versionLabel.numberOfLines = 0;
versionLabel.textAlignment = NSTextAlignmentCenter;
versionLabel.font = MT_FONT_REGULAR_SIZE(11);
[versionLabel sizeToFit];
versionLabel.y = FIX_SIZE(30);
versionLabel.centerX = SCREEN_WIDTH * 0.5;
[footerView addSubview:versionLabel];
footerView.height = versionLabel.bottom + 20;
self.tableView.tableFooterView = footerView;
UIView *logoutItem = [[UIView alloc] init];
logoutItem.width = SCREEN_WIDTH;
logoutItem.height = FIX_SIZE(84);
logoutItem.backgroundColor = UIColor.clearColor;
UILabel *logoutLabel = [[UILabel alloc] init];
logoutLabel.font = MT_FONT_REGULAR_SIZE(18);
logoutLabel.textColor = COLOR_WITH_RGB(0xFF4C73);
logoutLabel.textAlignment = NSTextAlignmentCenter;
logoutLabel.backgroundColor = UIColor.clearColor;
logoutLabel.width = SCREEN_WIDTH;
logoutLabel.height = FIX_SIZE(53);
logoutLabel.text = @"退出登录";
[logoutLabel addTapWithAction:^{
[MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) {
config.title = @"退出登录";
config.message = @"退出后不会删除任何历史数据,下次登录依然可以使用本账号。";
config.cancelTitle = @"取消";
config.otherTitle = @"确定";
config.otherHandler = ^(MTAlertButton *button) {
[SVProgressHUD showWithStatus:@"登出中..."];
[PYAppService logout];
};
}];
}];
[logoutItem addSubview:logoutLabel];
logoutItem.bottom = SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT + 20;
[self.view addSubview:logoutItem];
self.tableView.contentSize = CGSizeMake(0, logoutItem.bottom);
[self getUserstatData];
}
- (void)getUserstatData {
[PYHTTPManager getWithPath:@"userstat" params:nil callback:^(id _Nullable rsp, NSError * _Nullable error) {
if (error == nil) {
self.statusStr = [NSString stringWithFormat:@"%@",rsp[@"is_hide"]];
[self reloadData];
}
}];
}
- (void)showAppUpdateAlertViewWithVersion:(NSString *)version content:(NSString *)content isForce:(BOOL)isForce andDownLoadAddress:(NSString *)app_urlStr{
UIView *customView = [[UIView alloc] init];
customView.width = FIX_SIZE(270);
customView.height = FIX_SIZE(494);
customView.backgroundColor = COLOR_WITH_RGB(0x222436);
customView.layer.cornerRadius = FIX_SIZE(10);
customView.clipsToBounds = YES;
MTAlertView *alerView = [MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) {
config.customView = customView;
}];
UIImageView *iconView = [[UIImageView alloc] init];
iconView.width = customView.width;
iconView.height = FIX_SIZE(160);
iconView.image = ImageNamed(@"TH_app_update_img");
[customView addSubview:iconView];
UILabel *versionLabel = [[UILabel alloc] init];
versionLabel.text = version;
versionLabel.font = MT_FONT_REGULAR_SIZE(12);
versionLabel.textColor = [UIColor whiteColor];
[versionLabel sizeToFit];
versionLabel.x = FIX_SIZE(25);
versionLabel.centerY = iconView.height * 0.5;
[iconView addSubview:versionLabel];
UIButton *nextButton = [[UIButton alloc] init];
[nextButton setTitle:@"稍后更新" forState:UIControlStateNormal];
[nextButton setTitleColor:CONTENT_COLOR forState:UIControlStateNormal];
[nextButton sizeToFit];
nextButton.width += 10;
nextButton.height = FIX_SIZE(30);
nextButton.titleLabel.font = MT_FONT_REGULAR_SIZE(13);
nextButton.centerX = customView.width * 0.5;
nextButton.bottom = customView.height - FIX_SIZE(15);
nextButton.hidden = isForce;
[customView addSubview:nextButton];
PYThemeButton *button = [PYThemeButton buttonWithTitle:@"立即更新" action:^(UIButton * _Nonnull button) {
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/qq/%@?mt=8", APPSTORE_APPID]] options:@{} completionHandler:^(BOOL success) {
//// NSLog(@"to App Store");
// }];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:app_urlStr] options:@{} completionHandler:^(BOOL success) {
// NSLog(@"to App Store");
}];
}];
[nextButton addTouchUpInsideWithAction:^(UIButton * _Nullable button) {
[alerView dismiss];
}];
button.width = FIX_SIZE(180);
button.centerX = customView.width * 0.5;
button.bottom = isForce ? customView.height - FIX_SIZE(20) : nextButton.y - FIX_SIZE(8);
[customView addSubview:button];
UITextView *textView = [[UITextView alloc] init];
textView.x = FIX_SIZE(20);
textView.text = content;
textView.backgroundColor = [UIColor clearColor];
textView.width = customView.width - textView.x * 2;
textView.y = iconView.bottom + FIX_SIZE(20);
textView.height = button.y - FIX_SIZE(20) - textView.y;
textView.textColor = [UIColor whiteColor];
textView.font = MT_FONT_REGULAR_SIZE(15);
[customView addSubview:textView];
}
- (MTCommonListTableConfig *)tableConfigForTableViewContorller
{
MTCommonListTableConfig *config = [MTCommonListTableConfig defaultConfigWithCellStyle:MTCommonListTableCellStyleDisclosureIndicator rowsCountForSections:@[@(6), @(2), @(2)]];
// 版本更新 邀请有奖 隐身 设置密码锁 修改密码锁 修改手机号
config.cellTitles = @[@"版本更新",@"邀请有奖", @"附近隐身",@"设置密码锁",@"修改密码锁", @"修改手机号",@"黑名单", @"隐私设置", @"意见反馈", @"清理缓存"];
config.cellImageNames = @[@"version",@"TH_pro_yqyj",@"yin",@"TH_pro_mms",@"TH_pro_set_password_icon",@"TH_pro_set_phone_icon", @"TH_pro_set_blacklist_icon", @"TH_pro_set_privacy_icon", @"TH_pro_set_opinion_icon", @"TH_pro_set_icon_dump"];
config.tableTitle = @"更多";
User *user = [UserService currentUser];
[config resetCellConfigForSection:0 row:0 config:^(MTCommonListTableCellConfig *cellConfig) {
cellConfig.cellAction = ^(MTCommonListTableViewController *tableViewController, NSIndexPath *indexPath, MTCommonListTableCellConfig *cellConfig) {
[PYHTTPManager postWithPath:@"checkappupdate" params:nil callback:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
NSString *type = rsp[@"update_type"];
NSString *version = rsp[@"new_version"];
NSString *content = rsp[@"update_content"];
NSString *app_urlStr = rsp[@"app_url"];
// NSLog(@"type:%@\napp_urlStr:%@",type,app_urlStr);
// NSString *type = @"force_update";
// NSString *content = @"https://sourl.cn/9KSTN6";
// NSString *app_urlStr = @"https://sourl.cn/9KSTN6";
if ([type isEqualToString:@"update_remind"]) { // 提醒更新
[self showAppUpdateAlertViewWithVersion:version content:content isForce:NO andDownLoadAddress:app_urlStr];
return;
}
if ([type isEqualToString:@"force_update"]) { // 强制更新
[self showAppUpdateAlertViewWithVersion:version content:content isForce:YES andDownLoadAddress:app_urlStr];
return;
} else {
[SVProgressHUD showInfoWithStatus:@"当前已经是最新版本了"];
}
}
}];
// [PYAppService pushViewControllerAnimated:[ChangePhoneViewController new]];
};
}];
MJWeakSelf
[config resetCellConfigForSection:0 row:2 config:^(MTCommonListTableCellConfig *cellConfig) {
cellConfig.accessoryTitle = weakSelf.statusStr.intValue == 1 ? @"已开启": @"未开启";
cellConfig.cellAction = ^(MTCommonListTableViewController *tableViewController, NSIndexPath *indexPath, MTCommonListTableCellConfig *cellConfig) {
if ([cellConfig.accessoryTitle isEqualToString:@"未开启"]){
if([UserService currentUser].vip_kind == 10){
[PYHTTPManager postWithPath:@"userhide" params:@{@"state":@1} callback:^(id _Nullable rsp, NSError * _Nullable error) {
if (error == nil) {
self.statusStr = @"1";
[self reloadData];
}
}];
} else {
[MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) {
config.message = @"";
config.title = @"开通年vip后就可以在附近隐身啦还可以获得其他十九种会员特权哦";
config.otherTitle = @"去开通";
config.cancelTitle = @"取消";
config.otherHandler = ^(MTAlertButton *button) {
[PYAppService showVipVC:@"vip_page"];
};
}];
}
} else {
[PYHTTPManager postWithPath:@"userhide" params:@{@"state":@0} callback:^(id _Nullable rsp, NSError * _Nullable error) {
if (error == nil) {
self.statusStr = @"0";
[self reloadData];
}
}];
}
};
}];
[config resetCellConfigForSection:0 row:1 config:^(MTCommonListTableCellConfig *cellConfig) {
cellConfig.cellAction = ^(MTCommonListTableViewController *tableViewController, NSIndexPath *indexPath, MTCommonListTableCellConfig *cellConfig) {
[PYAppService pushViewControllerAnimated:[InviteCodeViewController new]];
};
}];
WeakSelf(self);
[config resetCellConfigForSection:0 row:4 config:^(MTCommonListTableCellConfig *cellConfig) {
cellConfig.accessoryTitle = user.security_code.length == SecurityCodeLength ? [NSString stringWithFormat:@"****%@", [user.security_code substringFromIndex:4]] : @"未设置";
cellConfig.cellAction = ^(MTCommonListTableViewController *tableViewController, NSIndexPath *indexPath, MTCommonListTableCellConfig *cellConfig) {
if ([UserService currentUser].security_code.length != SecurityCodeLength) {
[AlertInputView showWithTitle:@"设置密码" content:nil maxLength:SecurityCodeLength action:^BOOL(NSString * _Nonnull content) {
if (content.length != SecurityCodeLength) {
[ToastUtil showToast:[NSString stringWithFormat:@"请输入%lu位数字", (unsigned long)SecurityCodeLength] position:CSToastPositionTop];
return NO;
}
[UserService updateUserSecurityToRemote:@{
@"security_code" : content ?: @"",
@"is_security_on" : @([UserService currentUser].is_security_on),
} completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (error) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]];
});
} else { // 设置成功
[UserService currentUser].security_code = content;
[self reloadData];
}
}];
return YES;
}];
return;
}
[AlertInputView showChangePasswordWithTitle:@"修改密码锁" maxLength:SecurityCodeLength action:^BOOL(NSString * _Nonnull originPassowrd, NSString * _Nonnull newPassowrd) {
if (originPassowrd.length != SecurityCodeLength || newPassowrd.length != SecurityCodeLength) {
[ToastUtil showToast:[NSString stringWithFormat:@"请输入%lu位数字", (unsigned long)SecurityCodeLength] position:CSToastPositionTop];
return NO;
}
if (![originPassowrd isEqualToString:[UserService currentUser].security_code]) {
[ToastUtil showToast:@"旧密码不正确" position:CSToastPositionTop];
return NO;
}
[UserService updateUserSecurityToRemote:@{
@"security_code" : newPassowrd ?: @"",
@"is_security_on" : @([UserService currentUser].is_security_on),
} completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
[UserService currentUser].security_code = newPassowrd;
[weakself reloadData];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD showSuccessWithStatus:@"修改成功"];
});
}else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]];
});
}
}];
return YES;
}];
};
}];
[config resetCellConfigForSection:0 row:3 config:^(MTCommonListTableCellConfig *cellConfig) {
BOOL canOpen = [UserService isSecurityCodeOpen];
cellConfig.accessoryTitle = canOpen ? @"已开启": @"未开启";
cellConfig.cellAction = ^(MTCommonListTableViewController *tableViewController, NSIndexPath *indexPath, MTCommonListTableCellConfig *cellConfig) {
if ([cellConfig.accessoryTitle isEqualToString:@"未开启"]) {
if ([UserService currentUser].security_code.length != SecurityCodeLength) {
// [sender setOn:NO animated:NO];
[AlertInputView showWithTitle:@"设置密码" content:nil maxLength:SecurityCodeLength action:^BOOL(NSString * _Nonnull content) {
if (content.length != SecurityCodeLength) {
[ToastUtil showToast:[NSString stringWithFormat:@"请输入%lu位数字", (unsigned long)SecurityCodeLength] position:CSToastPositionTop];
return NO;
}
[UserService updateUserSecurityToRemote:@{
@"security_code" : content ?: @"",
@"is_security_on" : @(1),
} completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (error) {
// [sender setOn:NO animated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]];
});
return;
} else { // 设置成功
// [sender setOn:YES animated:YES];
[UserService currentUser].security_code = content;
[UserService currentUser].is_security_on = 1;
[self reloadData];
}
}];
return YES;
}];
return;
}else{
// [sender setOn:NO animated:NO];
[UserService updateUserSecurityToRemote:@{
@"security_code" : [UserService currentUser].security_code,
@"is_security_on" : @(1),
} completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (error) {
// [sender setOn:NO animated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]];
});
return;
} else { // 设置成功
[UserService currentUser].is_security_on = 1;
int status2 = [UserService currentUser].is_security_on;
[self reloadData];
// [sender setOn:YES animated:YES];
}
}];
}
} else {
[UserService updateUserSecurityToRemote:@{
@"security_code" : [UserService currentUser].security_code,
@"is_security_on" : @(0),
} completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (error) {
// [sender setOn:YES animated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]];
});
return;
} else { // 设置成功
[UserService currentUser].is_security_on = 0;
[self reloadData];
// [sender setOn:NO animated:YES];
}
}];
}
};
}];
[config resetCellConfigForSection:0 row:5 config:^(MTCommonListTableCellConfig *cellConfig) {
cellConfig.cellAction = ^(MTCommonListTableViewController *tableViewController, NSIndexPath *indexPath, MTCommonListTableCellConfig *cellConfig) {
[PYAppService pushViewControllerAnimated:[ChangePhoneViewController new]];
};
}];
[config resetCellConfigForSection:1 row:0 config:^(MTCommonListTableCellConfig *cellConfig) {
cellConfig.cellAction = ^(MTCommonListTableViewController *tableViewController, NSIndexPath *indexPath, MTCommonListTableCellConfig *cellConfig) {
[PYAppService pushViewControllerAnimated:[BlackListViewController new]];
};
}];
[config resetCellConfigForSection:1 row:1 config:^(MTCommonListTableCellConfig *cellConfig) {
cellConfig.cellAction = ^(MTCommonListTableViewController *tableViewController, NSIndexPath *indexPath, MTCommonListTableCellConfig *cellConfig) {
[PYAppService pushViewControllerAnimated:[PrivacySettingsViewController new]];
};
}];
[config resetCellConfigForSection:2 row:0 config:^(MTCommonListTableCellConfig *cellConfig) {
cellConfig.cellAction = ^(MTCommonListTableViewController *tableViewController, NSIndexPath *indexPath, MTCommonListTableCellConfig *cellConfig) {
[PYAppService pushViewControllerAnimated:[FeedbackViewController new]];
};
}];
[config resetCellConfigForSection:2 row:1 config:^(MTCommonListTableCellConfig *cellConfig) {
cellConfig.cellAction = ^(MTCommonListTableViewController *tableViewController, NSIndexPath *indexPath, MTCommonListTableCellConfig *cellConfig) {
[SVProgressHUD showInfoWithStatus:@"清除中..."];
[[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
[SVProgressHUD showSuccessWithStatus:@"清除缓存成功"];
// cellConfig.accessoryTitle = @"0.00M";
[self reloadData];
}];
};
cellConfig.accessoryTitle = [NSString stringWithFormat:@"%.02fM", [[SDImageCache sharedImageCache] totalDiskSize] / 1024 / 1024.0];
}];
return config;
}
@end