fileTransferPathCheckViewController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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. #import "backupPathListModel.h"
  13. @interface fileTransferPathCheckViewController ()<UITableViewDelegate,UITableViewDataSource>
  14. @property (nonatomic, strong) UITableView *tableView;
  15. @property (nonatomic, strong) NSMutableArray * folderListArr;
  16. @property (nonatomic,assign) NSInteger selectIndex;
  17. @property(nonatomic,copy)NSString* createFolderNameStr;
  18. @end
  19. @implementation fileTransferPathCheckViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. [self.toolBar setHidden:YES];
  24. [self.navigationBar setHidden:YES];
  25. [self.navBarBGView setHidden:NO];
  26. //[self.titleLabel setText:NSLocalizedString(@"File_upload_path_check",nil)];
  27. [self.view setBackgroundColor:HWF5F7FAColor];
  28. _folderListArr = [NSMutableArray new];
  29. _selectIndex = -1;
  30. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(createFolderDoneNotFun:) name:createFolderDoneNotification object:nil];
  31. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getFolderListDoneNotFun:) name:getFolderListDoneNotification object:nil];
  32. [self drawAnyView];
  33. [self setupKeyboardManager];
  34. [self getFolderListFun];
  35. }
  36. - (void)getFolderListFun
  37. {
  38. //原来走通道
  39. //[[webRtcManager shareManager] getBackupFolderListFun];
  40. //改走frpc方案
  41. [self getBackupPathListFun];
  42. }
  43. #pragma mark 改走frpc方案 取备份备份文件夹列表
  44. - (void)getBackupPathListFun
  45. {
  46. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  47. KWeakSelf
  48. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"backupPath" Parameters:paraDict success:^(id _Nonnull responseObject) {
  49. backupPathListModel *model = [[backupPathListModel alloc] initWithDictionary:responseObject error:nil];
  50. if(model && model.status == 0){
  51. [weakSelf getFolderListDoneWith:model];
  52. }
  53. else{
  54. }
  55. } failure:^(NSError * _Nonnull error) {
  56. }];
  57. }
  58. - (void)drawAnyView{
  59. UIButton* rightButton = [[UIButton alloc] init];
  60. [rightButton setTitle:NSLocalizedString(@"File_upload_path_new",nil) forState:UIControlStateNormal];
  61. [rightButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  62. rightButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
  63. rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  64. [rightButton addTarget:self action:@selector(didiClikRightButFun:) forControlEvents:UIControlEventTouchUpInside];
  65. [self.navBarBGView addSubview:rightButton];
  66. [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.width.mas_equalTo(120);
  68. make.height.mas_equalTo(40);
  69. make.right.mas_equalTo(-15);
  70. make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  71. }];
  72. [self.view addSubview:self.tableView];
  73. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.mas_equalTo(0);
  75. make.right.mas_equalTo(0);
  76. make.bottom.mas_equalTo(-(safeArea -20));
  77. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  78. }];
  79. }
  80. - (void)viewWillAppear:(BOOL)animated
  81. {
  82. [super viewWillAppear:animated];
  83. IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
  84. keyboardManager.enable = YES;
  85. if(_curType == 2){
  86. [self.titleLabel setText:NSLocalizedString(@"File_upload_path_new_check_title",nil)];
  87. }
  88. else if(_curType == 3){
  89. [self.titleLabel setText:NSLocalizedString(@"File_save_to_box_check_title",nil)];
  90. }
  91. else{
  92. [self.titleLabel setText:NSLocalizedString(@"File_upload_path_check",nil)];
  93. }
  94. }
  95. - (void)viewWillDisappear:(BOOL)animated
  96. {
  97. [super viewWillDisappear:animated];
  98. IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
  99. keyboardManager.enable = NO;
  100. }
  101. - (void)setupKeyboardManager {
  102. IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
  103. keyboardManager.enable = YES;
  104. keyboardManager.shouldResignOnTouchOutside = YES;
  105. keyboardManager.shouldShowToolbarPlaceholder = NO;
  106. keyboardManager.enableAutoToolbar = NO;
  107. }
  108. #pragma mark - 懒加载
  109. - (UITableView *)tableView{
  110. if (!_tableView) {
  111. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain];
  112. _tableView.delegate = self;
  113. _tableView.dataSource = self;
  114. _tableView.showsVerticalScrollIndicator = NO;
  115. _tableView.showsHorizontalScrollIndicator = NO;
  116. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  117. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  118. [_tableView setSeparatorColor:[UIColor clearColor]];
  119. [_tableView setBackgroundColor:[UIColor clearColor]];
  120. [_tableView setTableFooterView:[UIView new]];
  121. [_tableView setBounces:YES];
  122. // _tableView.layer.cornerRadius = 8;
  123. // _tableView.layer.masksToBounds = YES;
  124. if (@available(iOS 15.0, *)) {
  125. _tableView.sectionHeaderTopPadding = 0;
  126. }
  127. }
  128. return _tableView;
  129. }
  130. #pragma mark - 列表委托
  131. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  132. return 1;
  133. }
  134. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  135. return _folderListArr.count;
  136. }
  137. - (fileTransferPathCheckTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  138. __block NSInteger row = indexPath.row;
  139. static NSString *identifier = @"fileTransferPathCheckTableViewCell";
  140. fileTransferPathCheckTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  141. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  142. if (!cell){
  143. cell = [[fileTransferPathCheckTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  144. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  145. [cell setBackgroundColor:[UIColor clearColor]];
  146. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  147. [cell.bgViewLayer removeFromSuperlayer];
  148. [cell.titleLabel2 setHidden:YES];
  149. [cell.rightImage setHidden:YES];
  150. [cell.lineView setHidden:NO];
  151. [cell.checkButton setHidden:NO];
  152. }
  153. if(row < _folderListArr.count){
  154. NSString *name = _folderListArr[row];
  155. name = [iTools changePathToShowPathBy:name];
  156. cell.titleLabel.text = name;
  157. if(row == _selectIndex){
  158. cell.checkButton.selected = YES;
  159. }
  160. else{
  161. cell.checkButton.selected = NO;
  162. }
  163. }
  164. if(_folderListArr.count == 1){
  165. //设置部分圆角 贝塞尔曲线
  166. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 90)
  167. byRoundingCorners:UIRectCornerAllCorners
  168. cornerRadii:CGSizeMake(8, 8)];
  169. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  170. maskLayer.frame = cell.cellBgView.bounds;
  171. maskLayer.path = maskPath.CGPath;
  172. cell.bgViewLayer = maskLayer;
  173. cell.cellBgView.layer.mask = cell.bgViewLayer;
  174. }
  175. else{
  176. if (row == 0){
  177. /*上圆角*/
  178. //设置部分圆角 贝塞尔曲线
  179. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 90)
  180. byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
  181. cornerRadii:CGSizeMake(8, 8)];
  182. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  183. maskLayer.frame = cell.cellBgView.bounds;
  184. maskLayer.path = maskPath.CGPath;
  185. cell.bgViewLayer = maskLayer;
  186. cell.cellBgView.layer.mask = cell.bgViewLayer;
  187. }//else
  188. if (row == _folderListArr.count -1){
  189. //[cell.titleLabel setText:NSLocalizedString(@"File_Transfer_set_battery_level",nil)];
  190. //cell.titleLabel.text = @"云机名称/我的空间/XYJ";
  191. /*下圆角*/
  192. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 90)
  193. byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
  194. cornerRadii:CGSizeMake(8, 8)];
  195. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  196. maskLayer.frame = cell.cellBgView.bounds;
  197. maskLayer.path = maskPath.CGPath;
  198. cell.bgViewLayer = maskLayer;
  199. cell.cellBgView.layer.mask = cell.bgViewLayer;
  200. [cell.lineView setHidden:YES];
  201. }
  202. }
  203. KWeakSelf
  204. cell.didClickSwitch = ^(BOOL SwitchOn) {
  205. [weakSelf userCheckFolderPathByRow:row];
  206. };
  207. return cell;
  208. }
  209. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  210. return 90;
  211. }
  212. - (void)didiClikRightButFun:(UIButton*)but
  213. {
  214. filePathCreatPopView * filePathCreatPopV = [[filePathCreatPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  215. if(ksharedAppDelegate.cloudPhoneExtraFileListMod){
  216. filePathCreatPopV.outSizeArr = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  217. }
  218. else{
  219. filePathCreatPopV.outSizeArr = @[];
  220. }
  221. [self.view addSubview:filePathCreatPopV];
  222. filePathCreatPopV.curType = _curType;
  223. KWeakSelf
  224. filePathCreatPopV.didClickOkBut = ^(NSString * _Nonnull folderName, NSString * _Nonnull DiskPathStr) {
  225. [weakSelf didGetFolderName:folderName withDiskPath:DiskPathStr];
  226. };
  227. }
  228. #pragma mark 用户选择默认上次文件夹
  229. - (void)userCheckFolderPathByRow:(NSInteger)row
  230. {
  231. _selectIndex = row;
  232. NSString *cutPath = _folderListArr[row];
  233. if(_curType == 2){
  234. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_backups_default_path) value:cutPath];
  235. }
  236. else if(_curType == 1){
  237. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_upload_default_path) value:cutPath];
  238. }
  239. else if(_curType == 3){
  240. [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:cutPath];
  241. }
  242. [[iToast makeText:NSLocalizedString(@"save_path_change_suc_tip",nil)] show];
  243. if(_didChangeSavePathFun){
  244. _didChangeSavePathFun();
  245. }
  246. if(_curType == 2){
  247. //相册自动备份
  248. //[[backupsFileManager shareInstance] reBackupsFileFun];
  249. [[nasBackupsManager shareInstance] reBackupsFileFun];
  250. }
  251. [self.tableView reloadData];
  252. }
  253. #pragma mark 信令通道创建 文件夹
  254. - (void)didGetFolderName:(NSString*)folderName withDiskPath:(NSString*)diskPathStr
  255. {
  256. _createFolderNameStr = folderName;
  257. NSString *curbackupsDefaultPath = [[NSString alloc] initWithFormat:@"%@/%@",diskPathStr,_createFolderNameStr];
  258. NSString *lastStr = [diskPathStr substringFromIndex:diskPathStr.length -1];
  259. if([lastStr isEqualToString:@"/"]){
  260. curbackupsDefaultPath = [[NSString alloc] initWithFormat:@"%@%@",diskPathStr,_createFolderNameStr];
  261. }
  262. if(_curType == 2){
  263. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_backups_default_path) value:curbackupsDefaultPath];
  264. }
  265. else if(_curType == 1){
  266. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_upload_default_path) value:curbackupsDefaultPath];
  267. }
  268. else if(_curType == 3){
  269. [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:curbackupsDefaultPath];
  270. }
  271. //[[webRtcManager shareManager] createBackupsFolderBy:curbackupsDefaultPath];
  272. [self mkdirPathFunBy:curbackupsDefaultPath];
  273. }
  274. #pragma mark frp创建 文件夹
  275. - (void)mkdirPathFunBy:(NSString*)path
  276. {
  277. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  278. if(path){
  279. [paraDict setValue:path forKeyPath:@"path"];
  280. }
  281. KWeakSelf
  282. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"mkdir" Parameters:paraDict success:^(id _Nonnull responseObject) {
  283. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  284. NSString * tipStr = @"";
  285. if(model && model.status == 0){
  286. tipStr = NSLocalizedString(@"File_upload_path_new_suc",nil);
  287. if(self->_didChangeSavePathFun){
  288. self->_didChangeSavePathFun();
  289. }
  290. if(self->_curType == 2){
  291. //相册自动备份
  292. //[[backupsFileManager shareInstance] reBackupsFileFun];
  293. [[nasBackupsManager shareInstance] reBackupsFileFun];
  294. }
  295. }
  296. else if (model.status == 2){
  297. tipStr = NSLocalizedString(@"File_upload_path_new_save",nil);
  298. }
  299. else{
  300. tipStr = NSLocalizedString(@"File_upload_path_new_fail",nil);
  301. }
  302. mainBlock(^{
  303. [[iToast makeText:tipStr] show];
  304. });
  305. [weakSelf getFolderListFun];
  306. } failure:^(NSError * _Nonnull error) {
  307. }];
  308. }
  309. - (void)createFolderDoneNotFun:(NSNotification *)notification
  310. {
  311. NSNumber *stateNumber = [notification object];
  312. NSString * tipStr = @"";
  313. if(stateNumber.integerValue == 0){
  314. tipStr = NSLocalizedString(@"File_upload_path_new_suc",nil);
  315. if(_didChangeSavePathFun){
  316. _didChangeSavePathFun();
  317. }
  318. if(_curType == 2){
  319. //相册自动备份
  320. //[[backupsFileManager shareInstance] reBackupsFileFun];
  321. [[nasBackupsManager shareInstance] reBackupsFileFun];
  322. }
  323. }
  324. else if(stateNumber.integerValue == 2 ){
  325. tipStr = NSLocalizedString(@"File_upload_path_new_save",nil);
  326. }
  327. else{
  328. tipStr = NSLocalizedString(@"File_upload_path_new_fail",nil);
  329. }
  330. mainBlock(^{
  331. [[iToast makeText:tipStr] show];
  332. });
  333. [self getFolderListFun];
  334. }
  335. #pragma mark 信令通道 或者webrtc通道获取备份文件夹列表的响应 弃用!!!!
  336. - (void)getFolderListDoneNotFun:(NSNotification *)notification
  337. {
  338. NSDictionary *dataDict = [notification object];
  339. couldPhoneFolderListModel *model = [[couldPhoneFolderListModel alloc] initWithDictionary:dataDict error:nil];
  340. if(model){
  341. [_folderListArr removeAllObjects];
  342. [_folderListArr addObjectsFromArray:model.data];
  343. NSString * backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_backups_default_path)];
  344. if(_curType == 1){
  345. backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)];
  346. }
  347. else if(_curType == 3){
  348. backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_box_save_default_path)];
  349. }
  350. NSString *lastbackupsStr = [backupsDefaultPath substringFromIndex:backupsDefaultPath.length -1];
  351. BOOL needAddHadDefaultPath = YES;
  352. for (int i=0; i<_folderListArr.count; i++) {
  353. NSString * curPathStr = _folderListArr[i];
  354. NSString *lastStr = [curPathStr substringFromIndex:curPathStr.length -1];
  355. if([lastStr isEqualToString:@"/"]
  356. && ![lastbackupsStr isEqualToString:@"/"]){
  357. curPathStr = [curPathStr substringToIndex:curPathStr.length -1];
  358. }
  359. if([curPathStr isEqualToString:@"sdcard/Download/"]){
  360. curPathStr = @"/sdcard/Download/";
  361. }
  362. if([curPathStr isEqualToString:backupsDefaultPath]){
  363. needAddHadDefaultPath = NO;
  364. _selectIndex = i;
  365. break;
  366. }
  367. }
  368. // if(needAddHadDefaultPath){
  369. // [_folderListArr insertObject:backupsDefaultPath atIndex:0];
  370. // _selectIndex = 0;
  371. // }
  372. }
  373. KWeakSelf
  374. mainBlock(^{
  375. [weakSelf.tableView reloadData];
  376. });
  377. }
  378. #pragma mark frp通道获取备份文件夹列表的响应 正在使用!!!!
  379. - (void)getFolderListDoneWith:(backupPathListModel*)model
  380. {
  381. if(model){
  382. [_folderListArr removeAllObjects];
  383. [_folderListArr addObjectsFromArray:model.data.path];
  384. NSString * backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_backups_default_path)];
  385. if(_curType == 1){
  386. backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)];
  387. }
  388. else if(_curType == 3){
  389. backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_box_save_default_path)];
  390. }
  391. NSString *lastbackupsStr = [backupsDefaultPath substringFromIndex:backupsDefaultPath.length -1];
  392. BOOL needAddHadDefaultPath = YES;
  393. for (int i=0; i<_folderListArr.count; i++) {
  394. NSString * curPathStr = _folderListArr[i];
  395. NSString *lastStr = [curPathStr substringFromIndex:curPathStr.length -1];
  396. if([lastStr isEqualToString:@"/"]
  397. && ![lastbackupsStr isEqualToString:@"/"]){
  398. curPathStr = [curPathStr substringToIndex:curPathStr.length -1];
  399. }
  400. if([curPathStr isEqualToString:@"sdcard/Download/"]){
  401. curPathStr = @"/sdcard/Download/";
  402. }
  403. if([curPathStr isEqualToString:backupsDefaultPath]){
  404. needAddHadDefaultPath = NO;
  405. _selectIndex = i;
  406. break;
  407. }
  408. }
  409. // if(needAddHadDefaultPath){
  410. // [_folderListArr insertObject:backupsDefaultPath atIndex:0];
  411. // _selectIndex = 0;
  412. // }
  413. }
  414. KWeakSelf
  415. mainBlock(^{
  416. [weakSelf.tableView reloadData];
  417. });
  418. }
  419. @end