backupsSetViewController.m 13 KB

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