// // backupsOptionViewController.m // 双子星云手机 // // Created by xd h on 2024/5/15. // #import "backupsOptionViewController.h" #import "uploadFileRecordViewController.h" #import "downloadManager.h" //#import "backupsFileManager.h" #import "nasBackupsManager.h" #import "AFNetworkReachabilityManager.h" #import "backupsOptionTipView.h" #import "fileTransfeSetViewController.h" @interface backupsOptionViewController () { UIButton* rightTransferListButton;//传输列表 UIView* rightRedView; BOOL hadUploadTaskType; BOOL hadDownloadTaskType; } @property(nonatomic,strong) UIButton* imageBackupsButton; @property(nonatomic,strong)UILabel*imageBackupsLabel; @end @implementation backupsOptionViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.toolBar setHidden:YES]; [self.navigationBar setHidden:YES]; [self.navBarBGView setHidden:NO]; self.navBarBGView.backgroundColor = [UIColor whiteColor]; [self.view setBackgroundColor:[UIColor hwColor:@"#F5F7FA"]]; self.titleLabel.text = NSLocalizedString(@"my_set_no_File_backups",nil); [self drawAnyView]; rightTransferListButton = [[UIButton alloc] init]; [rightTransferListButton setImage:[UIImage imageNamed:@"icon_file_transfer"] forState:UIControlStateNormal]; [rightTransferListButton addTarget:self action:@selector(didiClikRightButGotoTransferListFun:) forControlEvents:UIControlEventTouchUpInside]; [self.navBarBGView addSubview:rightTransferListButton]; [rightTransferListButton mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(40); make.height.mas_equalTo(40); make.right.mas_equalTo(-15); make.centerY.mas_equalTo(self.titleLabel.mas_centerY); }]; rightRedView = [[UIView alloc] init]; rightRedView.backgroundColor = [UIColor hwColor:@"#DD4E4E" alpha:1.0]; [rightTransferListButton addSubview:rightRedView]; rightRedView.layer.cornerRadius = 7; rightRedView.hidden = YES; [rightRedView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(14); make.height.mas_equalTo(14); make.right.mas_equalTo(0); make.top.mas_equalTo(6); }]; [self setBackupsStateFun]; //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Backup"]; } - (void)drawAnyView { UIView*imageBackupsBgView = [[UIView alloc] init]; imageBackupsBgView.backgroundColor = [UIColor whiteColor]; imageBackupsBgView.layer.cornerRadius = 8; [self.view addSubview:imageBackupsBgView]; [imageBackupsBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.left.mas_equalTo(10); make.top.equalTo(self.navBarBGView.mas_bottom).offset(16.f); make.height.mas_equalTo(56); }]; UIImageView *backupsImageV = [[UIImageView alloc] init]; backupsImageV.image = [UIImage imageNamed:@"image_backups_icon"]; [imageBackupsBgView addSubview:backupsImageV]; [backupsImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(0); make.left.mas_equalTo(10); make.width.mas_equalTo(28); make.height.mas_equalTo(28); }]; UILabel *imageBackupsTitleLabel = [[UILabel alloc] init]; imageBackupsTitleLabel.text = NSLocalizedString(@"set_Privacy_title_image",nil) ; imageBackupsTitleLabel.font = [UIFont systemFontOfSize:14.0]; imageBackupsTitleLabel.textColor = [UIColor blackColor]; [imageBackupsBgView addSubview:imageBackupsTitleLabel]; [imageBackupsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(-10); make.left.mas_equalTo(backupsImageV.mas_right).offset(10); make.right.mas_equalTo(-(10+60+10)); make.height.mas_equalTo(20); }]; _imageBackupsLabel = [[UILabel alloc] init]; //_imageBackupsLabel.text = NSLocalizedString(@"set_Privacy_title_image_open",nil) ; _imageBackupsLabel.font = [UIFont systemFontOfSize:12.0]; _imageBackupsLabel.textColor = [UIColor hwColor:@"#6A6A6A" alpha:1.0]; [imageBackupsBgView addSubview:_imageBackupsLabel]; [_imageBackupsLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(10); make.left.mas_equalTo(backupsImageV.mas_right).offset(10); make.right.mas_equalTo(-(10+60+10)); make.height.mas_equalTo(20); }]; _imageBackupsButton = [[UIButton alloc] init]; _imageBackupsButton.backgroundColor = [UIColor hwColor:@"#DCF4FB" alpha:1.0]; _imageBackupsButton.tag = 7; [_imageBackupsButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; _imageBackupsButton.layer.cornerRadius = 12.0; _imageBackupsButton.layer.masksToBounds = YES; [_imageBackupsButton setTitle:NSLocalizedString(@"common_open",nil) forState:UIControlStateNormal]; [_imageBackupsButton setTitle:NSLocalizedString(@"common_close",nil) forState:UIControlStateSelected]; [_imageBackupsButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal]; _imageBackupsButton.titleLabel.font = [UIFont systemFontOfSize:12.0]; [imageBackupsBgView addSubview:_imageBackupsButton]; [_imageBackupsButton mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.centerY.mas_equalTo(0); make.width.mas_equalTo(60); make.height.mas_equalTo(24); }]; } - (void)closeImageBackupsFun { [HWDataManager setBoolWithKey:stringKeyAddSn(Const_photo_backups_state) value:NO]; [self setBackupsStateFun]; //处理相册备份 //[[backupsFileManager shareInstance] suspendBackupsFileFun]; [[nasBackupsManager shareInstance] suspendBackupsFileFun]; //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Album_Backup_off"]; } - (void)openImageBackupsFun { BOOL isCanUseCellular = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_canUse_Cellular_all)]; if(!isCanUseCellular){//不允许流量上传 // if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN){ mainBlock(^{ [[iToast makeText:NSLocalizedString(@"File_Transfer_By_Cellular_tip",nil)] show]; }); return; } } [self showBackupsReadTipFun]; [HWDataManager setBoolWithKey:stringKeyAddSn(Const_photo_backups_state) value:YES]; [self setBackupsStateFun]; [[iToast makeText:NSLocalizedString(@"set_Privacy_title_image_open",nil)] show]; //处理相册备份 //[[backupsFileManager shareInstance] handlePhotosBackupsFun]; [[nasBackupsManager shareInstance] handlePhotosBackupsFun]; //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Album_Backup_on"]; } - (void)showBackupsReadTipFun { BOOL didReadbackupsTipType = [HWDataManager getBoolWithKey:Const_file_backups_need_read]; if(didReadbackupsTipType){//阅读过 return; } backupsOptionTipView * backupsOptionTipV = [[backupsOptionTipView alloc] init]; [ksharedAppDelegate.window addSubview:backupsOptionTipV]; [backupsOptionTipV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0.0); make.right.mas_equalTo(0.0); make.top.mas_equalTo(0.0); make.bottom.mas_equalTo(0.0); }]; KWeakSelf backupsOptionTipV.didClickButtonFun = ^(NSInteger tag) { if(tag==10){ [weakSelf gotoFileTransfeSetVCFun]; } }; // NSString*msgStr1 = NSLocalizedString(@"backups_need_read_msg",nil); // NSString*msgStr2 = NSLocalizedString(@"backups_need_read_msg2",nil); // // NSString *totalMsgstr = [[NSString alloc] initWithFormat:@"%@%@",msgStr1,msgStr2]; // // //KWeakSelf // /*弹窗提示恢复出厂*/ // ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:@"" // msg:totalMsgstr // imageStr:@"" // cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil) // okTitle:@"" // isOkBtnHighlight:NO // didClickOk:^{ // // } didClickCancel:^{ // [HWDataManager setBoolWithKey:Const_file_backups_need_read value:YES]; // }]; // // nextVC.modalPresentationStyle = UIModalPresentationCustom; // [nextVC setMsgTextAlignment:NSTextAlignmentLeft]; // // [[iTools appRootViewController] presentViewController:nextVC animated:YES completion:^{ // nextVC.view.superview.backgroundColor = [UIColor clearColor]; // }]; } #pragma mark 调整传输设置 - (void)gotoFileTransfeSetVCFun { if(!ksharedAppDelegate.isWebSockLinkOKAginType){ [[iToast makeText:NSLocalizedString(@"check_could_phone_state",nil)] show]; return; } fileTransfeSetViewController *nextVC = [fileTransfeSetViewController new]; [self.navigationController pushViewController:nextVC animated:YES]; } - (void)setBackupsStateFun { BOOL haveOpenBackups = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_photo_backups_state)]; _imageBackupsButton.selected = haveOpenBackups; if(haveOpenBackups){ _imageBackupsLabel.text = NSLocalizedString(@"set_Privacy_title_image_open",nil) ; } else { _imageBackupsLabel.text = NSLocalizedString(@"set_Privacy_title_image_close",nil) ; } } #pragma mark 按钮点击事件 - (void)didClickButFun:(UIButton*)but { //NSInteger tag = but.tag; //HLog(@"xxxx:%ld",tag) BOOL haveOpenBackups = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_photo_backups_state)]; if(!haveOpenBackups){ if(ksharedAppDelegate.DisabledFileTransferType){ if(ksharedAppDelegate.isImageNewFor130){ [[iToast makeText:NSLocalizedString(@"File_Transfer_Disable_tip",nil)] show]; } else{ [[iToast makeText:NSLocalizedString(@"File_Transfer_Disable_tip2",nil)] show]; } return; } if(!ksharedAppDelegate.isWebSockLinkOKAginType){ [[iToast makeText:NSLocalizedString(@"check_could_phone_state",nil)] show]; return; } //相册权限 if (![[TZImageManager manager] authorizationStatusAuthorized]){ [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { if(status == PHAuthorizationStatusAuthorized){ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self openImageBackupsFun]; }); } }]; } else{ [self openImageBackupsFun]; } return; } else{ KWeakSelf /*弹窗提示关闭备份*/ ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_backups_set_close_title",nil) msg:NSLocalizedString(@"File_backups_set_close_tip",nil) imageStr:nil cancelTitle:NSLocalizedString(@"other_cancel",nil) okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES didClickOk:^{ [weakSelf closeImageBackupsFun]; } didClickCancel:^{ }]; nextVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:nextVC animated:YES completion:^{ nextVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } } - (void)checkFileTransferTask {//有个偶现的闪退在BGFMDB [[nasUploadFileManager shareInstance] checkHadUploadTaskWithComplete:^(BOOL isSuccess) { self->hadUploadTaskType = isSuccess; [self setRightButtonRedTypeFun]; }]; KWeakSelf dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[nasDownloadFileManager shareInstance] checkHadDownloadTaskWithComplete:^(BOOL isSuccess) { self->hadDownloadTaskType = isSuccess; [weakSelf setRightButtonRedTypeFun]; }]; }); } - (void)setRightButtonRedTypeFun { mainBlock(^{ if(self->hadUploadTaskType || self->hadDownloadTaskType){ self->rightRedView.hidden = NO; } else{ self->rightRedView.hidden = YES; } }); } - (void)didiClikRightButGotoTransferListFun:(UIButton*)but { uploadFileRecordViewController *vc = [uploadFileRecordViewController new]; [self.navigationController pushViewController:vc animated:YES]; } - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; [self checkFileTransferTask]; } @end