downLoadPreviewViewController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. //
  2. // downLoadPreviewViewController.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/7.
  6. //
  7. #import "downLoadPreviewViewController.h"
  8. #import "couldPhoneFileListModel.h"
  9. #import "downLoadPreViewCell.h"
  10. #import "downloadFileBottomView.h"
  11. #import "downloadThumbnailManager.h"
  12. #import "downloadManager.h"
  13. #import "uploadFileRecordViewController.h"
  14. #import "UIScrollView+EmptyDataSet.h"
  15. #import "diskListBgView.h"
  16. #import "diskListTableView.h"
  17. @interface downLoadPreviewViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  18. {
  19. UIButton *tapBtn;
  20. }
  21. @property (nonatomic, strong) UITableView *tableView;
  22. @property (strong, nonatomic) UILabel *MytitleLabel;
  23. @property (strong, nonatomic) UIImageView *selectTip;
  24. @property (nonatomic, strong) UIButton *rightButton;
  25. @property (nonatomic, strong) diskListBgView *diskListBgV;
  26. @property (nonatomic, strong) diskListTableView *diskListTableV;
  27. @property (nonatomic, strong) NSMutableArray*diskListArr;
  28. @property (nonatomic, copy) NSString *defaultDiskPath;
  29. @property (nonatomic, strong) downloadFileBottomView *downloadFileBottomV;
  30. @property(nonatomic,strong) couldPhoneFileListModel *curCouldPhoneFileListMod;
  31. @end
  32. @implementation downLoadPreviewViewController
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. // Do any additional setup after loading the view.
  36. [self.toolBar setHidden:YES];
  37. [self.navigationBar setHidden:YES];
  38. [self.navBarBGView setHidden:NO];
  39. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  40. [self.view setBackgroundColor:[UIColor whiteColor]];
  41. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(searchFileListDoneFun:) name:searchFileListDoneNotification object:nil];
  42. [self drawAnyView];
  43. }
  44. - (void)drawAnyView{
  45. [self initNavHeadUIFun];
  46. [self.view addSubview:self.tableView];
  47. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.mas_equalTo(0);
  49. make.right.mas_equalTo(0);
  50. make.bottom.mas_equalTo(-(60 + safeArea));
  51. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  52. }];
  53. _downloadFileBottomV = [[downloadFileBottomView alloc] init];
  54. [self.view insertSubview:_downloadFileBottomV atIndex:0];
  55. [_downloadFileBottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.mas_equalTo(0);
  57. make.right.mas_equalTo(0);
  58. make.bottom.mas_equalTo(0);
  59. make.height.mas_equalTo(60 + safeArea);
  60. }];
  61. [self RefreshBottomViewUIFun];
  62. KWeakSelf
  63. _downloadFileBottomV.didClickDownloadFile = ^{
  64. [weakSelf gotoDownloadloadFileRecordFun];
  65. };
  66. NSMutableArray *arr = [NSMutableArray new];
  67. NSArray *diskList = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  68. if(diskList && [diskList isKindOfClass:[NSArray class]]){
  69. for (cloudPhoneExtraFileModel *model in diskList) {
  70. model.isCheckType = NO;
  71. [arr addObject:model];
  72. }
  73. }
  74. if(arr.count >0){
  75. cloudPhoneExtraFileModel *model = arr.firstObject;
  76. model.isCheckType = YES;
  77. _defaultDiskPath = model.extraPath;
  78. }
  79. _diskListArr = arr;
  80. [self setTitleAfterGetdiskFun];
  81. }
  82. - (void)initNavHeadUIFun
  83. {
  84. //title
  85. UILabel *titleLabel = [[UILabel alloc] init];
  86. titleLabel.textAlignment = NSTextAlignmentCenter;
  87. titleLabel.font = [UIFont boldSystemFontOfSize:18.0];
  88. titleLabel.textColor = [UIColor blackColor];
  89. titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
  90. [self.navBarBGView addSubview:titleLabel];
  91. self.MytitleLabel = titleLabel;
  92. //selectTipImageView
  93. UIImageView *selectTip = [[UIImageView alloc] init];
  94. selectTip.image = [UIImage imageNamed:@"upload_image_arrow"];
  95. selectTip.translatesAutoresizingMaskIntoConstraints = NO;
  96. [self.navBarBGView addSubview:selectTip];
  97. self.selectTip = selectTip;
  98. tapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  99. tapBtn.backgroundColor = [UIColor clearColor];
  100. tapBtn.translatesAutoresizingMaskIntoConstraints = NO;
  101. [tapBtn addTarget:self action:@selector(selectDiskAction:) forControlEvents:UIControlEventTouchUpInside];
  102. [self.navBarBGView addSubview:tapBtn];
  103. [tapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  105. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  106. make.width.mas_equalTo(100);
  107. make.height.mas_equalTo(30);
  108. }];
  109. [self setTitleLabelText:@""];
  110. _rightButton = [[UIButton alloc] init];
  111. [_rightButton setTitle:NSLocalizedString(@"File_upload_Record_select_all",nil) forState:UIControlStateNormal];
  112. [_rightButton setTitle:NSLocalizedString(@"File_upload_cancel_select_all",nil) forState:UIControlStateSelected];
  113. [_rightButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  114. _rightButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
  115. _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  116. [_rightButton addTarget:self action:@selector(didClickSelectAllButton:) forControlEvents:UIControlEventTouchUpInside];
  117. [self.navBarBGView addSubview:_rightButton];
  118. //多国语言适配
  119. NSString *languageCode = [NSLocale preferredLanguages][0];
  120. if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
  121. {
  122. _rightButton.titleLabel.font = [UIFont systemFontOfSize:13.0];
  123. }
  124. [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.width.mas_equalTo(90);
  126. make.height.mas_equalTo(40);
  127. make.right.mas_equalTo(-15);
  128. make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  129. }];
  130. //_rightButton.backgroundColor = [UIColor redColor];
  131. }
  132. #pragma mark - 懒加载
  133. - (UITableView *)tableView{
  134. if (!_tableView) {
  135. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain];
  136. _tableView.delegate = self;
  137. _tableView.dataSource = self;
  138. _tableView.showsVerticalScrollIndicator = NO;
  139. _tableView.showsHorizontalScrollIndicator = NO;
  140. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  141. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  142. [_tableView setSeparatorColor:[UIColor clearColor]];
  143. [_tableView setBackgroundColor:[UIColor clearColor]];
  144. [_tableView setTableFooterView:[UIView new]];
  145. [_tableView setBounces:YES];
  146. if (@available(iOS 15.0, *)) {
  147. _tableView.sectionHeaderTopPadding = 0;
  148. }
  149. //空数据引入第三方开源处理
  150. _tableView.emptyDataSetSource = self;
  151. _tableView.emptyDataSetDelegate = self;
  152. }
  153. return _tableView;
  154. }
  155. - (diskListBgView*)diskListBgV
  156. {
  157. if(!_diskListBgV){
  158. _diskListBgV = [[diskListBgView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
  159. _diskListBgV.hidden = YES;
  160. [self.view addSubview:_diskListBgV];
  161. KWeakSelf
  162. _diskListBgV.didTapWhitePlace = ^{
  163. [weakSelf hideDiskListVieFun];
  164. };
  165. [_diskListBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  166. make.left.mas_equalTo(0);
  167. make.bottom.mas_equalTo(0);
  168. make.right.mas_equalTo(0);
  169. make.top.mas_equalTo(self.navBarBGView.mas_bottom);
  170. }];
  171. [self.view addSubview:self.diskListTableV];
  172. self.diskListTableV.hidden = YES;
  173. [self.diskListTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  174. make.left.mas_equalTo(0);
  175. make.height.mas_equalTo(3*70);
  176. make.right.mas_equalTo(0);
  177. make.top.mas_equalTo(self.navBarBGView.mas_bottom);
  178. }];
  179. self.diskListTableV.diskListArr = _diskListArr;
  180. self.diskListTableV.didClickDiskModel = ^(NSString * _Nonnull checkPath) {
  181. [weakSelf didCheckDiskFunByPath:checkPath];
  182. };
  183. }
  184. return _diskListBgV;
  185. }
  186. - (UITableView *)diskListTableV{
  187. if (!_diskListTableV) {
  188. _diskListTableV = [[diskListTableView alloc] init];
  189. //
  190. }
  191. return _diskListTableV;
  192. }
  193. #pragma mark 选中磁盘
  194. - (void)didCheckDiskFunByPath:(NSString*)pathStr
  195. {
  196. self.defaultDiskPath = pathStr;
  197. //[self searchFileListFun];
  198. [self setTitleAfterGetdiskFun];
  199. [self hideDiskListVieFun];
  200. }
  201. #pragma mark - 列表委托
  202. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  203. return 1;
  204. }
  205. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  206. if(!_curCouldPhoneFileListMod){
  207. return 0;
  208. }
  209. return _curCouldPhoneFileListMod.data.list.count;
  210. }
  211. - (downLoadPreViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  212. __block NSInteger row = indexPath.row;
  213. static NSString *identifier = @"downLoadPreViewCell";
  214. downLoadPreViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  215. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  216. if (!cell){
  217. cell = [[downLoadPreViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  218. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  219. [cell setBackgroundColor:[UIColor clearColor]];
  220. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  221. [cell.bgViewLayer removeFromSuperlayer];
  222. [cell.titleLabel2 setHidden:NO];
  223. [cell.rightImage setHidden:YES];
  224. [cell.lineView setHidden:YES];
  225. [cell.checkButton setHidden:NO];
  226. }
  227. if(row < _curCouldPhoneFileListMod.data.list.count){
  228. couldPhoneFileModel* fileModel = _curCouldPhoneFileListMod.data.list[row];
  229. cell.curFileModel = fileModel;
  230. }
  231. KWeakSelf
  232. cell.didClickSwitch = ^(BOOL SwitchOn) {
  233. [weakSelf userCheckFilePreviewByRow:row];
  234. };
  235. return cell;
  236. }
  237. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  238. return 70;
  239. }
  240. #pragma mark 空数据
  241. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  242. NSString *imageName = @"uploadFile_noData";
  243. return [UIImage imageNamed:imageName];
  244. }
  245. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  246. NSString *text = NSLocalizedString(@"File_download_file_no_data",nil);
  247. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  248. NSForegroundColorAttributeName: HW999999Color};
  249. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  250. }
  251. //调整图片位置
  252. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  253. return -150;
  254. }
  255. - (void)userCheckFilePreviewByRow:(NSInteger)row
  256. {
  257. if(row < _curCouldPhoneFileListMod.data.list.count){
  258. couldPhoneFileModel* fileModel = _curCouldPhoneFileListMod.data.list[row];
  259. fileModel.isSelectType = !fileModel.isSelectType;
  260. [self.tableView reloadData];
  261. [self RefreshBottomViewUIFun];
  262. }
  263. }
  264. - (void)didClickSelectAllButton:(UIButton*)button
  265. {
  266. button.selected = !button.selected;
  267. for (couldPhoneFileModel* fileModel in _curCouldPhoneFileListMod.data.list) {
  268. fileModel.isSelectType = button.selected;
  269. }
  270. [self.tableView reloadData];
  271. [self RefreshBottomViewUIFun];
  272. }
  273. #pragma mark 设置标题
  274. - (void)setTitleLabelText:(NSString*)title
  275. {
  276. NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  277. if(diskNameArr && diskNameArr.count >= 2){
  278. NSString *name = diskNameArr.lastObject;
  279. if(name.length == 0)
  280. {
  281. name = diskNameArr[diskNameArr.count -2];
  282. }
  283. title = [[NSString alloc] initWithFormat:@"[%@]%@",name,title];
  284. }
  285. self.MytitleLabel.text = title;
  286. CGFloat curWidth = [title boundingRectWithSize:CGSizeMake(SCREEN_W, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18.f]} context:nil].size.width;
  287. curWidth += 20;
  288. //HLog(@"title w:%f",curWidth);
  289. [self.MytitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  290. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX).offset(-10);
  291. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  292. make.width.mas_equalTo(curWidth);
  293. make.height.mas_equalTo(30);
  294. }];
  295. //self.MytitleLabel.backgroundColor = [UIColor greenColor];
  296. [self.selectTip mas_makeConstraints:^(MASConstraintMaker *make) {
  297. make.left.mas_equalTo(self.MytitleLabel.mas_right).offset(0);
  298. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  299. make.width.mas_equalTo(15);
  300. make.height.mas_equalTo(15);
  301. }];
  302. [tapBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  303. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  304. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  305. make.width.mas_equalTo(curWidth+15);
  306. make.height.mas_equalTo(30);
  307. }];
  308. }
  309. #pragma mark 选择硬盘
  310. - (void)selectDiskAction:(UIButton*)but
  311. {
  312. if(self.diskListBgV.hidden){
  313. [self showDiskListVieFun];
  314. }
  315. else{
  316. [self hideDiskListVieFun];
  317. }
  318. }
  319. - (void)showDiskListVieFun
  320. {
  321. self.diskListBgV.hidden = NO;
  322. self.diskListTableV.hidden = NO;
  323. [UIView animateWithDuration:0.3 animations:^{
  324. CGRect rect = self.diskListTableV.frame;
  325. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  326. self.diskListTableV.frame = rect;
  327. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  328. }];
  329. }
  330. - (void)hideDiskListVieFun
  331. {
  332. self.diskListBgV.hidden = YES;
  333. [UIView animateWithDuration:0.3 animations:^{
  334. self.diskListTableV.hidden = YES;
  335. self.selectTip.transform = CGAffineTransformIdentity;
  336. }completion:^(BOOL finished) {
  337. CGRect rect = self.diskListTableV.frame;
  338. rect.origin.y = 0;
  339. self.diskListTableV.frame = rect;
  340. }];
  341. }
  342. #pragma mark 刷新底部
  343. - (void)RefreshBottomViewUIFun
  344. {
  345. NSMutableArray *selectArr = [NSMutableArray new];
  346. for (couldPhoneFileModel* fileModel in _curCouldPhoneFileListMod.data.list) {
  347. if(fileModel.isSelectType){
  348. [selectArr addObject:fileModel];
  349. }
  350. }
  351. _downloadFileBottomV.indexPathsForSelectedItems = selectArr;
  352. }
  353. #pragma mark 设置标题
  354. - (void)setTitleAfterGetdiskFun
  355. {
  356. if(_isPhotoType){
  357. //self.titleLabel.text = NSLocalizedString(@"my_set_no_image_upload",nil) ;
  358. [self setTitleLabelText:NSLocalizedString(@"my_set_no_image_upload",nil)];
  359. }
  360. else{
  361. //self.titleLabel.text = NSLocalizedString(@"my_set_no_video_upload",nil) ;
  362. [self setTitleLabelText:NSLocalizedString(@"my_set_no_video_upload",nil)];
  363. }
  364. [self searchFileListFun];
  365. }
  366. - (void)viewWillAppear:(BOOL)animated
  367. {
  368. [super viewWillAppear:animated];
  369. }
  370. - (void)searchFileListFun
  371. {
  372. NSMutableDictionary *dict = [NSMutableDictionary new];
  373. NSNumber *curNum = [NSNumber numberWithBool:_isPhotoType];
  374. [dict setObject:curNum forKey:@"type"];
  375. if(!_defaultDiskPath){
  376. _defaultDiskPath = @"";
  377. }
  378. [dict setObject:_defaultDiskPath forKey:@"path"];
  379. [[NSNotificationCenter defaultCenter] postNotificationName:searchFileListBeginNotification object:dict];/*发送通知*/
  380. }
  381. - (void)searchFileListDoneFun:(NSNotification*)notification
  382. {
  383. NSDictionary *dataDict = [notification object];
  384. if(!dataDict || ![dataDict isKindOfClass:[NSDictionary class]]){
  385. return;
  386. }
  387. _curCouldPhoneFileListMod = [[couldPhoneFileListModel alloc] initWithDictionary:dataDict error:nil];
  388. NSMutableArray *filterArr = [NSMutableArray new];
  389. for (couldPhoneFileModel*model in _curCouldPhoneFileListMod.data.list) {
  390. //if(model.length > 1024)
  391. if(model.length > 1024*50)
  392. {
  393. [filterArr addObject:model];
  394. }
  395. }
  396. _curCouldPhoneFileListMod.data.list = filterArr;
  397. [self.tableView reloadData];
  398. //这个要做判断 不能为空
  399. //[self gotoDownThumbnailManagerFun];
  400. }
  401. #pragma mark 去下载缩略图
  402. - (void)gotoDownThumbnailManagerFun
  403. {
  404. [[downloadThumbnailManager shareInstance] handlToDownloadThumbnailWith:_curCouldPhoneFileListMod.data.list];
  405. }
  406. - (void)gotoDownloadloadFileRecordFun
  407. {
  408. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  409. [self.navigationController pushViewController:vc animated:YES];
  410. vc.isDownloadingType = YES;
  411. [vc gotoDownloadFile:_downloadFileBottomV.indexPathsForSelectedItems];
  412. }
  413. - (void)viewDidAppear:(BOOL)animated{
  414. [super viewDidAppear:animated];
  415. [self showDownloadTipFun];
  416. }
  417. - (void)showDownloadTipFun
  418. {
  419. BOOL didReadUploadTipType = [HWDataManager getBoolWithKey:Const_file_downLoad_need_read];
  420. if(didReadUploadTipType){
  421. return;
  422. }
  423. //KWeakSelf
  424. /*弹窗提示恢复出厂*/
  425. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:nil
  426. msg:NSLocalizedString(@"upload_download_need_read_msg",nil)
  427. imageStr:nil
  428. cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
  429. okTitle:nil
  430. isOkBtnHighlight:NO
  431. didClickOk:^{
  432. } didClickCancel:^{
  433. [HWDataManager setBoolWithKey:Const_file_downLoad_need_read value:YES];
  434. }];
  435. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  436. [self presentViewController:nextVC animated:YES completion:^{
  437. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  438. }];
  439. }
  440. @end