filePathCreatPopView.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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,strong) 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. - (BOOL)textFieldShouldReturn:(UITextField *)textField{
  240. [textField resignFirstResponder];
  241. return YES;
  242. }
  243. - (void)setModelSelectInRow:(NSInteger)row
  244. {
  245. for (int i=0; i<_curDataArr.count; i++) {
  246. cloudPhoneExtraFileModel *model = _curDataArr[i];
  247. model.isCheckType = NO;
  248. if(i == row){
  249. model.isCheckType = YES;
  250. _defaultSaveDiskStr = model.extraPath;
  251. }
  252. }
  253. if(row == 0){
  254. isCouldPhonePathType = YES;
  255. }
  256. else{
  257. isCouldPhonePathType = NO;
  258. }
  259. [self.tableView reloadData];
  260. }
  261. //- (void)setFileTransferType:(NSInteger)fileTransferType
  262. //{
  263. // _fileTransferType = fileTransferType;
  264. //
  265. // NSString *uploadTitle = NSLocalizedString(@"File_upload_type_image",nil);
  266. // NSString *uploadTip = NSLocalizedString(@"File_upload_type_tip",nil);
  267. //
  268. // NSString *downloadTitle = NSLocalizedString(@"File_down_type_image",nil);
  269. // NSString *downloadTip = NSLocalizedString(@"File_down_type_tip",nil);
  270. //
  271. // if(fileTransferType == 2)
  272. // {
  273. // uploadTitle = NSLocalizedString(@"File_upload_type_video",nil);
  274. // downloadTitle = NSLocalizedString(@"File_down_type_video",nil);
  275. // }
  276. //
  277. // UILabel *uploadLabel = [[UILabel alloc] init];
  278. // uploadLabel.textColor = [UIColor whiteColor];
  279. // uploadLabel.font = [UIFont boldSystemFontOfSize:18.0];
  280. // uploadLabel.numberOfLines = 0;
  281. // [uploadButton addSubview:uploadLabel];
  282. //
  283. // NSString *totalStr = [[NSString alloc] initWithFormat:@"%@\n%@",uploadTitle,uploadTip];
  284. //
  285. // NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  286. //
  287. // NSRange redRange = NSMakeRange([totalStr rangeOfString:uploadTip].location, [totalStr rangeOfString:uploadTip].length);
  288. // [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#FFFFFF" alpha:0.8] range:redRange];
  289. // [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:redRange];
  290. // // 设置行间距
  291. // NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  292. // [paragraphStyle setLineSpacing:5]; //设置行间距
  293. //
  294. // [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  295. //
  296. // uploadLabel.attributedText = noteStr;
  297. //
  298. // [uploadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  299. // make.left.mas_equalTo(15);
  300. // make.right.mas_equalTo(-15);
  301. // make.bottom.mas_equalTo(0);
  302. // make.top.mas_equalTo(0);
  303. // }];
  304. //
  305. // UILabel *downloadLabel = [[UILabel alloc] init];
  306. // downloadLabel.textColor = [UIColor whiteColor];
  307. // downloadLabel.font = [UIFont boldSystemFontOfSize:18.0];
  308. // downloadLabel.numberOfLines = 0;
  309. // [downButton addSubview:downloadLabel];
  310. //
  311. // NSString *downTotalStr = [[NSString alloc] initWithFormat:@"%@\n%@",downloadTitle,downloadTip];
  312. //
  313. // NSMutableAttributedString *downNoteStr = [[NSMutableAttributedString alloc] initWithString:downTotalStr];
  314. //
  315. // NSRange downredRange = NSMakeRange([downTotalStr rangeOfString:downloadTip].location, [downTotalStr rangeOfString:downloadTip].length);
  316. // [downNoteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#FFFFFF" alpha:0.8] range:downredRange];
  317. // [downNoteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:downredRange];
  318. // // 设置行间距
  319. //// NSMutableParagraphStyle *paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
  320. //// [paragraphStyle1 setLineSpacing:5]; //设置行间距
  321. //
  322. // [downNoteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [downTotalStr length])];
  323. //
  324. // downloadLabel.attributedText = downNoteStr;
  325. //
  326. // [downloadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  327. // make.left.mas_equalTo(15);
  328. // make.right.mas_equalTo(-15);
  329. // make.bottom.mas_equalTo(0);
  330. // make.top.mas_equalTo(0);
  331. // }];
  332. //}
  333. - (void)setOutSizeArr:(NSArray *)outSizeArr
  334. {
  335. NSMutableArray *arr = [NSMutableArray new];
  336. if(outSizeArr && outSizeArr.count >0){
  337. for (cloudPhoneExtraFileModel*model in outSizeArr) {
  338. model.isCheckType = NO;
  339. [arr addObject:model];
  340. }
  341. //[arr addObjectsFromArray:outSizeArr];
  342. }
  343. // cloudPhoneExtraFileModel *defModel = [cloudPhoneExtraFileModel new];
  344. // //defModel
  345. // defModel.extraPath = @"sdcard";
  346. // //defModel.extraTotalSize = ksharedAppDelegate.couldPhoneBaseInfoMod;
  347. //
  348. // [arr insertObject:defModel atIndex:0];
  349. //设置默认的选中
  350. cloudPhoneExtraFileModel *defModel = arr.firstObject;
  351. defModel.isCheckType = YES;
  352. _defaultSaveDiskStr = defModel.extraPath;
  353. isCouldPhonePathType = YES;
  354. NSInteger tableRowHeight = 70;
  355. NSInteger allRow = arr.count;
  356. [whiteBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  357. make.left.mas_equalTo(0);
  358. make.right.mas_equalTo(0);
  359. make.height.mas_equalTo(278 +tableRowHeight*allRow + 10 + safeArea);
  360. //make.height.mas_equalTo(418+ 10 + safeArea);
  361. make.bottom.mas_equalTo(10);
  362. }];
  363. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  364. make.left.mas_equalTo(15);
  365. make.right.mas_equalTo(-15);
  366. make.height.mas_equalTo(tableRowHeight*allRow +50);
  367. //make.height.mas_equalTo(0.0);
  368. make.top.equalTo(titleLabel.mas_bottom).offset(15.f);
  369. }];
  370. _curDataArr = arr;
  371. [self.tableView reloadData];
  372. }
  373. - (void)tapUpFun:(UITapGestureRecognizer*)tap
  374. {
  375. //[self deleteFromSuperview];
  376. }
  377. - (void)deleteFromSuperview
  378. {
  379. [self removeFromSuperview];
  380. }
  381. - (void)didClickButtonFun:(UIButton*)button
  382. {
  383. NSInteger tag = button.tag;
  384. if(tag == 1){
  385. [self deleteFromSuperview];
  386. }
  387. else if(tag == 2){
  388. if(!_defaultSaveDiskStr ||_defaultSaveDiskStr.length ==0){
  389. //[[iToast makeText:NSLocalizedString(@"File_upload_path_new_input_tip",nil)] show];
  390. return;
  391. }
  392. NSString* folderName = [filePathNameTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  393. //去掉中间空格
  394. folderName = [folderName stringByReplacingOccurrencesOfString:@" " withString:@""];
  395. folderName = [folderName stringByReplacingOccurrencesOfString:@" " withString:@""];
  396. if(!folderName || folderName.length ==0){
  397. [[iToast makeText:NSLocalizedString(@"File_upload_path_new_input_tip",nil)] show];
  398. return;
  399. }
  400. if(isCouldPhonePathType
  401. && ([folderName isEqualToString:@"Download"]
  402. ||[folderName isEqualToString:@"download"])){
  403. [[iToast makeText:NSLocalizedString(@"File_creat_def_path_error_tip",nil)] show];
  404. return;
  405. }
  406. [self deleteFromSuperview];
  407. if(_didClickOkBut)
  408. {
  409. _didClickOkBut(folderName,_defaultSaveDiskStr);
  410. }
  411. }
  412. }
  413. @end