fileTransferPathCheckViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. //
  2. // fileTransferPathCheckViewController.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/12/28.
  6. //
  7. #import "fileTransferPathCheckViewController.h"
  8. #import "fileTransferPathCheckTableViewCell.h"
  9. #import "filePathCreatPopView.h"
  10. #import "IQKeyboardManager.h"
  11. #import "couldPhoneFolderListModel.h"
  12. @interface fileTransferPathCheckViewController ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic, strong) UITableView *tableView;
  14. @property (nonatomic, strong) NSMutableArray * folderListArr;
  15. @property (nonatomic,assign) NSInteger selectIndex;
  16. @property(nonatomic,copy)NSString* createFolderNameStr;
  17. @end
  18. @implementation fileTransferPathCheckViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. [self.toolBar setHidden:YES];
  23. [self.navigationBar setHidden:YES];
  24. [self.navBarBGView setHidden:NO];
  25. //[self.titleLabel setText:NSLocalizedString(@"File_upload_path_check",nil)];
  26. [self.view setBackgroundColor:HWF5F7FAColor];
  27. _folderListArr = [NSMutableArray new];
  28. _selectIndex = -1;
  29. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(createFolderDoneNotFun:) name:createFolderDoneNotification object:nil];
  30. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getFolderListDoneNotFun:) name:getFolderListDoneNotification object:nil];
  31. [self drawAnyView];
  32. [self setupKeyboardManager];
  33. [self getFolderListFun];
  34. }
  35. - (void)getFolderListFun
  36. {
  37. [[webSocketManager shareInstance] getBackupFolderListFun];
  38. }
  39. - (void)drawAnyView{
  40. UIButton* rightButton = [[UIButton alloc] init];
  41. [rightButton setTitle:NSLocalizedString(@"File_upload_path_new",nil) forState:UIControlStateNormal];
  42. [rightButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  43. rightButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
  44. rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  45. [rightButton addTarget:self action:@selector(didiClikRightButFun:) forControlEvents:UIControlEventTouchUpInside];
  46. [self.navBarBGView addSubview:rightButton];
  47. [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.width.mas_equalTo(120);
  49. make.height.mas_equalTo(40);
  50. make.right.mas_equalTo(-15);
  51. make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  52. }];
  53. [self.view addSubview:self.tableView];
  54. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.mas_equalTo(0);
  56. make.right.mas_equalTo(0);
  57. make.bottom.mas_equalTo(-(safeArea -20));
  58. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  59. }];
  60. }
  61. - (void)viewWillAppear:(BOOL)animated
  62. {
  63. [super viewWillAppear:animated];
  64. IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
  65. keyboardManager.enable = YES;
  66. if(_curType == 2){
  67. [self.titleLabel setText:NSLocalizedString(@"File_upload_path_new_check_title",nil)];
  68. }
  69. else if(_curType == 3){
  70. [self.titleLabel setText:NSLocalizedString(@"File_save_to_box_check_title",nil)];
  71. }
  72. else{
  73. [self.titleLabel setText:NSLocalizedString(@"File_upload_path_check",nil)];
  74. }
  75. }
  76. - (void)viewWillDisappear:(BOOL)animated
  77. {
  78. [super viewWillDisappear:animated];
  79. IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
  80. keyboardManager.enable = NO;
  81. }
  82. - (void)setupKeyboardManager {
  83. IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
  84. keyboardManager.enable = YES;
  85. keyboardManager.shouldResignOnTouchOutside = YES;
  86. keyboardManager.shouldShowToolbarPlaceholder = NO;
  87. keyboardManager.enableAutoToolbar = NO;
  88. }
  89. #pragma mark - 懒加载
  90. - (UITableView *)tableView{
  91. if (!_tableView) {
  92. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain];
  93. _tableView.delegate = self;
  94. _tableView.dataSource = self;
  95. _tableView.showsVerticalScrollIndicator = NO;
  96. _tableView.showsHorizontalScrollIndicator = NO;
  97. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  98. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  99. [_tableView setSeparatorColor:[UIColor clearColor]];
  100. [_tableView setBackgroundColor:[UIColor clearColor]];
  101. [_tableView setTableFooterView:[UIView new]];
  102. [_tableView setBounces:YES];
  103. // _tableView.layer.cornerRadius = 8;
  104. // _tableView.layer.masksToBounds = YES;
  105. if (@available(iOS 15.0, *)) {
  106. _tableView.sectionHeaderTopPadding = 0;
  107. }
  108. }
  109. return _tableView;
  110. }
  111. #pragma mark - 列表委托
  112. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  113. return 1;
  114. }
  115. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  116. return _folderListArr.count;
  117. }
  118. - (fileTransferPathCheckTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  119. __block NSInteger row = indexPath.row;
  120. static NSString *identifier = @"fileTransferPathCheckTableViewCell";
  121. fileTransferPathCheckTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  122. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  123. if (!cell){
  124. cell = [[fileTransferPathCheckTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  125. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  126. [cell setBackgroundColor:[UIColor clearColor]];
  127. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  128. [cell.bgViewLayer removeFromSuperlayer];
  129. [cell.titleLabel2 setHidden:YES];
  130. [cell.rightImage setHidden:YES];
  131. [cell.lineView setHidden:NO];
  132. [cell.checkButton setHidden:NO];
  133. }
  134. if(row < _folderListArr.count){
  135. NSString *name = _folderListArr[row];
  136. name = [iTools changePathToShowPathBy:name];
  137. cell.titleLabel.text = name;
  138. if(row == _selectIndex){
  139. cell.checkButton.selected = YES;
  140. }
  141. else{
  142. cell.checkButton.selected = NO;
  143. }
  144. }
  145. if (row == 0){
  146. /*上圆角*/
  147. //设置部分圆角 贝塞尔曲线
  148. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 90)
  149. byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
  150. cornerRadii:CGSizeMake(8, 8)];
  151. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  152. maskLayer.frame = cell.cellBgView.bounds;
  153. maskLayer.path = maskPath.CGPath;
  154. cell.bgViewLayer = maskLayer;
  155. cell.cellBgView.layer.mask = cell.bgViewLayer;
  156. }//else
  157. if (row == _folderListArr.count -1){
  158. //[cell.titleLabel setText:NSLocalizedString(@"File_Transfer_set_battery_level",nil)];
  159. //cell.titleLabel.text = @"云机名称/我的空间/XYJ";
  160. /*下圆角*/
  161. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 90)
  162. byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
  163. cornerRadii:CGSizeMake(8, 8)];
  164. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  165. maskLayer.frame = cell.cellBgView.bounds;
  166. maskLayer.path = maskPath.CGPath;
  167. cell.bgViewLayer = maskLayer;
  168. cell.cellBgView.layer.mask = cell.bgViewLayer;
  169. [cell.lineView setHidden:YES];
  170. }
  171. KWeakSelf
  172. cell.didClickSwitch = ^(BOOL SwitchOn) {
  173. [weakSelf userCheckFolderPathByRow:row];
  174. };
  175. return cell;
  176. }
  177. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  178. return 90;
  179. }
  180. - (void)didiClikRightButFun:(UIButton*)but
  181. {
  182. filePathCreatPopView * filePathCreatPopV = [[filePathCreatPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  183. if(ksharedAppDelegate.cloudPhoneExtraFileListMod){
  184. filePathCreatPopV.outSizeArr = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  185. }
  186. else{
  187. filePathCreatPopV.outSizeArr = @[];
  188. }
  189. [self.view addSubview:filePathCreatPopV];
  190. filePathCreatPopV.curType = _curType;
  191. KWeakSelf
  192. filePathCreatPopV.didClickOkBut = ^(NSString * _Nonnull folderName, NSString * _Nonnull DiskPathStr) {
  193. [weakSelf didGetFolderName:folderName withDiskPath:DiskPathStr];
  194. };
  195. }
  196. #pragma mark 用户选择默认上次文件夹
  197. - (void)userCheckFolderPathByRow:(NSInteger)row
  198. {
  199. _selectIndex = row;
  200. NSString *cutPath = _folderListArr[row];
  201. if(_curType == 2){
  202. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_backups_default_path) value:cutPath];
  203. }
  204. else if(_curType == 1){
  205. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_upload_default_path) value:cutPath];
  206. }
  207. else if(_curType == 3){
  208. [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:cutPath];
  209. }
  210. [[iToast makeText:NSLocalizedString(@"save_path_change_suc_tip",nil)] show];
  211. if(_didChangeSavePathFun){
  212. _didChangeSavePathFun();
  213. }
  214. if(_curType == 2){
  215. //相册自动备份
  216. [[backupsFileManager shareInstance] reBackupsFileFun];
  217. }
  218. [self.tableView reloadData];
  219. }
  220. #pragma mark
  221. - (void)didGetFolderName:(NSString*)folderName withDiskPath:(NSString*)diskPathStr
  222. {
  223. _createFolderNameStr = folderName;
  224. NSString *curbackupsDefaultPath = [[NSString alloc] initWithFormat:@"%@/%@",diskPathStr,_createFolderNameStr];
  225. NSString *lastStr = [diskPathStr substringFromIndex:diskPathStr.length -1];
  226. if([lastStr isEqualToString:@"/"]){
  227. curbackupsDefaultPath = [[NSString alloc] initWithFormat:@"%@%@",diskPathStr,_createFolderNameStr];
  228. }
  229. if(_curType == 2){
  230. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_backups_default_path) value:curbackupsDefaultPath];
  231. }
  232. else if(_curType == 1){
  233. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_upload_default_path) value:curbackupsDefaultPath];
  234. }
  235. else if(_curType == 3){
  236. [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:curbackupsDefaultPath];
  237. }
  238. [[webSocketManager shareInstance] createBackupsFolderBy:curbackupsDefaultPath];
  239. }
  240. - (void)createFolderDoneNotFun:(NSNotification *)notification
  241. {
  242. NSNumber *stateNumber = [notification object];
  243. NSString * tipStr = @"";
  244. if(stateNumber.integerValue == 0){
  245. tipStr = NSLocalizedString(@"File_upload_path_new_suc",nil);
  246. if(_didChangeSavePathFun){
  247. _didChangeSavePathFun();
  248. }
  249. if(_curType == 2){
  250. //相册自动备份
  251. [[backupsFileManager shareInstance] reBackupsFileFun];
  252. }
  253. }
  254. else if(stateNumber.integerValue == 2 ){
  255. tipStr = NSLocalizedString(@"File_upload_path_new_save",nil);
  256. }
  257. else{
  258. tipStr = NSLocalizedString(@"File_upload_path_new_fail",nil);
  259. }
  260. [[iToast makeText:tipStr] show];
  261. [self getFolderListFun];
  262. }
  263. - (void)getFolderListDoneNotFun:(NSNotification *)notification
  264. {
  265. NSDictionary *dataDict = [notification object];
  266. couldPhoneFolderListModel *model = [[couldPhoneFolderListModel alloc] initWithDictionary:dataDict error:nil];
  267. if(model){
  268. [_folderListArr removeAllObjects];
  269. [_folderListArr addObjectsFromArray:model.data];
  270. NSString * backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_backups_default_path)];
  271. if(_curType == 1){
  272. backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)];
  273. }
  274. else if(_curType == 3){
  275. backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_box_save_default_path)];
  276. }
  277. NSString *lastbackupsStr = [backupsDefaultPath substringFromIndex:backupsDefaultPath.length -1];
  278. BOOL needAddHadDefaultPath = YES;
  279. for (int i=0; i<_folderListArr.count; i++) {
  280. NSString * curPathStr = _folderListArr[i];
  281. NSString *lastStr = [curPathStr substringFromIndex:curPathStr.length -1];
  282. if([lastStr isEqualToString:@"/"]
  283. && ![lastbackupsStr isEqualToString:@"/"]){
  284. curPathStr = [curPathStr substringToIndex:curPathStr.length -1];
  285. }
  286. if([curPathStr isEqualToString:@"sdcard/Download/"]){
  287. curPathStr = @"/sdcard/Download/";
  288. }
  289. if([curPathStr isEqualToString:backupsDefaultPath]){
  290. needAddHadDefaultPath = NO;
  291. _selectIndex = i;
  292. break;
  293. }
  294. }
  295. // if(needAddHadDefaultPath){
  296. // [_folderListArr insertObject:backupsDefaultPath atIndex:0];
  297. // _selectIndex = 0;
  298. // }
  299. }
  300. [self.tableView reloadData];
  301. }
  302. @end