downLoadPreviewViewController.m 16 KB

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