// // YOUPAIBBSettingVC.m // VQU // // Created by Elaine on 2021/11/1. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAIBBSettingVC.h" #import "YOUPAIZYSettingCell.h" #import "YOUPAILCBindPhoneAccountVC.h" #import "YOUPAILCMediaChatRecordVC.h" #import "YOUPAILCBlackListVC.h" #import "YOUPAILCNewChatNoticationVC.h" #import "YOUPAILCAboutVC.h" #import "YOUPAILCUpdateVersionVC.h" #import "UIViewController+TFPresent.h" #import "YOUPAILPYoungSettingVC.h" @interface YOUPAIBBSettingVC () @property(nonatomic,strong)UITableView* youpaiptableView; @property(nonatomic,strong)UIView* youpaipfooterView; /* <#Annotation#> */ @property (strong, nonatomic) NSArray *youpaiptitleArr; @end @implementation YOUPAIBBSettingVC - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.youpaiptableView reloadData]; } - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"设置"; if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender != 1) { //男 self.youpaiptitleArr = @[@"账号绑定",@"消息通知",@"青少年模式",@"黑名单",@"清除缓存",@"清除所有聊天记录",@"去评分",@"关于花蝶"]; }else{ self.youpaiptitleArr = @[@"账号绑定",@"消息通知",@"黑名单",@"清除缓存",@"清除所有聊天记录",@"去评分",@"关于花蝶"]; } [self.view addSubview:self.youpaiptableView]; self.youpaiptableView.tableFooterView = self.youpaipfooterView; } -(UIView *)youpaipfooterView{ if (!_youpaipfooterView) { _youpaipfooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 120 + SafeHeight)]; _youpaipfooterView.backgroundColor = LCWhiteColor; UIButton* startBtn = [[UIButton alloc]initWithFrame:CGRectMake(40.0f,40.0f, KScreenWidth - 80.0f, 49.0f)]; startBtn.backgroundColor = HexColorFromRGB(0x4F4B5B); startBtn.titleLabel.font = LCFont16; startBtn.layer.cornerRadius = 24.5f; startBtn.layer.masksToBounds = YES; [startBtn setTitle:@"退出登录" forState:(UIControlStateNormal)]; [startBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; [startBtn addTarget:self action:@selector(youpaifbackClick) forControlEvents:(UIControlEventTouchUpInside)]; [_youpaipfooterView addSubview:startBtn]; } return _youpaipfooterView; } - (UITableView *)youpaiptableView{ if (!_youpaiptableView) { _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight) style:UITableViewStylePlain]; _youpaiptableView.showsVerticalScrollIndicator = NO; _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone; _youpaiptableView.backgroundColor = LCWhiteColor; // _tableView.separatorInset = UIEdgeInsetsMake(0,34, 0,34); _youpaiptableView.delegate = self; _youpaiptableView.dataSource = self; if (@available(iOS 15.0, *)) { _youpaiptableView.sectionHeaderTopPadding = 0; } } return _youpaiptableView; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.youpaiptitleArr.count; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return CGFLOAT_MIN; } - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ return [[UIView alloc]init]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 54.0f; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAIZYSettingCell * cell = [[YOUPAIZYSettingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"commonCell"]; NSString *titleStr = self.youpaiptitleArr[indexPath.row]; if ([titleStr isEqualToString:@"账号绑定"]) { cell.youpaipheadLabel.text = @"账号绑定"; cell.youpaiparrowLabel.text = [LCSaveModel getUserModel].youpaipuserinfo.youpaipmobile; if (cell.youpaiparrowLabel.text.length != 0) { cell.youpaiparrowImgView.hidden = YES; [cell.youpaiparrowLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.offset(-20.0f); make.centerY.equalTo(cell.youpaipbaseView); make.height.equalTo(15); }]; }else{ cell.youpaiparrowImgView.hidden = NO; [cell.youpaiparrowLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(cell.youpaiparrowImgView.left).offset(-5); make.centerY.equalTo(cell.youpaipbaseView); make.height.equalTo(15); }]; } }else if ([titleStr isEqualToString:@"黑名单"]){ // if (indexPath.row==0) { // cell.headLabel.text = @"通话记录"; // }else{ cell.youpaipheadLabel.text = @"黑名单"; // } } /*else if ([titleStr isEqualToString:@"勿扰模式"]){ cell.hintLabel.hidden = NO; cell.headLabel.text = @"勿扰模式"; cell.rightSwitch.hidden = NO; cell.arrowImgView.hidden = YES; if ([LCSaveModel getUserModel].userinfo.is_anchor == 1) { cell.rightSwitch.selected = ![LCSaveData getVideoOpenStatu]; [cell.rightSwitch addTarget:self action:@selector(youpaifvideoSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside]; }else{ cell.rightSwitch.selected = [LCSaveData getProfileWuraoStatus]; [cell.rightSwitch addTarget:self action:@selector(youpaifopenDontDisturb) forControlEvents:UIControlEventTouchUpInside]; } }*/else if ([titleStr isEqualToString:@"青少年模式"]){ // if (indexPath.row==0) { // cell.headLabel.text = @"通话记录"; // }else{ cell.youpaipheadLabel.text = @"青少年模式"; // } } else if ([titleStr isEqualToString:@"消息通知"]){ cell.youpaipheadLabel.text = @"消息通知"; }else if ([titleStr isEqualToString:@"清除缓存"]){ cell.youpaipheadLabel.text = @"清除缓存"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSString * resultPath = [DocPath stringByAppendingPathComponent:@"/save"]; NSUInteger tmpSize = resultPath.fileSize+[[SDImageCache sharedImageCache] getSize]; CGFloat unit = 1000.0; NSString *sizeText = nil; if (tmpSize >= unit * unit * unit) { // >= 1GB sizeText = [NSString stringWithFormat:@"%.1fGB", tmpSize / unit / unit / unit]; } else if (tmpSize >= unit * unit) { // >= 1MB sizeText = [NSString stringWithFormat:@"%.1fMB", tmpSize / unit / unit]; } else if (tmpSize >= unit) { // >= 1KB sizeText = [NSString stringWithFormat:@"%.1fKB", tmpSize / unit]; } else { // >= 0B sizeText = [NSString stringWithFormat:@"%zdB", tmpSize]; } dispatch_async(dispatch_get_main_queue(), ^{ cell.youpaiparrowLabel.text = sizeText; }); }); }else if ([titleStr isEqualToString:@"清除所有聊天记录"]){ cell.youpaipheadLabel.text = @"清除所有聊天记录"; } else if ([titleStr isEqualToString:@"去评分"]){ cell.youpaipheadLabel.text = @"去评分"; }else if ([titleStr isEqualToString:@"关于花蝶"]){ cell.youpaipheadLabel.text = @"关于花蝶"; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *titleStr = self.youpaiptitleArr[indexPath.row]; if ([titleStr isEqualToString:@"账号绑定"]) { if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipmobile.length == 0) { YOUPAILCBindPhoneAccountVC* bindAccount = [[YOUPAILCBindPhoneAccountVC alloc]init]; [self.navigationController pushViewController:bindAccount animated:YES]; } }else if ([titleStr isEqualToString:@"黑名单"]){ YOUPAILCBlackListVC* black = [[YOUPAILCBlackListVC alloc]init]; [self.navigationController pushViewController:black animated:YES]; }else if ([titleStr isEqualToString:@"勿扰模式"]){ }else if ([titleStr isEqualToString:@"青少年模式"]){ YOUPAILPYoungSettingVC* setting = [[YOUPAILPYoungSettingVC alloc]init]; [self.navigationController pushViewController:setting animated:YES]; }else if ([titleStr isEqualToString:@"消息通知"]){ YOUPAILCNewChatNoticationVC * noti = [[YOUPAILCNewChatNoticationVC alloc]init]; [self.navigationController pushViewController:noti animated:YES]; }else if ([titleStr isEqualToString:@"清除缓存"]){ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"是否确定清除缓存?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){ }]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){ [ZCHUDHelper showWithStatus:@"正在清理..."]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [[SDImageCache sharedImageCache] clearMemory]; [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{ }]; NSString * resultPath = [DocPath stringByAppendingPathComponent:@"/save"]; NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:resultPath]; for (NSString *fileName in enumerator) { NSString *filePath = [resultPath stringByAppendingPathComponent:fileName]; [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; } dispatch_async(dispatch_get_main_queue(), ^{ [ZCHUDHelper showTitle:@"清理完成"]; [self.youpaiptableView reloadData]; }); }); }]; [alertController addAction:cancelAction]; [alertController addAction:okAction]; [self presentViewController:alertController animated:YES completion:nil]; }else if ([titleStr isEqualToString:@"清除所有聊天记录"]){ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"是否确定清除聊天记录?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){ }]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){ id manager = [[NIMSDK sharedSDK] conversationManager]; NIMDeleteMessagesOption* deleteOption = [[NIMDeleteMessagesOption alloc]init]; deleteOption.removeSession = YES; deleteOption.removeTable = YES; [manager deleteAllMessages:deleteOption]; [ZCHUDHelper showTitle:@"聊天记录已清空"]; }]; [alertController addAction:cancelAction]; [alertController addAction:okAction]; [self presentViewController:alertController animated:YES completion:nil]; } else if ([titleStr isEqualToString:@"去评分"]){ NSString *urlStr = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8", APPID]; if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:urlStr]]) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]]; } }else if ([titleStr isEqualToString:@"关于花蝶"]){ YOUPAILCAboutVC* about = [[YOUPAILCAboutVC alloc]init]; [self.navigationController pushViewController:about animated:YES]; } } - (void)youpaifbackClick{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"退出账号" message:@"是否退出当前账号登录状态?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){ }]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){ [self.navigationController popToRootViewControllerAnimated:NO]; [LCTools changeRootToLogin]; }]; [alertController addAction:cancelAction]; [alertController addAction:okAction]; [self presentViewController:alertController animated:YES completion:nil]; } -(void)youpaifcheckAppUpdate:(BOOL)need { [ZCHUDHelper showWithStatus:@"请求中..."]; [LCHttpHelper requestWithURLString:CheckUpdateVersion parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary *dict = (NSDictionary *)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { NSString *newVersion = [[dict objectForKey:@"data"] objectForKey:@"newversion"]; //NSString *myVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; NSString *app_build = [[UIApplication sharedApplication] appVersion]; if ([newVersion compare:app_build options:NSCaseInsensitiveSearch] > 0) { [ZCHUDHelper dismiss]; YOUPAILCUpdateVersionVC *VC= [[YOUPAILCUpdateVersionVC alloc]init]; VC.youpaipenforce = [[[dict objectForKey:@"data"] objectForKey:@"enforce"]integerValue]; VC.youpaipdownLoadUrl = [[dict objectForKey:@"data"] objectForKey:@"downloadurl"]; VC.youpaipversionStr = [NSString stringWithFormat:@"版本号:%@",newVersion]; VC.youpaipupdateText = [[dict objectForKey:@"data"] objectForKey:@"upgradetext"]; VC.vWidth = KScreenWidth - 70; NSDictionary *attrs = @{NSFontAttributeName : [UIFont systemFontOfSize:14]}; CGSize maxSize= [VC.youpaipupdateText boundingRectWithSize:CGSizeMake(VC.vWidth-116,66) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size; if(maxSize.height<28) { maxSize.height = 28; } else{ maxSize.height = maxSize.height+20; } VC.vHeight = VC.vWidth*203/305.0 +86 + maxSize.height + 120; VC.isTouchDismiss = YES; [self TFPresentVC:VC completion:^{ }]; }else{ if (need) { // [ZCHUDHelper dismiss]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)0.5*NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [ZCHUDHelper showTitle:@"已经是最新版本" showtime:1]; }); } } } } failure:^(NSError *error) { [ZCHUDHelper dismiss]; }]; } - (void)youpaifvideoSwitchValueChange:(UIButton*)switchView{ NSInteger status = 0; if (switchView.selected == NO) {//将状态置为1空闲 status = 0; }else{ status = 1; } [LCHttpHelper requestWithURLString:BigCastSetVideoStatus parameters:@{@"status":@(status)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) { if (status==1) { [LCSaveData saveVideoOpenStatu:YES]; }else{ [LCSaveData saveVideoOpenStatu:NO]; } } [self.youpaiptableView reloadData]; } failure:^(NSError *error) { }]; } - (void)youpaifopenDontDisturb{ NSString *status = [LCSaveData getProfileWuraoStatus] ? @"0" : @"1"; [LCHttpHelper requestWithURLString:SetWuRaoStatus parameters:@{@"is_msg_refuse":status} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) { if ([status isEqualToString:@"1"]) { [ZCHUDHelper showTitle:@"打开勿打扰"]; [LCSaveData saveProfileWuraoStatus:YES]; [self.youpaiptableView reloadData]; }else{ [ZCHUDHelper showTitle:@"关闭勿打扰"]; [LCSaveData saveProfileWuraoStatus:NO]; [self.youpaiptableView reloadData]; } } } failure:^(NSError *error) { }]; } @end