backupsSetViewController.m 10 KB

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