filePathCreatPopView.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. //
  2. // filePathCreatPopView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/12/29.
  6. //
  7. #import "filePathCreatPopView.h"
  8. #import "filePathCreatTableViewCell.h"
  9. #import "cloudPhoneExtraFileListModel.h"
  10. @interface filePathCreatPopView ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
  11. {
  12. UIView *whiteBgView;
  13. UILabel *titleLabel;
  14. UITextField *filePathNameTF;
  15. UIButton *canclButton;
  16. UIButton *okButton;
  17. BOOL isCouldPhonePathType;//路径是否为云机
  18. }
  19. @property (nonatomic, strong) UITableView *tableView;
  20. @property(nonatomic,copy) NSMutableArray *curDataArr;//磁盘数据 +默认
  21. @end
  22. @implementation filePathCreatPopView
  23. - (id)initWithFrame:(CGRect)frame{
  24. self = [super initWithFrame:frame];
  25. [self drawAnyView];
  26. return self;
  27. }
  28. - (void)drawAnyView{
  29. [self setBackgroundColor:[UIColor hwColor:@"#000000" alpha:0.6]];
  30. whiteBgView = [[UIView alloc] init];
  31. whiteBgView.backgroundColor = [UIColor whiteColor];
  32. whiteBgView.layer.cornerRadius = 12;
  33. [self addSubview:whiteBgView];
  34. [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.mas_equalTo(0);
  36. make.right.mas_equalTo(0);
  37. make.height.mas_equalTo(418+ 10 + safeArea);
  38. //make.height.mas_equalTo(200+ 10 + safeArea);
  39. make.bottom.mas_equalTo(10);
  40. }];
  41. UIView *tapView = [[UIView alloc] init];
  42. [self addSubview:tapView];
  43. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapUpFun:)];
  44. // [tapView addGestureRecognizer:tap];
  45. [tapView mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.mas_equalTo(0);
  47. make.right.mas_equalTo(0);
  48. make.top.mas_equalTo(0);
  49. make.bottom.mas_equalTo(whiteBgView.mas_top);
  50. }];
  51. titleLabel = [[UILabel alloc] init];
  52. titleLabel.text = NSLocalizedString(@"File_upload_path_new",nil);
  53. titleLabel.font = [UIFont boldSystemFontOfSize:18.0];
  54. titleLabel.textColor = [UIColor hwColor:@"#0A132B" alpha:1.0];
  55. [whiteBgView addSubview:titleLabel];
  56. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.right.mas_equalTo(0);
  58. make.height.mas_equalTo(20);
  59. make.left.mas_equalTo(15);
  60. make.top.mas_equalTo(15);
  61. }];
  62. [whiteBgView addSubview:self.tableView];
  63. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.mas_equalTo(15);
  65. make.right.mas_equalTo(-15);
  66. make.height.mas_equalTo(70*2+50);
  67. //make.height.mas_equalTo(0.0);
  68. make.top.equalTo(titleLabel.mas_bottom).offset(15.f);
  69. }];
  70. //self.tableView.hidden = YES;
  71. UILabel *tipLabel = [[UILabel alloc] init];
  72. tipLabel.text = NSLocalizedString(@"File_upload_path_new_name_tip",nil);
  73. tipLabel.font = [UIFont systemFontOfSize:14.0];
  74. tipLabel.textColor = [UIColor hwColor:@"#0A132B" alpha:1.0];
  75. [whiteBgView addSubview:tipLabel];
  76. [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.right.mas_equalTo(0);
  78. make.height.mas_equalTo(20);
  79. make.left.mas_equalTo(15);
  80. make.top.equalTo(self.tableView.mas_bottom).offset(15);
  81. }];
  82. filePathNameTF = [[UITextField alloc] init];
  83. filePathNameTF.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0];
  84. filePathNameTF.layer.cornerRadius = 8;
  85. filePathNameTF.textColor = [UIColor blackColor];
  86. filePathNameTF.font = [UIFont systemFontOfSize:14.0];
  87. filePathNameTF.placeholder = NSLocalizedString(@"File_upload_path_new_input_tip",nil);
  88. filePathNameTF.delegate = self;
  89. filePathNameTF.returnKeyType = UIReturnKeyDone;
  90. [whiteBgView addSubview:filePathNameTF];
  91. [filePathNameTF setTintColor:[UIColor hwColor:@"#01B7EA" alpha:1.0]];
  92. UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 1)];
  93. filePathNameTF.leftView = leftView;
  94. filePathNameTF.leftViewMode = UITextFieldViewModeAlways;
  95. [filePathNameTF mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.right.mas_equalTo(-15);
  97. make.height.mas_equalTo(48);
  98. make.left.mas_equalTo(15);
  99. make.top.equalTo(tipLabel.mas_bottom).offset(15);
  100. }];
  101. canclButton = [[UIButton alloc] init];
  102. [canclButton setTitle:NSLocalizedString(@"other_cancel",nil) forState:UIControlStateNormal];
  103. [canclButton setTitleColor:[UIColor hwColor:@"#0A132B" alpha:1.0] forState:UIControlStateNormal];
  104. canclButton.backgroundColor = [UIColor hwColor:@"#E3E8F1" alpha:1.0];
  105. canclButton.layer.cornerRadius = 8;
  106. canclButton.tag = 1;
  107. [canclButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  108. [whiteBgView addSubview:canclButton];
  109. [canclButton mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.left.mas_equalTo(15.0);
  111. make.right.equalTo(whiteBgView.mas_centerX).offset(-10);
  112. make.height.mas_equalTo(40);
  113. make.bottom.mas_equalTo(-safeArea -10);
  114. }];
  115. okButton = [[UIButton alloc] init];
  116. okButton.tag = 2;
  117. [okButton setTitle:NSLocalizedString(@"other_comment_ok",nil) forState:UIControlStateNormal];
  118. okButton.titleLabel.font = [UIFont boldSystemFontOfSize:16.0];
  119. okButton.layer.cornerRadius = 8;
  120. okButton.layer.masksToBounds = YES;
  121. [okButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  122. [whiteBgView addSubview:okButton];
  123. // gradient
  124. CAGradientLayer* _glayer = [CAGradientLayer layer];
  125. _glayer.startPoint = CGPointMake(0, 0.5);
  126. _glayer.endPoint = CGPointMake(1, 0.5);
  127. _glayer.colors = @[(__bridge id)[UIColor hwColor:@"#0BDDFD" alpha:1.0].CGColor, (__bridge id)[UIColor hwColor:@"#048CFB" alpha:1.0].CGColor];
  128. _glayer.locations = @[@(0), @(1.0f)];
  129. [okButton.layer insertSublayer:_glayer atIndex:0];
  130. CGRect frame = CGRectMake(0, 0, SCREEN_W/2.0, 40);
  131. _glayer.frame = frame;
  132. [okButton mas_makeConstraints:^(MASConstraintMaker *make) {
  133. make.right.mas_equalTo(-15.0);
  134. make.left.equalTo(whiteBgView.mas_centerX).offset(10);
  135. make.height.mas_equalTo(40);
  136. make.bottom.mas_equalTo(-safeArea -10);
  137. }];
  138. }
  139. #pragma mark - 懒加载
  140. - (UITableView *)tableView{
  141. if (!_tableView) {
  142. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
  143. _tableView.delegate = self;
  144. _tableView.dataSource = self;
  145. _tableView.showsVerticalScrollIndicator = NO;
  146. _tableView.showsHorizontalScrollIndicator = NO;
  147. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  148. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  149. [_tableView setSeparatorColor:[UIColor clearColor]];
  150. [_tableView setBackgroundColor:[UIColor clearColor]];
  151. [_tableView setTableFooterView:[UIView new]];
  152. [_tableView setBounces:YES];
  153. _tableView.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0];
  154. _tableView.layer.cornerRadius = 8;
  155. _tableView.scrollEnabled = NO;
  156. if (@available(iOS 15.0, *)) {
  157. _tableView.sectionHeaderTopPadding = 0;
  158. }
  159. }
  160. return _tableView;
  161. }
  162. #pragma mark - 列表委托
  163. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  164. return 1;
  165. }
  166. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  167. return _curDataArr.count;
  168. }
  169. - (filePathCreatTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  170. __block NSInteger row = indexPath.row;
  171. static NSString *identifier = @"filePathCreatTableViewCell";
  172. filePathCreatTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  173. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  174. if (!cell){
  175. cell = [[filePathCreatTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  176. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  177. [cell setBackgroundColor:[UIColor clearColor]];
  178. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  179. [cell.bgViewLayer removeFromSuperlayer];
  180. [cell.titleLabel2 setHidden:NO];
  181. [cell.rightImage setHidden:YES];
  182. [cell.lineView setHidden:YES];
  183. [cell.checkButton setHidden:NO];
  184. }
  185. if(row < _curDataArr.count){
  186. cloudPhoneExtraFileModel *model = _curDataArr[row];
  187. cell.curModel = model;
  188. }
  189. // if (row == 0){
  190. // //[cell.titleLabel setText:NSLocalizedString(@"File_Transfer_set_Cellular",nil)];
  191. // cell.titleLabel.text = @"云机系统名称";
  192. //
  193. // cell.checkButton.selected = YES;
  194. //
  195. // }else if (row == 1){
  196. // //[cell.titleLabel setText:NSLocalizedString(@"File_Transfer_set_battery_level",nil)];
  197. //
  198. // cell.titleLabel.text = @"云机系统名称";
  199. //
  200. // }
  201. KWeakSelf
  202. cell.didClickSwitch = ^(BOOL SwitchOn) {
  203. [weakSelf setModelSelectInRow:row];
  204. };
  205. return cell;
  206. }
  207. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  208. return 70;
  209. }
  210. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  211. {
  212. return 40.0;
  213. }
  214. - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  215. {
  216. UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  217. //headView.backgroundColor = [UIColor greenColor];
  218. UILabel *titleLabel = [[UILabel alloc] init];
  219. titleLabel.text = NSLocalizedString(@"File_upload_path_new_check_tip",nil);
  220. titleLabel.font = [UIFont systemFontOfSize:14.0];
  221. titleLabel.textColor = [UIColor hwColor:@"#0A132B" alpha:1.0];
  222. [headView addSubview:titleLabel];
  223. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  224. make.left.mas_equalTo(15);
  225. make.right.mas_equalTo(-15);
  226. make.height.mas_equalTo(20);
  227. make.top.mas_equalTo(10);
  228. }];
  229. return headView;
  230. }
  231. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  232. NSString *beString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  233. if ([beString length] > 16) {
  234. textField.text = [beString substringToIndex:16];
  235. return NO;
  236. }
  237. return YES;
  238. }
  239. - (void)setModelSelectInRow:(NSInteger)row
  240. {
  241. for (int i=0; i<_curDataArr.count; i++) {
  242. cloudPhoneExtraFileModel *model = _curDataArr[i];
  243. model.isCheckType = NO;
  244. if(i == row){
  245. model.isCheckType = YES;
  246. _defaultSaveDiskStr = model.extraPath;
  247. }
  248. }
  249. if(row == 0){
  250. isCouldPhonePathType = YES;
  251. }
  252. else{
  253. isCouldPhonePathType = NO;
  254. }
  255. [self.tableView reloadData];
  256. }
  257. //- (void)setFileTransferType:(NSInteger)fileTransferType
  258. //{
  259. // _fileTransferType = fileTransferType;
  260. //
  261. // NSString *uploadTitle = NSLocalizedString(@"File_upload_type_image",nil);
  262. // NSString *uploadTip = NSLocalizedString(@"File_upload_type_tip",nil);
  263. //
  264. // NSString *downloadTitle = NSLocalizedString(@"File_down_type_image",nil);
  265. // NSString *downloadTip = NSLocalizedString(@"File_down_type_tip",nil);
  266. //
  267. // if(fileTransferType == 2)
  268. // {
  269. // uploadTitle = NSLocalizedString(@"File_upload_type_video",nil);
  270. // downloadTitle = NSLocalizedString(@"File_down_type_video",nil);
  271. // }
  272. //
  273. // UILabel *uploadLabel = [[UILabel alloc] init];
  274. // uploadLabel.textColor = [UIColor whiteColor];
  275. // uploadLabel.font = [UIFont boldSystemFontOfSize:18.0];
  276. // uploadLabel.numberOfLines = 0;
  277. // [uploadButton addSubview:uploadLabel];
  278. //
  279. // NSString *totalStr = [[NSString alloc] initWithFormat:@"%@\n%@",uploadTitle,uploadTip];
  280. //
  281. // NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  282. //
  283. // NSRange redRange = NSMakeRange([totalStr rangeOfString:uploadTip].location, [totalStr rangeOfString:uploadTip].length);
  284. // [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#FFFFFF" alpha:0.8] range:redRange];
  285. // [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:redRange];
  286. // // 设置行间距
  287. // NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  288. // [paragraphStyle setLineSpacing:5]; //设置行间距
  289. //
  290. // [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  291. //
  292. // uploadLabel.attributedText = noteStr;
  293. //
  294. // [uploadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  295. // make.left.mas_equalTo(15);
  296. // make.right.mas_equalTo(-15);
  297. // make.bottom.mas_equalTo(0);
  298. // make.top.mas_equalTo(0);
  299. // }];
  300. //
  301. // UILabel *downloadLabel = [[UILabel alloc] init];
  302. // downloadLabel.textColor = [UIColor whiteColor];
  303. // downloadLabel.font = [UIFont boldSystemFontOfSize:18.0];
  304. // downloadLabel.numberOfLines = 0;
  305. // [downButton addSubview:downloadLabel];
  306. //
  307. // NSString *downTotalStr = [[NSString alloc] initWithFormat:@"%@\n%@",downloadTitle,downloadTip];
  308. //
  309. // NSMutableAttributedString *downNoteStr = [[NSMutableAttributedString alloc] initWithString:downTotalStr];
  310. //
  311. // NSRange downredRange = NSMakeRange([downTotalStr rangeOfString:downloadTip].location, [downTotalStr rangeOfString:downloadTip].length);
  312. // [downNoteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#FFFFFF" alpha:0.8] range:downredRange];
  313. // [downNoteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:downredRange];
  314. // // 设置行间距
  315. //// NSMutableParagraphStyle *paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
  316. //// [paragraphStyle1 setLineSpacing:5]; //设置行间距
  317. //
  318. // [downNoteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [downTotalStr length])];
  319. //
  320. // downloadLabel.attributedText = downNoteStr;
  321. //
  322. // [downloadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  323. // make.left.mas_equalTo(15);
  324. // make.right.mas_equalTo(-15);
  325. // make.bottom.mas_equalTo(0);
  326. // make.top.mas_equalTo(0);
  327. // }];
  328. //}
  329. - (void)setOutSizeArr:(NSArray *)outSizeArr
  330. {
  331. NSMutableArray *arr = [NSMutableArray new];
  332. if(outSizeArr && outSizeArr.count >0){
  333. for (cloudPhoneExtraFileModel*model in outSizeArr) {
  334. model.isCheckType = NO;
  335. [arr addObject:model];
  336. }
  337. //[arr addObjectsFromArray:outSizeArr];
  338. }
  339. // cloudPhoneExtraFileModel *defModel = [cloudPhoneExtraFileModel new];
  340. // //defModel
  341. // defModel.extraPath = @"sdcard";
  342. // //defModel.extraTotalSize = ksharedAppDelegate.couldPhoneBaseInfoMod;
  343. //
  344. // [arr insertObject:defModel atIndex:0];
  345. //设置默认的选中
  346. cloudPhoneExtraFileModel *defModel = arr.firstObject;
  347. defModel.isCheckType = YES;
  348. _defaultSaveDiskStr = defModel.extraPath;
  349. isCouldPhonePathType = YES;
  350. NSInteger tableRowHeight = 70;
  351. NSInteger allRow = arr.count;
  352. [whiteBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  353. make.left.mas_equalTo(0);
  354. make.right.mas_equalTo(0);
  355. make.height.mas_equalTo(278 +tableRowHeight*allRow + 10 + safeArea);
  356. //make.height.mas_equalTo(418+ 10 + safeArea);
  357. make.bottom.mas_equalTo(10);
  358. }];
  359. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  360. make.left.mas_equalTo(15);
  361. make.right.mas_equalTo(-15);
  362. make.height.mas_equalTo(tableRowHeight*allRow +50);
  363. //make.height.mas_equalTo(0.0);
  364. make.top.equalTo(titleLabel.mas_bottom).offset(15.f);
  365. }];
  366. _curDataArr = arr;
  367. [self.tableView reloadData];
  368. }
  369. - (void)tapUpFun:(UITapGestureRecognizer*)tap
  370. {
  371. //[self deleteFromSuperview];
  372. }
  373. - (void)deleteFromSuperview
  374. {
  375. [self removeFromSuperview];
  376. }
  377. - (void)didClickButtonFun:(UIButton*)button
  378. {
  379. NSInteger tag = button.tag;
  380. if(tag == 1){
  381. [self deleteFromSuperview];
  382. }
  383. else if(tag == 2){
  384. if(!_defaultSaveDiskStr ||_defaultSaveDiskStr.length ==0){
  385. //[[iToast makeText:NSLocalizedString(@"File_upload_path_new_input_tip",nil)] show];
  386. return;
  387. }
  388. NSString* folderName = [filePathNameTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  389. //去掉中间空格
  390. folderName = [folderName stringByReplacingOccurrencesOfString:@" " withString:@""];
  391. folderName = [folderName stringByReplacingOccurrencesOfString:@" " withString:@""];
  392. if(!folderName || folderName.length ==0){
  393. [[iToast makeText:NSLocalizedString(@"File_upload_path_new_input_tip",nil)] show];
  394. return;
  395. }
  396. if(isCouldPhonePathType
  397. && ([folderName isEqualToString:@"Download"]
  398. ||[folderName isEqualToString:@"download"])){
  399. [[iToast makeText:NSLocalizedString(@"File_creat_def_path_error_tip",nil)] show];
  400. return;
  401. }
  402. [self deleteFromSuperview];
  403. if(_didClickOkBut)
  404. {
  405. _didClickOkBut(folderName,_defaultSaveDiskStr);
  406. }
  407. }
  408. }
  409. @end