filePathCreatPopView.m 17 KB

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