backupsSetViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. //
  2. // backupsSetViewController.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/2.
  6. //
  7. #import "backupsSetViewController.h"
  8. #import "fileSetTableViewCell.h"
  9. #import "fileTransferPathCheckViewController.h"
  10. #import "backupsFileManager.h"
  11. @interface backupsSetViewController ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic, strong) UITableView *tableView;
  13. @property (nonatomic, strong) UIView *tailView;
  14. @property (nonatomic, strong) UILabel *uploadFilePathLabel;
  15. @end
  16. @implementation backupsSetViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // Do any additional setup after loading the view.
  20. [self.toolBar setHidden:YES];
  21. [self.navigationBar setHidden:YES];
  22. [self.navBarBGView setHidden:NO];
  23. [self.titleLabel setText:NSLocalizedString(@"File_backups_path_set",nil)];
  24. //多国语言适配
  25. NSString *languageCode = [NSLocale preferredLanguages][0];
  26. if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
  27. {
  28. self.titleLabel.font = [UIFont boldSystemFontOfSize:15.0];
  29. }
  30. [self.view setBackgroundColor:HWF5F7FAColor];
  31. [self drawAnyView];
  32. }
  33. - (void)viewWillAppear:(BOOL)animated
  34. {
  35. [super viewWillAppear:animated];
  36. [self setUploadFilePathLabelTitleFun];
  37. }
  38. - (void)drawAnyView{
  39. [self.view addSubview:self.tableView];
  40. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.mas_equalTo(0);
  42. make.right.mas_equalTo(0);
  43. make.bottom.mas_equalTo(0);
  44. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  45. }];
  46. self.tableView.tableFooterView = [self tailView];
  47. }
  48. #pragma mark - 懒加载
  49. - (UITableView *)tableView{
  50. if (!_tableView) {
  51. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain];
  52. _tableView.delegate = self;
  53. _tableView.dataSource = self;
  54. _tableView.showsVerticalScrollIndicator = NO;
  55. _tableView.showsHorizontalScrollIndicator = NO;
  56. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  57. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  58. [_tableView setSeparatorColor:[UIColor clearColor]];
  59. [_tableView setBackgroundColor:[UIColor clearColor]];
  60. [_tableView setTableFooterView:[UIView new]];
  61. [_tableView setBounces:YES];
  62. _tableView.scrollEnabled = NO;
  63. if (@available(iOS 15.0, *)) {
  64. _tableView.sectionHeaderTopPadding = 0;
  65. }
  66. }
  67. return _tableView;
  68. }
  69. #pragma mark - 懒加载
  70. - (UIView *)tailView{
  71. if (!_tailView) {
  72. _tailView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 140 +15)];
  73. UIView *tailBgView = [[UIView alloc] init];
  74. tailBgView.backgroundColor = [UIColor whiteColor];
  75. tailBgView.layer.cornerRadius = 8;
  76. [_tailView addSubview:tailBgView];
  77. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickTailViewFun)];
  78. [tailBgView addGestureRecognizer:tap];
  79. [tailBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.left.mas_equalTo(15);
  81. make.right.mas_equalTo(-15);
  82. make.height.mas_equalTo(60);
  83. make.top.mas_equalTo(15);
  84. }];
  85. UILabel *titleLab = [[UILabel alloc] init];
  86. titleLab.text = NSLocalizedString(@"File_backups_path_set",nil);
  87. titleLab.font = [UIFont boldSystemFontOfSize:14.0];
  88. titleLab.textColor = [UIColor hwColor:@"#0A132B" alpha:1.0];
  89. [tailBgView addSubview:titleLab];
  90. [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.mas_equalTo(10);
  92. make.right.mas_equalTo(-50);
  93. make.height.mas_equalTo(20);
  94. make.top.mas_equalTo(20);
  95. }];
  96. /*右侧箭头*/
  97. UIImageView *rightImage = [[UIImageView alloc] init];
  98. [rightImage setBackgroundColor:[UIColor clearColor]];
  99. [rightImage setImage:[UIImage imageNamed:@"cell_right_access"]];
  100. [tailBgView addSubview:rightImage];
  101. [rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.width.mas_equalTo(28);
  103. make.right.mas_equalTo(-15.f);
  104. make.height.mas_equalTo(28);
  105. make.centerY.equalTo(titleLab.mas_centerY);
  106. }];
  107. _uploadFilePathLabel=[[UILabel alloc] init];
  108. //titleLab.text = NSLocalizedString(@"File_upload_path_set",nil);
  109. _uploadFilePathLabel.font = [UIFont systemFontOfSize:12.0];
  110. _uploadFilePathLabel.textColor = [UIColor hwColor:@"#6A6A6A" alpha:1.0];
  111. _uploadFilePathLabel.numberOfLines = 0;
  112. [_tailView addSubview:_uploadFilePathLabel];
  113. [_uploadFilePathLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  114. make.left.mas_equalTo(15);
  115. make.right.mas_equalTo(-15);
  116. make.bottom.mas_equalTo(-10);
  117. make.top.mas_equalTo(tailBgView.mas_bottom).offset(10.0);
  118. }];
  119. [self setUploadFilePathLabelTitleFun];
  120. }
  121. return _tailView;
  122. }
  123. - (void)setUploadFilePathLabelTitleFun
  124. {
  125. NSString * leftStr = NSLocalizedString(@"File_backups_path_way_tip",nil);
  126. NSString * backupsDefaultPath = [HWDataManager getStringWithKey:Const_photo_backups_default_path];
  127. if(!backupsDefaultPath || backupsDefaultPath.length == 0){
  128. backupsDefaultPath = Const_default_backups_path;
  129. [HWDataManager setStringWithKey:Const_photo_backups_default_path value:backupsDefaultPath];
  130. }
  131. if([backupsDefaultPath containsString:@"mnt/media_rw"]){
  132. backupsDefaultPath = [backupsDefaultPath stringByReplacingOccurrencesOfString:@"mnt/media_rw" withString:NSLocalizedString(@"disk_Extra_default_tip",nil)];
  133. }
  134. else if([backupsDefaultPath containsString:@"storage/emulated/0"]){
  135. backupsDefaultPath = [backupsDefaultPath stringByReplacingOccurrencesOfString:@"storage/emulated/0" withString:NSLocalizedString(@"disk_phone_default_tip",nil)];
  136. }
  137. else if([backupsDefaultPath containsString:@"sdcard"]){
  138. backupsDefaultPath = [backupsDefaultPath stringByReplacingOccurrencesOfString:@"sdcard" withString:NSLocalizedString(@"disk_phone_default_tip",nil)];
  139. }
  140. NSString * rightStr = backupsDefaultPath;
  141. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  142. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  143. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  144. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#01B7EA" alpha:0.8] range:redRange];
  145. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  146. // 设置行间距
  147. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  148. [paragraphStyle setLineSpacing:5]; //设置行间距
  149. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  150. _uploadFilePathLabel.attributedText = noteStr;
  151. }
  152. #pragma mark 尾部事件
  153. - (void)didClickTailViewFun
  154. {
  155. photosBackupsTaskModel* model = [backupsFileManager shareInstance].curPhotosBackupsTaskMod;
  156. if(!model){
  157. KWeakSelf
  158. [photosBackupsTaskModel bg_findAsync:backups_photos_tableName limit:1 orderBy:nil desc:YES complete:^(NSArray * _Nullable array) {
  159. mainBlock(^{
  160. if(array && array.count > 0){
  161. photosBackupsTaskModel *preModel = array.lastObject;
  162. if(preModel.curBackupsState == backupsStateUploading
  163. ||preModel.curBackupsState == backupsStateSuspend
  164. ){
  165. [[iToast makeText:NSLocalizedString(@"File_backups_set_default_path_tip",nil)] show];
  166. }
  167. else{
  168. [self gotofileTransferPathCheckVCFun];
  169. }
  170. }
  171. else{
  172. [self gotofileTransferPathCheckVCFun];
  173. }
  174. });
  175. }];
  176. }
  177. else if(model.curBackupsState == backupsStateUploading
  178. //|| model.curBackupsState == backupsStateSuspend
  179. )
  180. {
  181. //判断尺寸路径是否存在
  182. NSString * uploadDefaultPath = [HWDataManager getStringWithKey:Const_photo_backups_default_path];
  183. BOOL isExtraFileType = NO;
  184. BOOL isExtraPathFind = NO;
  185. if(uploadDefaultPath){
  186. if(![uploadDefaultPath containsString:@"sdcard/"]){
  187. isExtraFileType = YES;
  188. }
  189. }
  190. if(uploadDefaultPath && ksharedAppDelegate.cloudPhoneExtraFileListMod){
  191. NSArray*arr = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  192. for (cloudPhoneExtraFileModel*model in arr) {
  193. if([uploadDefaultPath containsString:model.extraPath]){
  194. isExtraPathFind = YES;
  195. break;
  196. }
  197. }
  198. }
  199. if(isExtraFileType && !isExtraPathFind){
  200. [self gotofileTransferPathCheckVCFun];
  201. }
  202. else{
  203. [[iToast makeText:NSLocalizedString(@"File_backups_set_default_path_tip",nil)] show];
  204. }
  205. }
  206. else{
  207. [self gotofileTransferPathCheckVCFun];
  208. }
  209. }
  210. - (void)gotofileTransferPathCheckVCFun
  211. {
  212. fileTransferPathCheckViewController *vc = [fileTransferPathCheckViewController new];
  213. vc.curType = 2;
  214. [self.navigationController pushViewController:vc animated:YES];
  215. }
  216. #pragma mark - 列表委托
  217. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  218. return 1;
  219. }
  220. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  221. //return 2;
  222. return 1;
  223. }
  224. - (fileSetTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  225. __block NSInteger row = indexPath.row;
  226. static NSString *identifier = @"fileSetTableViewCell";
  227. fileSetTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  228. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  229. if (!cell){
  230. cell = [[fileSetTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  231. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  232. [cell setBackgroundColor:[UIColor clearColor]];
  233. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  234. [cell.bgViewLayer removeFromSuperlayer];
  235. [cell.titleLabel2 setHidden:YES];
  236. [cell.rightImage setHidden:YES];
  237. [cell.lineView setHidden:NO];
  238. [cell.maskSwitch setHidden:NO];
  239. }
  240. if (row == 0){
  241. [cell.titleLabel setText:NSLocalizedString(@"File_backups_set_Cellular",nil)];
  242. BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_file_backups_canUse_Cellular];
  243. [cell.maskSwitch setOn:haveOpenMask];
  244. /*上圆角*/
  245. //设置部分圆角 贝塞尔曲线
  246. // UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 60)
  247. // byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
  248. // cornerRadii:CGSizeMake(8, 8)];
  249. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 60)
  250. byRoundingCorners:UIRectCornerAllCorners
  251. cornerRadii:CGSizeMake(8, 8)];
  252. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  253. maskLayer.frame = cell.cellBgView.bounds;
  254. maskLayer.path = maskPath.CGPath;
  255. cell.bgViewLayer = maskLayer;
  256. cell.cellBgView.layer.mask = cell.bgViewLayer;
  257. [cell.lineView setHidden:YES];
  258. }
  259. else if (row == 1)
  260. {
  261. // [cell.titleLabel setText:NSLocalizedString(@"File_backups_set_battery_level",nil)];
  262. //
  263. // BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_file_backups_battery_level];
  264. // [cell.maskSwitch setOn:haveOpenMask];
  265. /*下圆角*/
  266. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 60)
  267. byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
  268. cornerRadii:CGSizeMake(8, 8)];
  269. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  270. maskLayer.frame = cell.cellBgView.bounds;
  271. maskLayer.path = maskPath.CGPath;
  272. cell.bgViewLayer = maskLayer;
  273. cell.cellBgView.layer.mask = cell.bgViewLayer;
  274. [cell.lineView setHidden:YES];
  275. }
  276. KWeakSelf
  277. cell.didClickSwitch = ^(BOOL SwitchOn) {
  278. [weakSelf didClickSwitchBy:SwitchOn withRow:row];
  279. };
  280. return cell;
  281. }
  282. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  283. return 60;
  284. }
  285. - (void)didClickSwitchBy:(BOOL)SwitchOn withRow:(NSInteger)row
  286. {
  287. if(row == 0){
  288. [HWDataManager setBoolWithKey:Const_file_backups_canUse_Cellular value:SwitchOn];
  289. }
  290. else{
  291. [HWDataManager setBoolWithKey:Const_file_backups_battery_level value:SwitchOn];
  292. }
  293. }
  294. @end