// // LFWSettingViewController.m // YouHuiProject // // Created by 小花 on 2018/1/25. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LFWSettingViewController.h" #import "LFWAuthorityManager.h" #import "CCActionSheet.h" #import #import #import "DXAlertView.h" #import "LFWLoginViewController.h" #import @interface LFWSettingViewController () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSArray *dataArr; @property (nonatomic, strong) NSArray *sexArr; @end @implementation LFWSettingViewController - (void)viewDidLoad { [super viewDidLoad]; [self configNavigationBar]; [self addObserToController]; } - (void)configNavigationBar { self.view.backgroundColor = [UIColor whiteColor]; [self.navigationBar setNavTitle:@"设置"]; self.navigationBar.showNavigationBarBottomLine = YES; [self.view addSubview:self.tableView]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; UILabel *logOut = [[UILabel alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-50-BottomMargin, SCREEN_WIDTH, 50)]; logOut.backgroundColor = [UIColor whiteColor]; logOut.textColor = [UIColor homeRedColor]; logOut.textAlignment = NSTextAlignmentCenter; logOut.font = [UIFont systemFontOfSize:14]; logOut.text = [AccountTool isLogin] ? @"退出登录":@"快速登录"; logOut.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(logOutAction)]; [logOut addGestureRecognizer:tap]; [self.view addSubview:logOut];} - (void)addObserToController { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(becomActive) name:UIApplicationDidBecomeActiveNotification object:nil]; } - (void)becomActive { [self.tableView reloadData]; } /** 返回 */ - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } /** 退出登录 */ - (void)logOutAction { if ([AccountTool isLogin]) { // DXAlertView *alert = [[DXAlertView alloc] initWithTitle:@"温馨提示" message:@"是否要退出登录?" cancelBtnTitle:@"取消" otherBtnTitle:@"确定"]; // alert.clickBlock = ^(NSInteger index) { // if (index == 1) { // [self logOutManager]; // } // }; // [alert show]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否要退出登录?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [self logOutManager]; }]; [alert addAction:cancel]; [alert addAction:sure]; [self presentViewController:alert animated:YES completion:nil]; }else { LFWLoginViewController *login = [[LFWLoginViewController alloc] init]; [self presentViewController:login animated:YES completion:nil]; } } - (void)logOutManager { [LFWHttp post:Logout params:nil success:^(id json) { [AccountTool deleteAccount]; [self.navigationController popViewControllerAnimated:YES]; } failure:^(NSError *error) { }]; } /** switch 点击 */ - (void)switchAction { NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if([[UIApplication sharedApplication]canOpenURL:url] ) { if (@available(iOS 10.0, *)) { [[UIApplication sharedApplication] openURL:url options:@{}completionHandler:^(BOOL success) { }]; } else { [[UIApplication sharedApplication]openURL:url]; } } } #pragma mark ------------------ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsMake(0, 50, 0, 0)]; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArr.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 50; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"]; cell.textLabel.text = self.dataArr[indexPath.row][@"title"]; if (indexPath.row != 0) { cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } // if (indexPath.row == 0) { // NSString *sex = [[NSUserDefaults standardUserDefaults] objectForKey:UserSexKey]; // // cell.detailTextLabel.text = [sex isEqualToString:@"0"] ? @"女":@"男"; // } if (indexPath.row == 0) { UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-60, 10, 50, 30)]; [switchView addTarget:self action:@selector(switchAction) forControlEvents:UIControlEventTouchUpInside]; // 开关事件切换通知 [cell addSubview:switchView]; if ([LFWAuthorityManager isObtainUserNotificationAuthority]) { switchView.on = YES; }else { switchView.on = NO; } } if (indexPath.row == 1) { NSUInteger intg = [[SDImageCache sharedImageCache] getSize]; NSString * currentVolum = [NSString stringWithFormat:@"%@",[self fileSizeWithInterge:intg]]; cell.detailTextLabel.text = currentVolum; } if (indexPath.row == 2) { if ([[ALBBSession sharedInstance] isLogin]) { cell.detailTextLabel.text = @"已授权"; }else { cell.detailTextLabel.text = @"未授权"; } } NSString *imgName = self.dataArr[indexPath.row][@"image"]; cell.imageView.image = [UIImage imageNamed:imgName]; cell.textLabel.font = [UIFont systemFontOfSize:15]; cell.textLabel.textColor = [UIColor YHColorWithHex:0x666666]; cell.detailTextLabel.font = [UIFont systemFontOfSize:15]; cell.detailTextLabel.textColor = [UIColor YHColorWithHex:0x999999]; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // if (indexPath.row == 0) { // //改变性别 // [self changeUserSex]; // } if (indexPath.row == 1) { //清理缓存 [self clearCacheWith:indexPath]; } if (indexPath.row == 2) { //淘宝授权 [self taobaoAuthor]; } } #pragma mark ------------ private---------- /** 改变性别 */ - (void)changeUserSex { CCActionSheet *actionSheet = [[CCActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:self.sexArr]; [actionSheet showInView:self.view]; } /** 清理缓存 */ - (void)clearCacheWith:(NSIndexPath *)indexPath { [[SDImageCache sharedImageCache] clearMemory]; [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{ NSUInteger intg = [[SDImageCache sharedImageCache] getSize]; NSString * currentVolum = [NSString stringWithFormat:@"%@",[self fileSizeWithInterge:intg]]; UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; cell.detailTextLabel.text = currentVolum; }]; } /** 淘宝授权 */ - (void)taobaoAuthor { if ([[ALBBSession sharedInstance] isLogin]) { // DXAlertView *alert = [[DXAlertView alloc] initWithTitle:@"温馨提示" message:@"是否取消淘宝授权?" cancelBtnTitle:@"取消" otherBtnTitle:@"确定"]; // alert.delegate = self; // [alert show]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否要取消淘宝授权?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { ALBBSDK *albbSDK = [ALBBSDK sharedInstance]; [albbSDK logoutWithCallback:^{ [self.tableView reloadData]; }]; }]; [alert addAction:cancel]; [alert addAction:sure]; [self presentViewController:alert animated:YES completion:nil]; }else { ALBBSDK *albbSDK = [ALBBSDK sharedInstance]; [albbSDK setAppkey:ALBC_APP_KEY]; [albbSDK setAuthOption:NormalAuth]; [albbSDK auth:self successCallback:^(ALBBSession *session){ // ALBBUser *user = [session getUser]; [self.tableView reloadData]; } failureCallback:^(ALBBSession *session,NSError *error){ NSLog(@"session == %@,error == %@",session,error); }]; } } #pragma mark ---------------- DXAlertView delegate --------- - (void)dxAlertView:(DXAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 1) { ALBBSDK *albbSDK = [ALBBSDK sharedInstance]; [albbSDK logoutWithCallback:^{ [self.tableView reloadData]; }]; } } //计算出大小 - (NSString *)fileSizeWithInterge:(NSInteger)size{ // 1k = 1024, 1m = 1024k if (size < 1024) {// 小于1k return [NSString stringWithFormat:@"%ld B",(long)size]; }else if (size < 1024 * 1024){// 小于1m CGFloat aFloat = size/1024; return [NSString stringWithFormat:@"%.0fK",aFloat]; }else if (size < 1024 * 1024 * 1024){// 小于1G CGFloat aFloat = size/(1024 * 1024); return [NSString stringWithFormat:@"%.1fM",aFloat]; }else{ CGFloat aFloat = size/(1024*1024*1024); return [NSString stringWithFormat:@"%.1fG",aFloat]; } } #pragma mark ------------------- CCActionSheet Delegate --------- - (void)actionSheet:(CCActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { NSDictionary *para = @{@"sex":@(buttonIndex)}; if ([AccountTool isLogin]) { [LFWHttp post:MySetting params:para success:^(id json) { NSInteger localSex = [[[NSUserDefaults standardUserDefaults] objectForKey:UserSexKey] integerValue]; if (buttonIndex != localSex) { [self saveSexWithButtonIndex:buttonIndex]; [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil]; } } failure:^(NSError *error) { }]; }else { [self saveSexWithButtonIndex:buttonIndex]; [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil]; } } - (void)saveSexWithButtonIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:UserSexKey]; }else { [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:UserSexKey]; } [[NSUserDefaults standardUserDefaults] synchronize]; [self.tableView reloadData]; } - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain]; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; _tableView.sectionFooterHeight = 0; _tableView.sectionHeaderHeight = 0; _tableView.delegate = self; _tableView.dataSource = self; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; _tableView.backgroundColor = [UIColor yhGrayColor]; _tableView.bounces = YES; _tableView.showsVerticalScrollIndicator = NO; [_tableView setSeparatorColor:[UIColor YHColorWithHex:0xdddddd]]; } return _tableView; } - (NSArray *)dataArr { if (!_dataArr) { _dataArr = @[@{@"title":@"推送设置",@"image":@"push_img"}, @{@"title":@"清理缓存",@"image":@"clear_cache"}, @{@"title":@"淘宝授权",@"image":@"taobao_man"},]; } return _dataArr; } - (NSArray *)sexArr { if (!_sexArr) { _sexArr = @[@"女",@"男"]; } return _sexArr; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ -(void)aotdPY:(UIView*) aotdPY aVHjs4im:(UIScreen*) aVHjs4im aExXe9Ivh:(UIBezierPath*) aExXe9Ivh anSlW:(UIButton*) anSlW aU18NBisL:(UITableView*) aU18NBisL a1Ixqm:(UIColor*) a1Ixqm a1eFrC5kU0:(UIKeyCommand*) a1eFrC5kU0 a0ZB23aTOK:(UIDevice*) a0ZB23aTOK auf8rGR:(UIDevice*) auf8rGR acHLp4exri:(UITableView*) acHLp4exri aJjtQbZ8UWE:(UITableView*) aJjtQbZ8UWE aBAtn:(UIApplication*) aBAtn a8c2sD:(UIEvent*) a8c2sD aHGCEv:(UITableView*) aHGCEv alU56fxH:(UIRegion*) alU56fxH a9cTeI4Srj:(UIViewController*) a9cTeI4Srj aPxaREG7g:(UIFont*) aPxaREG7g aJPeU8I:(UIKeyCommand*) aJPeU8I { NSLog(@"Wab3cXyHfdv5UtG7eBVkoq8Lx"); NSLog(@"cmpDBZeFgMYnGSNr"); NSLog(@"nSMYfONVokDd6jhGPXubRWg"); NSLog(@"WPeK1vbiBh8EHyuadN5Oz32x4Um9qQgFwGkrDY"); NSLog(@"eBfAaGSn1lX0"); NSLog(@"PBHGzViQjytmLh"); NSLog(@"vyVhwJskbjf"); NSLog(@"Hym0SsgCp8ZEr2f4IhX"); NSLog(@"DZEiod3Ouz6XlKmL2JPb"); NSLog(@"4UKzNLApj5uglYeibQ"); NSLog(@"QFE8uVTkzon7L6mcZGXsptWjfAOCNU3DPwqhI50"); NSLog(@"dx17Fb503azuwqZts9kPA2EIpiY"); } -(void)arHf1:(UILabel*) arHf1 aOMkxLe0Bfj:(UIApplication*) aOMkxLe0Bfj aM4sbLegIH:(UIUserInterfaceIdiom*) aM4sbLegIH aZ2tSoNayH:(UISwitch*) aZ2tSoNayH akA3HF2lzOf:(UIWindow*) akA3HF2lzOf aTqo30iL4:(UIEvent*) aTqo30iL4 aVOSPnX0hMC:(UIDevice*) aVOSPnX0hMC azofn:(UIFont*) azofn aOpwGs:(UIEvent*) aOpwGs a2WUH:(UIWindow*) a2WUH aWG1k0:(UIVisualEffectView*) aWG1k0 a0pr1ZItYa:(UIBarButtonItem*) a0pr1ZItYa atgG5:(UIViewController*) atgG5 a5sKl3grUL6:(UIEvent*) a5sKl3grUL6 axLvi:(UIButton*) axLvi a7sVnO:(UIScreen*) a7sVnO { NSLog(@"QAe2sX3GIHgvx8dBlD1Ktr7zWfN0in"); NSLog(@"jUdRvbk5w2FgSPNKiQA0TfOreCtWz8xD"); NSLog(@"kZQdCW0Mxr2yD"); NSLog(@"orGsnIPW9hVDvX"); NSLog(@"sTOzlfte6KvkrEN0B72cd5aS4AgJYMDuXw1C"); NSLog(@"oSZpIG5EAF18fkHJxWNc9dMm07l4B6yLw2uaQKzr"); NSLog(@"BFz581vOwDsYNIhlQUTgJV97i0Kk2j"); NSLog(@"XLqwyUsFJMmviBS40auPlYKr"); NSLog(@"R8zgHj0wAMukLtavYBTeGi"); NSLog(@"yb8u5V0nYfpWko1x7POH"); NSLog(@"SfK0xHQ8NaoTDiX6sgckP4Rn3GtAYUrv"); NSLog(@"NWs9TGZzqhRYj47XobMIBaySKCwu362nxm"); } -(void)aNkAJQgWBL:(UIBarButtonItem*) aNkAJQgWBL aWKqBLD50:(UIAlertView*) aWKqBLD50 aKrIoSzwQX:(UILabel*) aKrIoSzwQX aOzQweWuT:(UIControl*) aOzQweWuT aURW7MdxF2H:(UIMotionEffect*) aURW7MdxF2H adHBWm:(UIUserInterfaceIdiom*) adHBWm azTYIag:(UICollectionView*) azTYIag a45KqXkprI:(UIInputView*) a45KqXkprI ayFGTfsA0u:(UIImageView*) ayFGTfsA0u akFBwhD:(UIFont*) akFBwhD aq7ShW6:(UIApplication*) aq7ShW6 a5UxpzZd:(UIImage*) a5UxpzZd aomau0Al:(UIControl*) aomau0Al { NSLog(@"CqPUEsz64QjONu97MwHhtoi3ZXT"); NSLog(@"zjhFMR2I1WB0ACJVUZs6qd8rg9mPS3okl7paN45T"); NSLog(@"nEQyhKrWOCb0XH25liVTzpf1qGZtJPvUe"); NSLog(@"WVMaxrGdiYBwOLtIXjkE"); NSLog(@"MFNkTGdAuQPOnZz"); NSLog(@"YEU1T2MQoVq"); NSLog(@"KLhsr4kEBIn8WvVaJxw9fgqz5t"); NSLog(@"khTy1BeUGOnMgfL5uDlNQaP"); NSLog(@"kK4vLWePYJ39QlrH5qDVmSd2p"); NSLog(@"uMahkiRqjY4fQcVKBrG01S53ysb7d6nwAPv"); NSLog(@"YTemL0Dr7BQ2FpcP"); NSLog(@"3Qi2MJqkRnwhdr"); NSLog(@"It5GBvbw7EH4A1VTZqr"); } @end