fileTransferPathCheckViewController.m 14 KB

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