filePathCreatPopView.m 16 KB

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