// // SettingsViewController.m // Youth // // Created by mambaxie on 2022/1/2. // #import "SettingsViewController.h" #import #import "ChangePhoneViewController.h" #import "BlackListViewController.h" #import "PrivacySettingsViewController.h" #import "FeedbackViewController.h" #import "AlertInputView.h" #import "MTCacheManager.h" @interface SettingsViewController () @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; [self.view addSubview:logoutItem]; self.tableView.contentSize = CGSizeMake(0, logoutItem.bottom); } - (MTCommonListTableConfig *)tableConfigForTableViewContorller { MTCommonListTableConfig *config = [MTCommonListTableConfig defaultConfigWithCellStyle:MTCommonListTableCellStyleDisclosureIndicator rowsCountForSections:@[@(2), @(2), @(2)]]; config.cellTitles = @[@"修改手机号", @"修改密码锁", @"黑名单", @"隐私设置", @"意见反馈", @"清理缓存"]; config.cellImageNames = @[@"TH_pro_set_phone_icon", @"TH_pro_set_password_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) { [PYAppService pushViewControllerAnimated:[ChangePhoneViewController new]]; }; }]; WeakSelf(self); [config resetCellConfigForSection:0 row:1 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: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