backupsSetViewController.m 12 KB

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