Files
yinmeng-ios-store/yinmeng-ios/DingDangApp/CodeClass/MyInfo/CC/DDMyInfoSettingViewController.m
2023-12-13 19:36:07 +08:00

368 lines
18 KiB
Objective-C

//
// DDMyInfoSettingViewController.m
// DingDangApp
//
// Created by apple on 2023/5/30.
//
#import "DDMyInfoSettingViewController.h"
#import <SDImageCache.h>
#import "DDNormalTextViewController.h"
#import "DDMyBlackListViewController.h"
#import "DDHandlePhoneCodeViewController.h"
#import "DDYoungModeViewController.h"
#import "DDMyInfoAccountViewController.h"
#import "DDWebViewController.h"
#import "DDUpdateVersionView.h"
@interface DDMyInfoSettingViewController ()
@end
@implementation DDMyInfoSettingViewController
-(UITableView *)myTableView
{
if (!_myTableView) {
_myTableView = [[UITableView alloc] initWithFrame:CGRectZero
style:UITableViewStyleGrouped];
_myTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
_myTableView.estimatedSectionHeaderHeight = 0;
_myTableView.estimatedSectionFooterHeight = 0;
_myTableView.dataSource = self;
_myTableView.delegate = self;
_myTableView.estimatedRowHeight = 0;
_myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_myTableView.separatorColor = [UIColor clearColor];
_myTableView.backgroundColor = [UIColor clearColor];
[_myTableView registerClass:DDMyInfoSettingTableViewCell.class forCellReuseIdentifier:@"DDMyInfoSettingTableViewCell"];
[ToolsObject customResetTableView:_myTableView];
}
return _myTableView;
}
- (UIButton *)loginOutButton{
if (!_loginOutButton){
_loginOutButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_loginOutButton setTitle:@"退出登录" forState:UIControlStateNormal];
[_loginOutButton setTitleColor:[UIColor jk_colorWithHexString:@"#FF5F5F"] forState:UIControlStateNormal];
_loginOutButton.titleLabel.font = [UIFont systemFontOfSize:16];
_loginOutButton.backgroundColor = UIColor.whiteColor;
[_loginOutButton jk_addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
DDCustomAlertView * alertView = [[DDCustomAlertView alloc] init:@[@"取消",@"退出"] title:@"确定要退出账号吗?" content:@"" alertType:0];
alertView.alertViewClickBlock = ^(NSInteger index, NSString * _Nonnull title) {
if ([title isEqualToString:@"退出"]) {
[ToolsObject loginOutJump];
}
};
[alertView showAlertView];
}];
}return _loginOutButton;
}
-(NSMutableArray *)listArr
{
if (!_listArr) {
_listArr = @[
[DDCellModel addDataWithName:@"账号与安全" icon:@"" cellType:DDCellModelType_Normal setType:(DDMyInfoModelType_Account) content:@""],
[DDCellModel addDataWithName:@"青少年模式" icon:@"" cellType:DDCellModelType_Normal setType:(DDMyInfoModelType_YoungMode) content:@""],
[DDCellModel addDataWithName:@"黑名单" icon:@"" cellType:DDCellModelType_Normal setType:(DDMyInfoModelType_MyBlackList) content:@""],
[DDCellModel addDataWithName:@"隐私协议" icon:@"" cellType:DDCellModelType_Normal setType:(DDMyInfoModelType_PrivacyAgreement) content:@""],
[DDCellModel addDataWithName:@"当前版本" icon:@"" cellType:DDCellModelType_Normal setType:(DDMyInfoModelType_CurrentVersion) content:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]],
[DDCellModel addDataWithName:@"清除缓存" icon:@"" cellType:DDCellModelType_Normal setType:(DDMyInfoModelType_ClearCache) content:[NSString stringWithFormat:@"%.2fM",[self getAppCacheSize]]],
[DDCellModel addDataWithName:@"位置显示" icon:@"" cellType:DDCellModelType_Switch setType:(DDMyInfoModelType_Location) content:[NSString stringWithFormat:@"%d",[AppDelegate getAppdelegate].isLocation]],
[DDCellModel addDataWithName:@"应用内通知" icon:@"" cellType:DDCellModelType_Switch setType:(DDMyInfoModelType_Notification) content:[NSString stringWithFormat:@"%d",[ToolsObject getUserModel].is_notification]],
// [DDCellModel addDat/*aWithName:@"" icon:@"" cellType:DDCellModelType_Copyright setType:(DDMyInfoModelType_Copyright) content:@"Copyright © 2022 - 2080\n奔梦科技 版权所有"],*/
].mutableCopy;
}
return _listArr;
}
-(CGFloat)getAppCacheSize
{
NSString *homeDir = NSHomeDirectory();
self.fileSize = 0;
[self currentFileSizeWithPath:homeDir];
NSString *fileSizeString = [NSByteCountFormatter stringFromByteCount:self.fileSize countStyle: NSByteCountFormatterCountStyleFile];
return [fileSizeString floatValue];
}
- (void)currentFileSizeWithPath:(NSString *)path{
NSFileManager * fileManger = [NSFileManager defaultManager];
BOOL isDirect = NO;
BOOL isExist = [fileManger fileExistsAtPath:path isDirectory:&isDirect];
if (isExist){
if(isDirect){
NSArray * dirArray = [fileManger contentsOfDirectoryAtPath:path error:nil];
NSString * subPath = nil;
for(NSString *str in dirArray) {
subPath = [path stringByAppendingPathComponent:str];
[self currentFileSizeWithPath:subPath];
}
}else{
NSDictionary *dict = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
NSInteger size = [dict[@"NSFileSize"] integerValue];
_fileSize += size;
}
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self defaultNavTitle:@"系统设置" hideLine:YES];
[self firstLocation];
self.view.backgroundColor = [UIColor jk_colorWithHexString:@"#f6f6f6"];
[self.view addSubview:self.myTableView];
[self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(DDNavigationBarHeight());
make.left.right.mas_equalTo(0);
make.bottom.mas_equalTo(-DDBottomHeight());
}];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 70;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
return [UIView new];
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 70)];
headerView.backgroundColor = [UIColor jk_colorWithHexString:@"#f6f6f6"];
self.loginOutButton.frame = CGRectMake(0, 20, kWidth, 50);
[headerView addSubview:self.loginOutButton];
return headerView;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.listArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
DDCellModel *model =self.listArr[indexPath.row];
if(model.cellType == DDCellModelType_Copyright){
return 70;
}else{
return 50;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *indentifiers = @"DDMyInfoSettingTableViewCell";
DDMyInfoSettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifiers];
if (!cell) {
cell = [[DDMyInfoSettingTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifiers];
}
cell.model = self.listArr[indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.didSwitchChangeValueBlock = ^(BOOL value, UISwitch * _Nonnull sender,DDCellModel * _Nonnull model) {
if (model.setType == DDMyInfoModelType_Location){
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] canOpenURL:url]) {
NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {}];
} else {
[[UIApplication sharedApplication] openURL:url];
}
}
}else if (model.setType == DDMyInfoModelType_Notification){
// WeakSelf(weakSelf)
// [NetworkRequest requestPOST:@"/home/set/notification" parameters:@{} block:^(BaseResponse * _Nonnull response) {
// if (response.code == 200) {
// AppUserModel * model = [ToolsObject getUserModel];
// model.is_notification = !model.is_notification;
// [ToolsObject saveUserModel:model];
// DDCellModel * cellModel = weakSelf.listArr[weakSelf.listArr.count-1];
// cellModel.content = [NSString stringWithFormat:@"%d",[ToolsObject getUserModel].is_notification];
// dispatch_async(dispatch_get_main_queue(), ^{
// NSIndexPath *index = [NSIndexPath indexPathForRow:weakSelf.listArr.count-1 inSection:0];
// [weakSelf.myTableView reloadRowsAtIndexPaths:@[index] withRowAnimation:(UITableViewRowAnimationNone)];
// });
// }
// }];
}else{}
};
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DDCellModel *model = self.listArr[indexPath.row];
switch (model.setType) {
case DDMyInfoModelType_ClearCache:
{
/* 清除缓存 */
DDCustomAlertView * alertView = [[DDCustomAlertView alloc] init:@[@"取消",@"清除"] title:@"是否清除缓存?" content:@"" alertType:0];
alertView.alertViewClickBlock = ^(NSInteger index, NSString * _Nonnull title) {
if ([title isEqualToString:@"清除"]) {
[[SDImageCache sharedImageCache] clearMemory];
[[SDImageCache sharedImageCache] clearDiskOnCompletion:^{}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
for (NSString *p in files) {
if([p rangeOfString:@"RoomChatImage"].location !=NSNotFound) {
continue;
}
NSError *error;
NSString *path = [cachPath stringByAppendingPathComponent:p];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
}
}
});
}
DDCellModel * cellModel = self.listArr[self.listArr.count-3];
cellModel.content = [NSString stringWithFormat:@"%.2fM",[self getAppCacheSize]];
[self.myTableView reloadData];
};
[alertView showAlertView];
}
break;
case DDMyInfoModelType_PrivacyAgreement:
{
/* 隐私协议 */
DDWebViewController * webVC = [DDWebViewController webControlerWithUrlStr:[NSString stringWithFormat:@"%@/yinmeng/modules/rule/privacy-wap.html",API_HOST_H5_URL] isShowNavBar:YES navTitle:@"隐私协议"];
webVC.view.backgroundColor = UIColor.whiteColor;
[[ToolsObject getCurrentViewController].navigationController pushViewController:webVC animated:NO];
}
break;
case DDMyInfoModelType_MyBlackList:
{
DDMyBlackListViewController * blackVC = [[DDMyBlackListViewController alloc] init];
[self.navigationController pushViewController:blackVC animated:YES];
}
break;
case DDMyInfoModelType_EditePassword:
{
DDHandlePhoneCodeViewController * editePsd = [[DDHandlePhoneCodeViewController alloc] init];
editePsd.type = DDHandlePasswordType_Edite;
[self.navigationController pushViewController:editePsd animated:YES];
}
break;
case DDMyInfoModelType_YoungMode:
{
DDYoungModeViewController *young = [[DDYoungModeViewController alloc] init];
[self.navigationController pushViewController:young animated:YES];
}
break;
case DDMyInfoModelType_CurrentVersion:
{
[self requestBaseConfig];
}
break;
case DDMyInfoModelType_Account:
{
DDMyInfoAccountViewController *account = [[DDMyInfoAccountViewController alloc] init];
[self.navigationController pushViewController:account animated:YES];
}
break;
case DDMyInfoModelType_AboutUs:{
DDWebViewController * webVC = [DDWebViewController webControlerWithUrlStr:[NSString stringWithFormat:@"%@/#/publicpage?position=1001",KWebURL] isShowNavBar:YES navTitle:@"联系我们"];
[self.navigationController pushViewController:webVC animated:NO];
}
break;
case DDMyInfoModelType_Location:
{
}
break;
default:
break;
}
}
- (void)requestBaseConfig{
WeakSelf(weakSelf)
[NetworkRequest requestPOST:@"/common/base" parameters:@{} block:^(BaseResponse * _Nonnull response) {
if ([ToolsObject IsNullWithObject:response.data]) {
return;
}
RoomConfigModel * model = [RoomConfigModel mj_objectWithKeyValues:response.data];
if (model.app.version.is_need_update) {
[AppDelegate getAppdelegate].alertViewIsShow = YES;
if (model.app.version.enforce){
[DDUpdateVersionView showUpdateVersionView:YES contentStr:model.app.version.content versionStr:model.app.version.version];
}else{
[DDUpdateVersionView showUpdateVersionView:NO contentStr:model.app.version.content versionStr:model.app.version.version];
}
return;
}
DDCustomAlertView * view = [[DDCustomAlertView alloc] init:@[@"我知道了"] title:@"当前已是最新版本" content:@"" alertType:0];
[view showAlertView];
}];
}
- (void)firstLocation {
[[TZLocationManager manager] startLocation];
self.authStatus = [CLLocationManager authorizationStatus];
if ([CLLocationManager locationServicesEnabled] == NO) {
self.authStatus = -1;
return;
}
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied ||
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted) {
[AppDelegate getAppdelegate].isLocation = NO;
}
[[TZLocationManager manager] startLocationWithSuccessBlock:^(NSArray<CLLocation *> *locations) {
} failureBlock:^(NSError *error) {
if ([AppDelegate getAppdelegate].isLocation) {
[AppDelegate getAppdelegate].isLocation = NO;
}
} geocoderBlock:^(NSArray *geocoderArray) {
if (geocoderArray.count > 0) {
CLPlacemark * placemark = geocoderArray[0];
[AppDelegate getAppdelegate].longitude = [NSString stringWithFormat:@"%f",placemark.location.coordinate.longitude];
[AppDelegate getAppdelegate].latitude = [NSString stringWithFormat:@"%f",placemark.location.coordinate.latitude];
[AppDelegate getAppdelegate].locationCity = [NSString stringWithFormat:@"%@",placemark.locality];
[AppDelegate getAppdelegate].provinceStr = [NSString stringWithFormat:@"%@",placemark.administrativeArea];
[AppDelegate getAppdelegate].countyStr = @"";
[AppDelegate getAppdelegate].addressStr = [NSString stringWithFormat:@"%@%@%@",[ToolsObject IsNullWithObject:[AppDelegate getAppdelegate].provinceStr]?@"":[AppDelegate getAppdelegate].provinceStr,[ToolsObject IsNullWithObject:[AppDelegate getAppdelegate].locationCity]?@"":[AppDelegate getAppdelegate].locationCity,placemark.name];
if (![AppDelegate getAppdelegate].isLocation) {
[AppDelegate getAppdelegate].isLocation = YES;
}
}
}];
}
- (void)appDidBecomeActiveNotification {
if ([CLLocationManager authorizationStatus] == self.authStatus || self.authStatus == -1) {
DDCellModel * cellModel = self.listArr[self.listArr.count-2];
cellModel.content = [NSString stringWithFormat:@"%d",[AppDelegate getAppdelegate].isLocation];
WeakSelf(weakSelf)
dispatch_async(dispatch_get_main_queue(), ^{
NSIndexPath *index = [NSIndexPath indexPathForRow:weakSelf.listArr.count-2 inSection:0];
[weakSelf.myTableView reloadRowsAtIndexPaths:@[index] withRowAnimation:(UITableViewRowAnimationNone)];
});
return;
}
[self firstLocation];
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
}
/*
#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.
}
*/
@end