downLoadPreviewViewController.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. @interface downLoadPreviewViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  16. @property (nonatomic, strong) UITableView *tableView;
  17. @property (nonatomic, strong) UIButton *rightButton;
  18. @property (nonatomic, strong) downloadFileBottomView *downloadFileBottomV;
  19. @property (nonatomic,assign) BOOL didGetType;
  20. @property(nonatomic,strong) couldPhoneFileListModel *curCouldPhoneFileListMod;
  21. @end
  22. @implementation downLoadPreviewViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. [self.toolBar setHidden:YES];
  27. [self.navigationBar setHidden:YES];
  28. [self.navBarBGView setHidden:NO];
  29. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  30. [self.view setBackgroundColor:[UIColor whiteColor]];
  31. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(searchFileListDoneFun:) name:searchFileListDoneNotification object:nil];
  32. [self drawAnyView];
  33. }
  34. - (void)drawAnyView{
  35. _rightButton = [[UIButton alloc] init];
  36. [_rightButton setTitle:NSLocalizedString(@"File_upload_Record_select_all",nil) forState:UIControlStateNormal];
  37. [_rightButton setTitle:NSLocalizedString(@"File_upload_cancel_select_all",nil) forState:UIControlStateSelected];
  38. [_rightButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  39. _rightButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
  40. _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  41. [_rightButton addTarget:self action:@selector(didClickSelectAllButton:) forControlEvents:UIControlEventTouchUpInside];
  42. [self.navBarBGView addSubview:_rightButton];
  43. [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.width.mas_equalTo(120);
  45. make.height.mas_equalTo(40);
  46. make.right.mas_equalTo(-15);
  47. make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  48. }];
  49. [self.view addSubview:self.tableView];
  50. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.left.mas_equalTo(0);
  52. make.right.mas_equalTo(0);
  53. make.bottom.mas_equalTo(-(60 + safeArea));
  54. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  55. }];
  56. _downloadFileBottomV = [[downloadFileBottomView alloc] init];
  57. [self.view insertSubview:_downloadFileBottomV atIndex:0];
  58. [_downloadFileBottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.mas_equalTo(0);
  60. make.right.mas_equalTo(0);
  61. make.bottom.mas_equalTo(0);
  62. make.height.mas_equalTo(60 + safeArea);
  63. }];
  64. [self RefreshBottomViewUIFun];
  65. KWeakSelf
  66. _downloadFileBottomV.didClickDownloadFile = ^{
  67. [weakSelf gotoDownloadloadFileRecordFun];
  68. };
  69. }
  70. #pragma mark - 懒加载
  71. - (UITableView *)tableView{
  72. if (!_tableView) {
  73. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain];
  74. _tableView.delegate = self;
  75. _tableView.dataSource = self;
  76. _tableView.showsVerticalScrollIndicator = NO;
  77. _tableView.showsHorizontalScrollIndicator = NO;
  78. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  79. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  80. [_tableView setSeparatorColor:[UIColor clearColor]];
  81. [_tableView setBackgroundColor:[UIColor clearColor]];
  82. [_tableView setTableFooterView:[UIView new]];
  83. [_tableView setBounces:YES];
  84. if (@available(iOS 15.0, *)) {
  85. _tableView.sectionHeaderTopPadding = 0;
  86. }
  87. //空数据引入第三方开源处理
  88. _tableView.emptyDataSetSource = self;
  89. _tableView.emptyDataSetDelegate = self;
  90. }
  91. return _tableView;
  92. }
  93. #pragma mark - 列表委托
  94. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  95. return 1;
  96. }
  97. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  98. if(!_curCouldPhoneFileListMod){
  99. return 0;
  100. }
  101. return _curCouldPhoneFileListMod.data.list.count;
  102. }
  103. - (downLoadPreViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  104. __block NSInteger row = indexPath.row;
  105. static NSString *identifier = @"downLoadPreViewCell";
  106. downLoadPreViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  107. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  108. if (!cell){
  109. cell = [[downLoadPreViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  110. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  111. [cell setBackgroundColor:[UIColor clearColor]];
  112. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  113. [cell.bgViewLayer removeFromSuperlayer];
  114. [cell.titleLabel2 setHidden:NO];
  115. [cell.rightImage setHidden:YES];
  116. [cell.lineView setHidden:YES];
  117. [cell.checkButton setHidden:NO];
  118. }
  119. if(row < _curCouldPhoneFileListMod.data.list.count){
  120. couldPhoneFileModel* fileModel = _curCouldPhoneFileListMod.data.list[row];
  121. cell.curFileModel = fileModel;
  122. }
  123. KWeakSelf
  124. cell.didClickSwitch = ^(BOOL SwitchOn) {
  125. [weakSelf userCheckFilePreviewByRow:row];
  126. };
  127. return cell;
  128. }
  129. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  130. return 70;
  131. }
  132. #pragma mark 空数据
  133. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  134. NSString *imageName = @"uploadFile_noData";
  135. return [UIImage imageNamed:imageName];
  136. }
  137. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  138. NSString *text = NSLocalizedString(@"File_download_file_no_data",nil);
  139. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  140. NSForegroundColorAttributeName: HW999999Color};
  141. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  142. }
  143. //调整图片位置
  144. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  145. return -150;
  146. }
  147. - (void)userCheckFilePreviewByRow:(NSInteger)row
  148. {
  149. if(row < _curCouldPhoneFileListMod.data.list.count){
  150. couldPhoneFileModel* fileModel = _curCouldPhoneFileListMod.data.list[row];
  151. fileModel.isSelectType = !fileModel.isSelectType;
  152. [self.tableView reloadData];
  153. [self RefreshBottomViewUIFun];
  154. }
  155. }
  156. - (void)didClickSelectAllButton:(UIButton*)button
  157. {
  158. button.selected = !button.selected;
  159. for (couldPhoneFileModel* fileModel in _curCouldPhoneFileListMod.data.list) {
  160. fileModel.isSelectType = button.selected;
  161. }
  162. [self.tableView reloadData];
  163. [self RefreshBottomViewUIFun];
  164. }
  165. #pragma mark 刷新底部
  166. - (void)RefreshBottomViewUIFun
  167. {
  168. NSMutableArray *selectArr = [NSMutableArray new];
  169. for (couldPhoneFileModel* fileModel in _curCouldPhoneFileListMod.data.list) {
  170. if(fileModel.isSelectType){
  171. [selectArr addObject:fileModel];
  172. }
  173. }
  174. _downloadFileBottomV.indexPathsForSelectedItems = selectArr;
  175. }
  176. - (void)viewWillAppear:(BOOL)animated
  177. {
  178. [super viewWillAppear:animated];
  179. if(!_didGetType){
  180. if(_isPhotoType){
  181. self.titleLabel.text = NSLocalizedString(@"my_set_no_image_upload",nil) ;
  182. }
  183. else{
  184. self.titleLabel.text = NSLocalizedString(@"my_set_no_video_upload",nil) ;
  185. }
  186. [self searchFileListFun];
  187. _didGetType = YES;
  188. }
  189. }
  190. - (void)searchFileListFun
  191. {
  192. NSNumber *curNum = [NSNumber numberWithBool:_isPhotoType];
  193. [[NSNotificationCenter defaultCenter] postNotificationName:searchFileListBeginNotification object:curNum];/*发送通知*/
  194. }
  195. - (void)searchFileListDoneFun:(NSNotification*)notification
  196. {
  197. NSDictionary *dataDict = [notification object];
  198. if(!dataDict || ![dataDict isKindOfClass:[NSDictionary class]]){
  199. return;
  200. }
  201. _curCouldPhoneFileListMod = [[couldPhoneFileListModel alloc] initWithDictionary:dataDict error:nil];
  202. NSMutableArray *filterArr = [NSMutableArray new];
  203. for (couldPhoneFileModel*model in _curCouldPhoneFileListMod.data.list) {
  204. if(model.length > 1024){
  205. [filterArr addObject:model];
  206. }
  207. }
  208. _curCouldPhoneFileListMod.data.list = filterArr;
  209. [self.tableView reloadData];
  210. [self gotoDownThumbnailManagerFun];
  211. }
  212. #pragma mark 去下载缩略图
  213. - (void)gotoDownThumbnailManagerFun
  214. {
  215. [[downloadThumbnailManager shareInstance] handlToDownloadThumbnailWith:_curCouldPhoneFileListMod.data.list];
  216. }
  217. - (void)gotoDownloadloadFileRecordFun
  218. {
  219. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  220. [self.navigationController pushViewController:vc animated:YES];
  221. vc.isDownloadingType = YES;
  222. [vc gotoDownloadFile:_downloadFileBottomV.indexPathsForSelectedItems];
  223. }
  224. @end