downLoadPreviewViewController.m 13 KB

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