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