// // fileTransferPathCheckViewController.m // 隐私保护 // // Created by xd h on 2023/12/28. // #import "fileTransferPathCheckViewController.h" #import "fileTransferPathCheckTableViewCell.h" #import "filePathCreatPopView.h" #import "IQKeyboardManager.h" #import "couldPhoneFolderListModel.h" #import "backupPathListModel.h" @interface fileTransferPathCheckViewController () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSMutableArray * folderListArr; @property (nonatomic,assign) NSInteger selectIndex; @property(nonatomic,copy)NSString* createFolderNameStr; @end @implementation fileTransferPathCheckViewController - (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.titleLabel setText:NSLocalizedString(@"File_upload_path_check",nil)]; [self.view setBackgroundColor:HWF5F7FAColor]; _folderListArr = [NSMutableArray new]; _selectIndex = -1; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(createFolderDoneNotFun:) name:createFolderDoneNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getFolderListDoneNotFun:) name:getFolderListDoneNotification object:nil]; [self drawAnyView]; [self setupKeyboardManager]; [self getFolderListFun]; } - (void)getFolderListFun { //原来走通道 //[[webRtcManager shareManager] getBackupFolderListFun]; //改走frpc方案 [self getBackupPathListFun]; } #pragma mark 改走frpc方案 取备份备份文件夹列表 - (void)getBackupPathListFun { NSMutableDictionary*paraDict = [NSMutableDictionary new]; KWeakSelf [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"backupPath" Parameters:paraDict success:^(id _Nonnull responseObject) { backupPathListModel *model = [[backupPathListModel alloc] initWithDictionary:responseObject error:nil]; if(model && model.status == 0){ [weakSelf getFolderListDoneWith:model]; } else{ } } failure:^(NSError * _Nonnull error) { }]; } - (void)drawAnyView{ UIButton* rightButton = [[UIButton alloc] init]; [rightButton setTitle:NSLocalizedString(@"File_upload_path_new",nil) forState:UIControlStateNormal]; [rightButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal]; rightButton.titleLabel.font = [UIFont systemFontOfSize:18.0]; rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; [rightButton addTarget:self action:@selector(didiClikRightButFun:) forControlEvents:UIControlEventTouchUpInside]; [self.navBarBGView addSubview:rightButton]; [rightButton mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(120); make.height.mas_equalTo(40); make.right.mas_equalTo(-15); make.centerY.mas_equalTo(self.titleLabel.mas_centerY); }]; [self.view addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(-(safeArea -20)); make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f); }]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager]; keyboardManager.enable = YES; if(_curType == 2){ [self.titleLabel setText:NSLocalizedString(@"File_upload_path_new_check_title",nil)]; } else if(_curType == 3){ [self.titleLabel setText:NSLocalizedString(@"File_save_to_box_check_title",nil)]; } else{ [self.titleLabel setText:NSLocalizedString(@"File_upload_path_check",nil)]; } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager]; keyboardManager.enable = NO; } - (void)setupKeyboardManager { IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager]; keyboardManager.enable = YES; keyboardManager.shouldResignOnTouchOutside = YES; keyboardManager.shouldShowToolbarPlaceholder = NO; keyboardManager.enableAutoToolbar = NO; } #pragma mark - 懒加载 - (UITableView *)tableView{ if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.showsVerticalScrollIndicator = NO; _tableView.showsHorizontalScrollIndicator = NO; // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0); [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)]; [_tableView setSeparatorColor:[UIColor clearColor]]; [_tableView setBackgroundColor:[UIColor clearColor]]; [_tableView setTableFooterView:[UIView new]]; [_tableView setBounces:YES]; // _tableView.layer.cornerRadius = 8; // _tableView.layer.masksToBounds = YES; if (@available(iOS 15.0, *)) { _tableView.sectionHeaderTopPadding = 0; } } return _tableView; } #pragma mark - 列表委托 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _folderListArr.count; } - (fileTransferPathCheckTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ __block NSInteger row = indexPath.row; static NSString *identifier = @"fileTransferPathCheckTableViewCell"; fileTransferPathCheckTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; if (!cell){ cell = [[fileTransferPathCheckTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; [cell setBackgroundColor:[UIColor clearColor]]; [cell setAccessoryType:(UITableViewCellAccessoryNone)]; [cell.bgViewLayer removeFromSuperlayer]; [cell.titleLabel2 setHidden:YES]; [cell.rightImage setHidden:YES]; [cell.lineView setHidden:NO]; [cell.checkButton setHidden:NO]; } if(row < _folderListArr.count){ NSString *name = _folderListArr[row]; name = [iTools changePathToShowPathBy:name]; cell.titleLabel.text = name; if(row == _selectIndex){ cell.checkButton.selected = YES; } else{ cell.checkButton.selected = NO; } } if(_folderListArr.count == 1){ //设置部分圆角 贝塞尔曲线 UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 90) byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(8, 8)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = cell.cellBgView.bounds; maskLayer.path = maskPath.CGPath; cell.bgViewLayer = maskLayer; cell.cellBgView.layer.mask = cell.bgViewLayer; } else{ if (row == 0){ /*上圆角*/ //设置部分圆角 贝塞尔曲线 UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 90) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = cell.cellBgView.bounds; maskLayer.path = maskPath.CGPath; cell.bgViewLayer = maskLayer; cell.cellBgView.layer.mask = cell.bgViewLayer; }//else if (row == _folderListArr.count -1){ //[cell.titleLabel setText:NSLocalizedString(@"File_Transfer_set_battery_level",nil)]; //cell.titleLabel.text = @"云机名称/我的空间/XYJ"; /*下圆角*/ UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 90) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = cell.cellBgView.bounds; maskLayer.path = maskPath.CGPath; cell.bgViewLayer = maskLayer; cell.cellBgView.layer.mask = cell.bgViewLayer; [cell.lineView setHidden:YES]; } } KWeakSelf cell.didClickSwitch = ^(BOOL SwitchOn) { [weakSelf userCheckFolderPathByRow:row]; }; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 90; } - (void)didiClikRightButFun:(UIButton*)but { filePathCreatPopView * filePathCreatPopV = [[filePathCreatPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)]; if(ksharedAppDelegate.cloudPhoneExtraFileListMod){ filePathCreatPopV.outSizeArr = ksharedAppDelegate.cloudPhoneExtraFileListMod.data; } else{ filePathCreatPopV.outSizeArr = @[]; } [self.view addSubview:filePathCreatPopV]; filePathCreatPopV.curType = _curType; KWeakSelf filePathCreatPopV.didClickOkBut = ^(NSString * _Nonnull folderName, NSString * _Nonnull DiskPathStr) { [weakSelf didGetFolderName:folderName withDiskPath:DiskPathStr]; }; } #pragma mark 用户选择默认上次文件夹 - (void)userCheckFolderPathByRow:(NSInteger)row { _selectIndex = row; NSString *cutPath = _folderListArr[row]; if(_curType == 2){ [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_backups_default_path) value:cutPath]; } else if(_curType == 1){ [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_upload_default_path) value:cutPath]; } else if(_curType == 3){ [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:cutPath]; } [[iToast makeText:NSLocalizedString(@"save_path_change_suc_tip",nil)] show]; if(_didChangeSavePathFun){ _didChangeSavePathFun(); } if(_curType == 2){ //相册自动备份 //[[backupsFileManager shareInstance] reBackupsFileFun]; [[nasBackupsManager shareInstance] reBackupsFileFun]; } [self.tableView reloadData]; } #pragma mark 信令通道创建 文件夹 - (void)didGetFolderName:(NSString*)folderName withDiskPath:(NSString*)diskPathStr { _createFolderNameStr = folderName; NSString *curbackupsDefaultPath = [[NSString alloc] initWithFormat:@"%@/%@",diskPathStr,_createFolderNameStr]; NSString *lastStr = [diskPathStr substringFromIndex:diskPathStr.length -1]; if([lastStr isEqualToString:@"/"]){ curbackupsDefaultPath = [[NSString alloc] initWithFormat:@"%@%@",diskPathStr,_createFolderNameStr]; } if(_curType == 2){ [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_backups_default_path) value:curbackupsDefaultPath]; } else if(_curType == 1){ [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_upload_default_path) value:curbackupsDefaultPath]; } else if(_curType == 3){ [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:curbackupsDefaultPath]; } //[[webRtcManager shareManager] createBackupsFolderBy:curbackupsDefaultPath]; [self mkdirPathFunBy:curbackupsDefaultPath]; } #pragma mark frp创建 文件夹 - (void)mkdirPathFunBy:(NSString*)path { NSMutableDictionary*paraDict = [NSMutableDictionary new]; if(path){ [paraDict setValue:path forKeyPath:@"path"]; } KWeakSelf [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"mkdir" Parameters:paraDict success:^(id _Nonnull responseObject) { SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil]; NSString * tipStr = @""; if(model && model.status == 0){ tipStr = NSLocalizedString(@"File_upload_path_new_suc",nil); if(self->_didChangeSavePathFun){ self->_didChangeSavePathFun(); } if(self->_curType == 2){ //相册自动备份 //[[backupsFileManager shareInstance] reBackupsFileFun]; [[nasBackupsManager shareInstance] reBackupsFileFun]; } } else if (model.status == 2){ tipStr = NSLocalizedString(@"File_upload_path_new_save",nil); } else{ tipStr = NSLocalizedString(@"File_upload_path_new_fail",nil); } mainBlock(^{ [[iToast makeText:tipStr] show]; }); [weakSelf getFolderListFun]; } failure:^(NSError * _Nonnull error) { }]; } - (void)createFolderDoneNotFun:(NSNotification *)notification { NSNumber *stateNumber = [notification object]; NSString * tipStr = @""; if(stateNumber.integerValue == 0){ tipStr = NSLocalizedString(@"File_upload_path_new_suc",nil); if(_didChangeSavePathFun){ _didChangeSavePathFun(); } if(_curType == 2){ //相册自动备份 //[[backupsFileManager shareInstance] reBackupsFileFun]; [[nasBackupsManager shareInstance] reBackupsFileFun]; } } else if(stateNumber.integerValue == 2 ){ tipStr = NSLocalizedString(@"File_upload_path_new_save",nil); } else{ tipStr = NSLocalizedString(@"File_upload_path_new_fail",nil); } mainBlock(^{ [[iToast makeText:tipStr] show]; }); [self getFolderListFun]; } #pragma mark 信令通道 或者webrtc通道获取备份文件夹列表的响应 弃用!!!! - (void)getFolderListDoneNotFun:(NSNotification *)notification { NSDictionary *dataDict = [notification object]; couldPhoneFolderListModel *model = [[couldPhoneFolderListModel alloc] initWithDictionary:dataDict error:nil]; if(model){ [_folderListArr removeAllObjects]; [_folderListArr addObjectsFromArray:model.data]; NSString * backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_backups_default_path)]; if(_curType == 1){ backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)]; } else if(_curType == 3){ backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_box_save_default_path)]; } NSString *lastbackupsStr = [backupsDefaultPath substringFromIndex:backupsDefaultPath.length -1]; BOOL needAddHadDefaultPath = YES; for (int i=0; i<_folderListArr.count; i++) { NSString * curPathStr = _folderListArr[i]; NSString *lastStr = [curPathStr substringFromIndex:curPathStr.length -1]; if([lastStr isEqualToString:@"/"] && ![lastbackupsStr isEqualToString:@"/"]){ curPathStr = [curPathStr substringToIndex:curPathStr.length -1]; } if([curPathStr isEqualToString:@"sdcard/Download/"]){ curPathStr = @"/sdcard/Download/"; } if([curPathStr isEqualToString:backupsDefaultPath]){ needAddHadDefaultPath = NO; _selectIndex = i; break; } } // if(needAddHadDefaultPath){ // [_folderListArr insertObject:backupsDefaultPath atIndex:0]; // _selectIndex = 0; // } } KWeakSelf mainBlock(^{ [weakSelf.tableView reloadData]; }); } #pragma mark frp通道获取备份文件夹列表的响应 正在使用!!!! - (void)getFolderListDoneWith:(backupPathListModel*)model { if(model){ [_folderListArr removeAllObjects]; [_folderListArr addObjectsFromArray:model.data.path]; NSString * backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_backups_default_path)]; if(_curType == 1){ backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)]; } else if(_curType == 3){ backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_box_save_default_path)]; } NSString *lastbackupsStr = [backupsDefaultPath substringFromIndex:backupsDefaultPath.length -1]; BOOL needAddHadDefaultPath = YES; for (int i=0; i<_folderListArr.count; i++) { NSString * curPathStr = _folderListArr[i]; NSString *lastStr = [curPathStr substringFromIndex:curPathStr.length -1]; if([lastStr isEqualToString:@"/"] && ![lastbackupsStr isEqualToString:@"/"]){ curPathStr = [curPathStr substringToIndex:curPathStr.length -1]; } if([curPathStr isEqualToString:@"sdcard/Download/"]){ curPathStr = @"/sdcard/Download/"; } if([curPathStr isEqualToString:backupsDefaultPath]){ needAddHadDefaultPath = NO; _selectIndex = i; break; } } // if(needAddHadDefaultPath){ // [_folderListArr insertObject:backupsDefaultPath atIndex:0]; // _selectIndex = 0; // } } KWeakSelf mainBlock(^{ [weakSelf.tableView reloadData]; }); } @end