fileTransfeSetViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. //
  2. // fileTransfeSetViewController.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/12/28.
  6. //
  7. #import "fileTransfeSetViewController.h"
  8. #import "fileSetTableViewCell.h"
  9. #import "fileTransferPathCheckViewController.h"
  10. #import "uploadFileManager.h"
  11. @interface fileTransfeSetViewController ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic, strong) UITableView *tableView;
  13. @property (nonatomic, strong) UIView *tailView;
  14. @property (nonatomic, strong) UILabel *uploadFilePathLabel;
  15. @end
  16. @implementation fileTransfeSetViewController
  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(@"set_upload_download_tip",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, 110 +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.bottom.mas_equalTo(0);
  77. make.top.mas_equalTo(15);
  78. }];
  79. UILabel *titleLab = [[UILabel alloc] init];
  80. titleLab.text = NSLocalizedString(@"File_upload_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. [tailBgView addSubview:_uploadFilePathLabel];
  107. [_uploadFilePathLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.left.mas_equalTo(10);
  109. make.right.mas_equalTo(-15);
  110. make.bottom.mas_equalTo(-20);
  111. make.top.mas_equalTo(titleLab.mas_bottom).offset(10.0);
  112. }];
  113. [self setUploadFilePathLabelTitleFun];
  114. }
  115. return _tailView;
  116. }
  117. - (void)setUploadFilePathLabelTitleFun
  118. {
  119. NSString * leftStr = NSLocalizedString(@"File_upload_path_way",nil);
  120. NSString * uploadDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)];
  121. if(!uploadDefaultPath || uploadDefaultPath.length == 0){
  122. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_upload_default_path) value:Const_default_upload_path];
  123. uploadDefaultPath = Const_default_upload_path;
  124. }
  125. if([uploadDefaultPath containsString:@"mnt/media_rw"]){
  126. uploadDefaultPath = [uploadDefaultPath stringByReplacingOccurrencesOfString:@"mnt/media_rw" withString:NSLocalizedString(@"disk_Extra_default_tip",nil)];
  127. }
  128. else if([uploadDefaultPath containsString:@"storage/emulated/0"]){
  129. uploadDefaultPath = [uploadDefaultPath stringByReplacingOccurrencesOfString:@"storage/emulated/0" withString:NSLocalizedString(@"disk_phone_default_tip",nil)];
  130. }
  131. else if([uploadDefaultPath containsString:@"sdcard"]){
  132. uploadDefaultPath = [uploadDefaultPath stringByReplacingOccurrencesOfString:@"sdcard" withString:NSLocalizedString(@"disk_phone_default_tip",nil)];
  133. }
  134. NSString * rightStr = uploadDefaultPath;
  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. uploadFileDataModel* model = [uploadFileManager shareInstance].curUploadFileDataModel;
  150. if(!model){
  151. [[uploadFileManager shareInstance] getDataInDatabaseFun:YES complete:^(NSMutableArray * _Nonnull Arr) {
  152. mainBlock(^{
  153. if(Arr && Arr.count== 3){
  154. NSArray *uploadingArr = Arr.firstObject;
  155. if(uploadingArr.count == 0){
  156. [self gotofileTransferPathCheckVCFun];
  157. }
  158. else{
  159. [[iToast makeText:NSLocalizedString(@"File_upload_set_default_path_tip",nil)] show];
  160. }
  161. }
  162. });
  163. }];
  164. }
  165. else if(model.curUploadStateType == uploadStateUploading
  166. ||model.curUploadStateType == uploadStateSuspend
  167. ){
  168. //判断尺寸路径是否存在
  169. NSString * uploadDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)];
  170. BOOL isExtraFileType = NO;
  171. BOOL isExtraPathFind = NO;
  172. if(uploadDefaultPath){
  173. if(![uploadDefaultPath containsString:@"sdcard/"]){
  174. isExtraFileType = YES;
  175. }
  176. }
  177. if(uploadDefaultPath && ksharedAppDelegate.cloudPhoneExtraFileListMod){
  178. NSArray*arr = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  179. for (cloudPhoneExtraFileModel*model in arr) {
  180. if([uploadDefaultPath containsString:model.extraPath]){
  181. isExtraPathFind = YES;
  182. break;
  183. }
  184. }
  185. }
  186. if(isExtraFileType && !isExtraPathFind){
  187. [self gotofileTransferPathCheckVCFun];
  188. }
  189. else{
  190. [[iToast makeText:NSLocalizedString(@"File_upload_set_default_path_tip",nil)] show];
  191. }
  192. }
  193. else{
  194. [self gotofileTransferPathCheckVCFun];
  195. }
  196. }
  197. - (void)gotofileTransferPathCheckVCFun
  198. {
  199. fileTransferPathCheckViewController *vc = [fileTransferPathCheckViewController new];
  200. vc.curType = 1;
  201. [self.navigationController pushViewController:vc animated:YES];
  202. }
  203. #pragma mark - 列表委托
  204. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  205. return 1;
  206. }
  207. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  208. //return 2;
  209. return 1;
  210. }
  211. - (fileSetTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  212. __block NSInteger row = indexPath.row;
  213. static NSString *identifier = @"fileSetTableViewCell";
  214. fileSetTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  215. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  216. if (!cell){
  217. cell = [[fileSetTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  218. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  219. [cell setBackgroundColor:[UIColor clearColor]];
  220. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  221. [cell.bgViewLayer removeFromSuperlayer];
  222. [cell.titleLabel2 setHidden:YES];
  223. [cell.rightImage setHidden:YES];
  224. [cell.lineView setHidden:NO];
  225. [cell.maskSwitch setHidden:NO];
  226. }
  227. if (row == 0){
  228. [cell.titleLabel setText:NSLocalizedString(@"File_Transfer_set_Cellular",nil)];
  229. BOOL haveOpenMask = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_canUse_Cellular)];
  230. [cell.maskSwitch setOn:haveOpenMask];
  231. /*上圆角*/
  232. //设置部分圆角 贝塞尔曲线
  233. // UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 60)
  234. // byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
  235. // cornerRadii:CGSizeMake(8, 8)];
  236. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 60)
  237. byRoundingCorners:UIRectCornerAllCorners
  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. }else if (row == 1){
  246. [cell.titleLabel setText:NSLocalizedString(@"File_Transfer_set_battery_level",nil)];
  247. BOOL haveOpenMask = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_battery_level)];
  248. [cell.maskSwitch setOn:haveOpenMask];
  249. /*下圆角*/
  250. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 60)
  251. byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
  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. KWeakSelf
  261. cell.didClickSwitch = ^(BOOL SwitchOn) {
  262. [weakSelf didClickSwitchBy:SwitchOn withRow:row];
  263. };
  264. return cell;
  265. }
  266. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  267. return 60;
  268. }
  269. - (void)didClickSwitchBy:(BOOL)SwitchOn withRow:(NSInteger)row
  270. {
  271. if(row == 0){
  272. [HWDataManager setBoolWithKey:stringKeyAddSn(Const_file_Transfe_canUse_Cellular) value:SwitchOn];
  273. }
  274. else{
  275. [HWDataManager setBoolWithKey:stringKeyAddSn(Const_file_Transfe_battery_level) value:SwitchOn];
  276. }
  277. }
  278. @end