backupsSetViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. backupsDefaultPath = [iTools changePathToShowPathBy:backupsDefaultPath];
  133. NSString * rightStr = backupsDefaultPath;
  134. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  135. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  136. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  137. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#01B7EA" alpha:0.8] range:redRange];
  138. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  139. // 设置行间距
  140. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  141. [paragraphStyle setLineSpacing:5]; //设置行间距
  142. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  143. _uploadFilePathLabel.attributedText = noteStr;
  144. }
  145. #pragma mark 尾部事件
  146. - (void)didClickTailViewFun
  147. {
  148. photosBackupsTaskModel* model = [backupsFileManager shareInstance].curPhotosBackupsTaskMod;
  149. if(!model){
  150. KWeakSelf
  151. [photosBackupsTaskModel bg_findAsync:backups_photos_tableName limit:1 orderBy:nil desc:YES complete:^(NSArray * _Nullable array) {
  152. mainBlock(^{
  153. if(array && array.count > 0){
  154. photosBackupsTaskModel *preModel = array.lastObject;
  155. if(preModel.curBackupsState == backupsStateUploading
  156. ||preModel.curBackupsState == backupsStateSuspend
  157. ){
  158. [[iToast makeText:NSLocalizedString(@"File_backups_set_default_path_tip",nil)] show];
  159. }
  160. else{
  161. [self gotofileTransferPathCheckVCFun];
  162. }
  163. }
  164. else{
  165. [self gotofileTransferPathCheckVCFun];
  166. }
  167. });
  168. }];
  169. }
  170. else if(model.curBackupsState == backupsStateUploading
  171. //|| model.curBackupsState == backupsStateSuspend
  172. )
  173. {
  174. //判断尺寸路径是否存在
  175. NSString * uploadDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_backups_default_path)];
  176. BOOL isExtraFileType = NO;
  177. BOOL isExtraPathFind = NO;
  178. if(uploadDefaultPath){
  179. if(![uploadDefaultPath containsString:@"sdcard/"]){
  180. isExtraFileType = YES;
  181. }
  182. }
  183. if(uploadDefaultPath && ksharedAppDelegate.cloudPhoneExtraFileListMod){
  184. NSArray*arr = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  185. for (cloudPhoneExtraFileModel*model in arr) {
  186. if([uploadDefaultPath containsString:model.extraPath]){
  187. isExtraPathFind = YES;
  188. break;
  189. }
  190. }
  191. }
  192. if(isExtraFileType && !isExtraPathFind){
  193. [self gotofileTransferPathCheckVCFun];
  194. }
  195. else{
  196. [[iToast makeText:NSLocalizedString(@"File_backups_set_default_path_tip",nil)] show];
  197. }
  198. }
  199. else{
  200. [self gotofileTransferPathCheckVCFun];
  201. }
  202. }
  203. - (void)gotofileTransferPathCheckVCFun
  204. {
  205. fileTransferPathCheckViewController *vc = [fileTransferPathCheckViewController new];
  206. vc.curType = 2;
  207. [self.navigationController pushViewController:vc animated:YES];
  208. }
  209. #pragma mark - 列表委托
  210. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  211. return 1;
  212. }
  213. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  214. //return 2;
  215. return 1;
  216. }
  217. - (fileSetTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  218. __block NSInteger row = indexPath.row;
  219. static NSString *identifier = @"fileSetTableViewCell";
  220. fileSetTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  221. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  222. if (!cell){
  223. cell = [[fileSetTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  224. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  225. [cell setBackgroundColor:[UIColor clearColor]];
  226. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  227. [cell.bgViewLayer removeFromSuperlayer];
  228. [cell.titleLabel2 setHidden:YES];
  229. [cell.rightImage setHidden:YES];
  230. [cell.lineView setHidden:NO];
  231. [cell.maskSwitch setHidden:NO];
  232. }
  233. if (row == 0){
  234. [cell.titleLabel setText:NSLocalizedString(@"File_backups_set_Cellular",nil)];
  235. BOOL haveOpenMask = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_canUse_Cellular_all)];
  236. [cell.maskSwitch setOn:haveOpenMask];
  237. /*上圆角*/
  238. //设置部分圆角 贝塞尔曲线
  239. // UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 60)
  240. // byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
  241. // cornerRadii:CGSizeMake(8, 8)];
  242. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 60)
  243. byRoundingCorners:UIRectCornerAllCorners
  244. cornerRadii:CGSizeMake(8, 8)];
  245. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  246. maskLayer.frame = cell.cellBgView.bounds;
  247. maskLayer.path = maskPath.CGPath;
  248. cell.bgViewLayer = maskLayer;
  249. cell.cellBgView.layer.mask = cell.bgViewLayer;
  250. [cell.lineView setHidden:YES];
  251. }
  252. else if (row == 1)
  253. {
  254. // [cell.titleLabel setText:NSLocalizedString(@"File_backups_set_battery_level",nil)];
  255. //
  256. // BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_file_backups_battery_level];
  257. // [cell.maskSwitch setOn:haveOpenMask];
  258. /*下圆角*/
  259. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 60)
  260. byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
  261. cornerRadii:CGSizeMake(8, 8)];
  262. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  263. maskLayer.frame = cell.cellBgView.bounds;
  264. maskLayer.path = maskPath.CGPath;
  265. cell.bgViewLayer = maskLayer;
  266. cell.cellBgView.layer.mask = cell.bgViewLayer;
  267. [cell.lineView setHidden:YES];
  268. }
  269. KWeakSelf
  270. cell.didClickSwitch = ^(BOOL SwitchOn) {
  271. [weakSelf didClickSwitchBy:SwitchOn withRow:row];
  272. };
  273. return cell;
  274. }
  275. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  276. return 60;
  277. }
  278. - (void)didClickSwitchBy:(BOOL)SwitchOn withRow:(NSInteger)row
  279. {
  280. if(row == 0){
  281. [HWDataManager setBoolWithKey:stringKeyAddSn(Const_file_Transfe_canUse_Cellular_all) value:SwitchOn];
  282. }
  283. else{
  284. [HWDataManager setBoolWithKey:stringKeyAddSn(Const_file_backups_battery_level) value:SwitchOn];
  285. }
  286. }
  287. @end