fileTransferPathCheckViewController.m 19 KB

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