downLoadPreviewViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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. [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  119. make.width.mas_equalTo(90);
  120. make.height.mas_equalTo(40);
  121. make.right.mas_equalTo(-15);
  122. make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  123. }];
  124. //_rightButton.backgroundColor = [UIColor redColor];
  125. }
  126. #pragma mark - 懒加载
  127. - (UITableView *)tableView{
  128. if (!_tableView) {
  129. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain];
  130. _tableView.delegate = self;
  131. _tableView.dataSource = self;
  132. _tableView.showsVerticalScrollIndicator = NO;
  133. _tableView.showsHorizontalScrollIndicator = NO;
  134. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  135. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  136. [_tableView setSeparatorColor:[UIColor clearColor]];
  137. [_tableView setBackgroundColor:[UIColor clearColor]];
  138. [_tableView setTableFooterView:[UIView new]];
  139. [_tableView setBounces:YES];
  140. if (@available(iOS 15.0, *)) {
  141. _tableView.sectionHeaderTopPadding = 0;
  142. }
  143. //空数据引入第三方开源处理
  144. _tableView.emptyDataSetSource = self;
  145. _tableView.emptyDataSetDelegate = self;
  146. }
  147. return _tableView;
  148. }
  149. - (diskListBgView*)diskListBgV
  150. {
  151. if(!_diskListBgV){
  152. _diskListBgV = [[diskListBgView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
  153. _diskListBgV.hidden = YES;
  154. [self.view addSubview:_diskListBgV];
  155. KWeakSelf
  156. _diskListBgV.didTapWhitePlace = ^{
  157. [weakSelf hideDiskListVieFun];
  158. };
  159. [_diskListBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  160. make.left.mas_equalTo(0);
  161. make.bottom.mas_equalTo(0);
  162. make.right.mas_equalTo(0);
  163. make.top.mas_equalTo(self.navBarBGView.mas_bottom);
  164. }];
  165. [self.view addSubview:self.diskListTableV];
  166. self.diskListTableV.hidden = YES;
  167. [self.diskListTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  168. make.left.mas_equalTo(0);
  169. make.height.mas_equalTo(3*70);
  170. make.right.mas_equalTo(0);
  171. make.top.mas_equalTo(self.navBarBGView.mas_bottom);
  172. }];
  173. self.diskListTableV.diskListArr = _diskListArr;
  174. self.diskListTableV.didClickDiskModel = ^(NSString * _Nonnull checkPath) {
  175. [weakSelf didCheckDiskFunByPath:checkPath];
  176. };
  177. }
  178. return _diskListBgV;
  179. }
  180. - (UITableView *)diskListTableV{
  181. if (!_diskListTableV) {
  182. _diskListTableV = [[diskListTableView alloc] init];
  183. //
  184. }
  185. return _diskListTableV;
  186. }
  187. #pragma mark 选中磁盘
  188. - (void)didCheckDiskFunByPath:(NSString*)pathStr
  189. {
  190. self.defaultDiskPath = pathStr;
  191. //[self searchFileListFun];
  192. [self setTitleAfterGetdiskFun];
  193. [self hideDiskListVieFun];
  194. }
  195. #pragma mark - 列表委托
  196. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  197. return 1;
  198. }
  199. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  200. if(!_curCouldPhoneFileListMod){
  201. return 0;
  202. }
  203. return _curCouldPhoneFileListMod.data.list.count;
  204. }
  205. - (downLoadPreViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  206. __block NSInteger row = indexPath.row;
  207. static NSString *identifier = @"downLoadPreViewCell";
  208. downLoadPreViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  209. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  210. if (!cell){
  211. cell = [[downLoadPreViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  212. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  213. [cell setBackgroundColor:[UIColor clearColor]];
  214. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  215. [cell.bgViewLayer removeFromSuperlayer];
  216. [cell.titleLabel2 setHidden:NO];
  217. [cell.rightImage setHidden:YES];
  218. [cell.lineView setHidden:YES];
  219. [cell.checkButton setHidden:NO];
  220. }
  221. if(row < _curCouldPhoneFileListMod.data.list.count){
  222. couldPhoneFileModel* fileModel = _curCouldPhoneFileListMod.data.list[row];
  223. cell.curFileModel = fileModel;
  224. }
  225. KWeakSelf
  226. cell.didClickSwitch = ^(BOOL SwitchOn) {
  227. [weakSelf userCheckFilePreviewByRow:row];
  228. };
  229. return cell;
  230. }
  231. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  232. return 70;
  233. }
  234. #pragma mark 空数据
  235. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  236. NSString *imageName = @"uploadFile_noData";
  237. return [UIImage imageNamed:imageName];
  238. }
  239. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  240. NSString *text = NSLocalizedString(@"File_download_file_no_data",nil);
  241. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  242. NSForegroundColorAttributeName: HW999999Color};
  243. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  244. }
  245. //调整图片位置
  246. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  247. return -150;
  248. }
  249. - (void)userCheckFilePreviewByRow:(NSInteger)row
  250. {
  251. if(row < _curCouldPhoneFileListMod.data.list.count){
  252. couldPhoneFileModel* fileModel = _curCouldPhoneFileListMod.data.list[row];
  253. fileModel.isSelectType = !fileModel.isSelectType;
  254. [self.tableView reloadData];
  255. [self RefreshBottomViewUIFun];
  256. }
  257. }
  258. - (void)didClickSelectAllButton:(UIButton*)button
  259. {
  260. button.selected = !button.selected;
  261. for (couldPhoneFileModel* fileModel in _curCouldPhoneFileListMod.data.list) {
  262. fileModel.isSelectType = button.selected;
  263. }
  264. [self.tableView reloadData];
  265. [self RefreshBottomViewUIFun];
  266. }
  267. #pragma mark 设置标题
  268. - (void)setTitleLabelText:(NSString*)title
  269. {
  270. NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  271. if(diskNameArr && diskNameArr.count >= 2){
  272. NSString *name = diskNameArr.lastObject;
  273. if(name.length == 0)
  274. {
  275. name = diskNameArr[diskNameArr.count -2];
  276. }
  277. title = [[NSString alloc] initWithFormat:@"[%@]%@",name,title];
  278. }
  279. self.MytitleLabel.text = title;
  280. CGFloat curWidth = [title boundingRectWithSize:CGSizeMake(SCREEN_W, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18.f]} context:nil].size.width;
  281. curWidth += 20;
  282. //HLog(@"title w:%f",curWidth);
  283. [self.MytitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  284. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX).offset(-10);
  285. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  286. make.width.mas_equalTo(curWidth);
  287. make.height.mas_equalTo(30);
  288. }];
  289. //self.MytitleLabel.backgroundColor = [UIColor greenColor];
  290. [self.selectTip mas_makeConstraints:^(MASConstraintMaker *make) {
  291. make.left.mas_equalTo(self.MytitleLabel.mas_right).offset(0);
  292. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  293. make.width.mas_equalTo(15);
  294. make.height.mas_equalTo(15);
  295. }];
  296. [tapBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  297. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  298. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  299. make.width.mas_equalTo(curWidth+15);
  300. make.height.mas_equalTo(30);
  301. }];
  302. }
  303. #pragma mark 选择硬盘
  304. - (void)selectDiskAction:(UIButton*)but
  305. {
  306. if(self.diskListBgV.hidden){
  307. [self showDiskListVieFun];
  308. }
  309. else{
  310. [self hideDiskListVieFun];
  311. }
  312. }
  313. - (void)showDiskListVieFun
  314. {
  315. self.diskListBgV.hidden = NO;
  316. self.diskListTableV.hidden = NO;
  317. [UIView animateWithDuration:0.3 animations:^{
  318. CGRect rect = self.diskListTableV.frame;
  319. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  320. self.diskListTableV.frame = rect;
  321. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  322. }];
  323. }
  324. - (void)hideDiskListVieFun
  325. {
  326. self.diskListBgV.hidden = YES;
  327. [UIView animateWithDuration:0.3 animations:^{
  328. self.diskListTableV.hidden = YES;
  329. self.selectTip.transform = CGAffineTransformIdentity;
  330. }completion:^(BOOL finished) {
  331. CGRect rect = self.diskListTableV.frame;
  332. rect.origin.y = 0;
  333. self.diskListTableV.frame = rect;
  334. }];
  335. }
  336. #pragma mark 刷新底部
  337. - (void)RefreshBottomViewUIFun
  338. {
  339. NSMutableArray *selectArr = [NSMutableArray new];
  340. for (couldPhoneFileModel* fileModel in _curCouldPhoneFileListMod.data.list) {
  341. if(fileModel.isSelectType){
  342. [selectArr addObject:fileModel];
  343. }
  344. }
  345. _downloadFileBottomV.indexPathsForSelectedItems = selectArr;
  346. }
  347. #pragma mark 设置标题
  348. - (void)setTitleAfterGetdiskFun
  349. {
  350. if(_isPhotoType){
  351. //self.titleLabel.text = NSLocalizedString(@"my_set_no_image_upload",nil) ;
  352. [self setTitleLabelText:NSLocalizedString(@"my_set_no_image_upload",nil)];
  353. }
  354. else{
  355. //self.titleLabel.text = NSLocalizedString(@"my_set_no_video_upload",nil) ;
  356. [self setTitleLabelText:NSLocalizedString(@"my_set_no_video_upload",nil)];
  357. }
  358. [self searchFileListFun];
  359. }
  360. - (void)viewWillAppear:(BOOL)animated
  361. {
  362. [super viewWillAppear:animated];
  363. }
  364. - (void)searchFileListFun
  365. {
  366. NSMutableDictionary *dict = [NSMutableDictionary new];
  367. NSNumber *curNum = [NSNumber numberWithBool:_isPhotoType];
  368. [dict setObject:curNum forKey:@"type"];
  369. if(!_defaultDiskPath){
  370. _defaultDiskPath = @"";
  371. }
  372. [dict setObject:_defaultDiskPath forKey:@"path"];
  373. [[NSNotificationCenter defaultCenter] postNotificationName:searchFileListBeginNotification object:dict];/*发送通知*/
  374. }
  375. - (void)searchFileListDoneFun:(NSNotification*)notification
  376. {
  377. NSDictionary *dataDict = [notification object];
  378. if(!dataDict || ![dataDict isKindOfClass:[NSDictionary class]]){
  379. return;
  380. }
  381. _curCouldPhoneFileListMod = [[couldPhoneFileListModel alloc] initWithDictionary:dataDict error:nil];
  382. NSMutableArray *filterArr = [NSMutableArray new];
  383. for (couldPhoneFileModel*model in _curCouldPhoneFileListMod.data.list) {
  384. //if(model.length > 1024)
  385. if(model.length > 1024*50)
  386. {
  387. [filterArr addObject:model];
  388. }
  389. }
  390. _curCouldPhoneFileListMod.data.list = filterArr;
  391. [self.tableView reloadData];
  392. //这个要做判断 不能为空
  393. //[self gotoDownThumbnailManagerFun];
  394. }
  395. #pragma mark 去下载缩略图
  396. - (void)gotoDownThumbnailManagerFun
  397. {
  398. [[downloadThumbnailManager shareInstance] handlToDownloadThumbnailWith:_curCouldPhoneFileListMod.data.list];
  399. }
  400. - (void)gotoDownloadloadFileRecordFun
  401. {
  402. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  403. [self.navigationController pushViewController:vc animated:YES];
  404. vc.isDownloadingType = YES;
  405. [vc gotoDownloadFile:_downloadFileBottomV.indexPathsForSelectedItems];
  406. }
  407. @end