downLoadPreviewViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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 hideDiskListVieFun];
  189. }
  190. #pragma mark - 列表委托
  191. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  192. return 1;
  193. }
  194. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  195. if(!_curCouldPhoneFileListMod){
  196. return 0;
  197. }
  198. return _curCouldPhoneFileListMod.data.list.count;
  199. }
  200. - (downLoadPreViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  201. __block NSInteger row = indexPath.row;
  202. static NSString *identifier = @"downLoadPreViewCell";
  203. downLoadPreViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  204. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  205. if (!cell){
  206. cell = [[downLoadPreViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  207. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  208. [cell setBackgroundColor:[UIColor clearColor]];
  209. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  210. [cell.bgViewLayer removeFromSuperlayer];
  211. [cell.titleLabel2 setHidden:NO];
  212. [cell.rightImage setHidden:YES];
  213. [cell.lineView setHidden:YES];
  214. [cell.checkButton setHidden:NO];
  215. }
  216. if(row < _curCouldPhoneFileListMod.data.list.count){
  217. couldPhoneFileModel* fileModel = _curCouldPhoneFileListMod.data.list[row];
  218. cell.curFileModel = fileModel;
  219. }
  220. KWeakSelf
  221. cell.didClickSwitch = ^(BOOL SwitchOn) {
  222. [weakSelf userCheckFilePreviewByRow:row];
  223. };
  224. return cell;
  225. }
  226. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  227. return 70;
  228. }
  229. #pragma mark 空数据
  230. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  231. NSString *imageName = @"uploadFile_noData";
  232. return [UIImage imageNamed:imageName];
  233. }
  234. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  235. NSString *text = NSLocalizedString(@"File_download_file_no_data",nil);
  236. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  237. NSForegroundColorAttributeName: HW999999Color};
  238. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  239. }
  240. //调整图片位置
  241. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  242. return -150;
  243. }
  244. - (void)userCheckFilePreviewByRow:(NSInteger)row
  245. {
  246. if(row < _curCouldPhoneFileListMod.data.list.count){
  247. couldPhoneFileModel* fileModel = _curCouldPhoneFileListMod.data.list[row];
  248. fileModel.isSelectType = !fileModel.isSelectType;
  249. [self.tableView reloadData];
  250. [self RefreshBottomViewUIFun];
  251. }
  252. }
  253. - (void)didClickSelectAllButton:(UIButton*)button
  254. {
  255. button.selected = !button.selected;
  256. for (couldPhoneFileModel* fileModel in _curCouldPhoneFileListMod.data.list) {
  257. fileModel.isSelectType = button.selected;
  258. }
  259. [self.tableView reloadData];
  260. [self RefreshBottomViewUIFun];
  261. }
  262. #pragma mark 设置标题
  263. - (void)setTitleLabelText:(NSString*)title
  264. {
  265. self.MytitleLabel.text = title;
  266. CGFloat curWidth = [title boundingRectWithSize:CGSizeMake(SCREEN_W, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18.f]} context:nil].size.width;
  267. curWidth += 20;
  268. //HLog(@"title w:%f",curWidth);
  269. [self.MytitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  270. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX).offset(-10);
  271. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  272. make.width.mas_equalTo(curWidth);
  273. make.height.mas_equalTo(30);
  274. }];
  275. //self.MytitleLabel.backgroundColor = [UIColor greenColor];
  276. [self.selectTip mas_makeConstraints:^(MASConstraintMaker *make) {
  277. make.left.mas_equalTo(self.MytitleLabel.mas_right).offset(2);
  278. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  279. make.width.mas_equalTo(15);
  280. make.height.mas_equalTo(15);
  281. }];
  282. }
  283. #pragma mark 选择硬盘
  284. - (void)selectDiskAction:(UIButton*)but
  285. {
  286. if(self.diskListBgV.hidden){
  287. [self showDiskListVieFun];
  288. }
  289. else{
  290. [self hideDiskListVieFun];
  291. }
  292. }
  293. - (void)showDiskListVieFun
  294. {
  295. self.diskListBgV.hidden = NO;
  296. self.diskListTableV.hidden = NO;
  297. [UIView animateWithDuration:0.3 animations:^{
  298. CGRect rect = self.diskListTableV.frame;
  299. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  300. self.diskListTableV.frame = rect;
  301. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  302. }];
  303. }
  304. - (void)hideDiskListVieFun
  305. {
  306. self.diskListBgV.hidden = YES;
  307. [UIView animateWithDuration:0.3 animations:^{
  308. self.diskListTableV.hidden = YES;
  309. self.selectTip.transform = CGAffineTransformIdentity;
  310. }completion:^(BOOL finished) {
  311. CGRect rect = self.diskListTableV.frame;
  312. rect.origin.y = 0;
  313. self.diskListTableV.frame = rect;
  314. }];
  315. }
  316. #pragma mark 刷新底部
  317. - (void)RefreshBottomViewUIFun
  318. {
  319. NSMutableArray *selectArr = [NSMutableArray new];
  320. for (couldPhoneFileModel* fileModel in _curCouldPhoneFileListMod.data.list) {
  321. if(fileModel.isSelectType){
  322. [selectArr addObject:fileModel];
  323. }
  324. }
  325. _downloadFileBottomV.indexPathsForSelectedItems = selectArr;
  326. }
  327. #pragma mark 设置标题
  328. - (void)setTitleAfterGetdiskFun
  329. {
  330. if(_isPhotoType){
  331. //self.titleLabel.text = NSLocalizedString(@"my_set_no_image_upload",nil) ;
  332. [self setTitleLabelText:NSLocalizedString(@"my_set_no_image_upload",nil)];
  333. }
  334. else{
  335. //self.titleLabel.text = NSLocalizedString(@"my_set_no_video_upload",nil) ;
  336. [self setTitleLabelText:NSLocalizedString(@"my_set_no_video_upload",nil)];
  337. }
  338. [self searchFileListFun];
  339. }
  340. - (void)viewWillAppear:(BOOL)animated
  341. {
  342. [super viewWillAppear:animated];
  343. }
  344. - (void)searchFileListFun
  345. {
  346. NSMutableDictionary *dict = [NSMutableDictionary new];
  347. NSNumber *curNum = [NSNumber numberWithBool:_isPhotoType];
  348. [dict setObject:curNum forKey:@"type"];
  349. if(!_defaultDiskPath){
  350. _defaultDiskPath = @"";
  351. }
  352. [dict setObject:_defaultDiskPath forKey:@"path"];
  353. [[NSNotificationCenter defaultCenter] postNotificationName:searchFileListBeginNotification object:dict];/*发送通知*/
  354. }
  355. - (void)searchFileListDoneFun:(NSNotification*)notification
  356. {
  357. NSDictionary *dataDict = [notification object];
  358. if(!dataDict || ![dataDict isKindOfClass:[NSDictionary class]]){
  359. return;
  360. }
  361. _curCouldPhoneFileListMod = [[couldPhoneFileListModel alloc] initWithDictionary:dataDict error:nil];
  362. NSMutableArray *filterArr = [NSMutableArray new];
  363. for (couldPhoneFileModel*model in _curCouldPhoneFileListMod.data.list) {
  364. //if(model.length > 1024)
  365. if(model.length > 1024*50)
  366. {
  367. [filterArr addObject:model];
  368. }
  369. }
  370. _curCouldPhoneFileListMod.data.list = filterArr;
  371. [self.tableView reloadData];
  372. //这个要做判断 不能为空
  373. //[self gotoDownThumbnailManagerFun];
  374. }
  375. #pragma mark 去下载缩略图
  376. - (void)gotoDownThumbnailManagerFun
  377. {
  378. [[downloadThumbnailManager shareInstance] handlToDownloadThumbnailWith:_curCouldPhoneFileListMod.data.list];
  379. }
  380. - (void)gotoDownloadloadFileRecordFun
  381. {
  382. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  383. [self.navigationController pushViewController:vc animated:YES];
  384. vc.isDownloadingType = YES;
  385. [vc gotoDownloadFile:_downloadFileBottomV.indexPathsForSelectedItems];
  386. }
  387. @end