filePathCreatPopView.m 17 KB

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