fileTransferPathCheckViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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(_folderListArr.count == 1){
  146. //设置部分圆角 贝塞尔曲线
  147. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 90)
  148. byRoundingCorners:UIRectCornerAllCorners
  149. cornerRadii:CGSizeMake(8, 8)];
  150. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  151. maskLayer.frame = cell.cellBgView.bounds;
  152. maskLayer.path = maskPath.CGPath;
  153. cell.bgViewLayer = maskLayer;
  154. cell.cellBgView.layer.mask = cell.bgViewLayer;
  155. }
  156. else{
  157. if (row == 0){
  158. /*上圆角*/
  159. //设置部分圆角 贝塞尔曲线
  160. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 90)
  161. byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
  162. cornerRadii:CGSizeMake(8, 8)];
  163. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  164. maskLayer.frame = cell.cellBgView.bounds;
  165. maskLayer.path = maskPath.CGPath;
  166. cell.bgViewLayer = maskLayer;
  167. cell.cellBgView.layer.mask = cell.bgViewLayer;
  168. }//else
  169. if (row == _folderListArr.count -1){
  170. //[cell.titleLabel setText:NSLocalizedString(@"File_Transfer_set_battery_level",nil)];
  171. //cell.titleLabel.text = @"云机名称/我的空间/XYJ";
  172. /*下圆角*/
  173. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 90)
  174. byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
  175. cornerRadii:CGSizeMake(8, 8)];
  176. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  177. maskLayer.frame = cell.cellBgView.bounds;
  178. maskLayer.path = maskPath.CGPath;
  179. cell.bgViewLayer = maskLayer;
  180. cell.cellBgView.layer.mask = cell.bgViewLayer;
  181. [cell.lineView setHidden:YES];
  182. }
  183. }
  184. KWeakSelf
  185. cell.didClickSwitch = ^(BOOL SwitchOn) {
  186. [weakSelf userCheckFolderPathByRow:row];
  187. };
  188. return cell;
  189. }
  190. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  191. return 90;
  192. }
  193. - (void)didiClikRightButFun:(UIButton*)but
  194. {
  195. filePathCreatPopView * filePathCreatPopV = [[filePathCreatPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  196. if(ksharedAppDelegate.cloudPhoneExtraFileListMod){
  197. filePathCreatPopV.outSizeArr = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  198. }
  199. else{
  200. filePathCreatPopV.outSizeArr = @[];
  201. }
  202. [self.view addSubview:filePathCreatPopV];
  203. filePathCreatPopV.curType = _curType;
  204. KWeakSelf
  205. filePathCreatPopV.didClickOkBut = ^(NSString * _Nonnull folderName, NSString * _Nonnull DiskPathStr) {
  206. [weakSelf didGetFolderName:folderName withDiskPath:DiskPathStr];
  207. };
  208. }
  209. #pragma mark 用户选择默认上次文件夹
  210. - (void)userCheckFolderPathByRow:(NSInteger)row
  211. {
  212. _selectIndex = row;
  213. NSString *cutPath = _folderListArr[row];
  214. if(_curType == 2){
  215. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_backups_default_path) value:cutPath];
  216. }
  217. else if(_curType == 1){
  218. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_upload_default_path) value:cutPath];
  219. }
  220. else if(_curType == 3){
  221. [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:cutPath];
  222. }
  223. [[iToast makeText:NSLocalizedString(@"save_path_change_suc_tip",nil)] show];
  224. if(_didChangeSavePathFun){
  225. _didChangeSavePathFun();
  226. }
  227. if(_curType == 2){
  228. //相册自动备份
  229. [[backupsFileManager shareInstance] reBackupsFileFun];
  230. [[nasBackupsManager shareInstance] reBackupsFileFun];
  231. }
  232. [self.tableView reloadData];
  233. }
  234. #pragma mark
  235. - (void)didGetFolderName:(NSString*)folderName withDiskPath:(NSString*)diskPathStr
  236. {
  237. _createFolderNameStr = folderName;
  238. NSString *curbackupsDefaultPath = [[NSString alloc] initWithFormat:@"%@/%@",diskPathStr,_createFolderNameStr];
  239. NSString *lastStr = [diskPathStr substringFromIndex:diskPathStr.length -1];
  240. if([lastStr isEqualToString:@"/"]){
  241. curbackupsDefaultPath = [[NSString alloc] initWithFormat:@"%@%@",diskPathStr,_createFolderNameStr];
  242. }
  243. if(_curType == 2){
  244. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_backups_default_path) value:curbackupsDefaultPath];
  245. }
  246. else if(_curType == 1){
  247. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_upload_default_path) value:curbackupsDefaultPath];
  248. }
  249. else if(_curType == 3){
  250. [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:curbackupsDefaultPath];
  251. }
  252. [[webSocketManager shareInstance] createBackupsFolderBy:curbackupsDefaultPath];
  253. }
  254. - (void)createFolderDoneNotFun:(NSNotification *)notification
  255. {
  256. NSNumber *stateNumber = [notification object];
  257. NSString * tipStr = @"";
  258. if(stateNumber.integerValue == 0){
  259. tipStr = NSLocalizedString(@"File_upload_path_new_suc",nil);
  260. if(_didChangeSavePathFun){
  261. _didChangeSavePathFun();
  262. }
  263. if(_curType == 2){
  264. //相册自动备份
  265. //[[backupsFileManager shareInstance] reBackupsFileFun];
  266. [[nasBackupsManager shareInstance] reBackupsFileFun];
  267. }
  268. }
  269. else if(stateNumber.integerValue == 2 ){
  270. tipStr = NSLocalizedString(@"File_upload_path_new_save",nil);
  271. }
  272. else{
  273. tipStr = NSLocalizedString(@"File_upload_path_new_fail",nil);
  274. }
  275. [[iToast makeText:tipStr] show];
  276. [self getFolderListFun];
  277. }
  278. - (void)getFolderListDoneNotFun:(NSNotification *)notification
  279. {
  280. NSDictionary *dataDict = [notification object];
  281. couldPhoneFolderListModel *model = [[couldPhoneFolderListModel alloc] initWithDictionary:dataDict error:nil];
  282. if(model){
  283. [_folderListArr removeAllObjects];
  284. [_folderListArr addObjectsFromArray:model.data];
  285. NSString * backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_backups_default_path)];
  286. if(_curType == 1){
  287. backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)];
  288. }
  289. else if(_curType == 3){
  290. backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_box_save_default_path)];
  291. }
  292. NSString *lastbackupsStr = [backupsDefaultPath substringFromIndex:backupsDefaultPath.length -1];
  293. BOOL needAddHadDefaultPath = YES;
  294. for (int i=0; i<_folderListArr.count; i++) {
  295. NSString * curPathStr = _folderListArr[i];
  296. NSString *lastStr = [curPathStr substringFromIndex:curPathStr.length -1];
  297. if([lastStr isEqualToString:@"/"]
  298. && ![lastbackupsStr isEqualToString:@"/"]){
  299. curPathStr = [curPathStr substringToIndex:curPathStr.length -1];
  300. }
  301. if([curPathStr isEqualToString:@"sdcard/Download/"]){
  302. curPathStr = @"/sdcard/Download/";
  303. }
  304. if([curPathStr isEqualToString:backupsDefaultPath]){
  305. needAddHadDefaultPath = NO;
  306. _selectIndex = i;
  307. break;
  308. }
  309. }
  310. // if(needAddHadDefaultPath){
  311. // [_folderListArr insertObject:backupsDefaultPath atIndex:0];
  312. // _selectIndex = 0;
  313. // }
  314. }
  315. [self.tableView reloadData];
  316. }
  317. @end