downloadFileRecordTableView.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. //
  2. // downloadFileRecordTableView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/10.
  6. //
  7. #import "downloadFileRecordTableView.h"
  8. #import "downloadFileRecordCell.h"
  9. #import "UIScrollView+EmptyDataSet.h"
  10. #import "uploadFileRecordTableViewHeadView.h"
  11. @interface downloadFileRecordTableView()<UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  12. {
  13. }
  14. @property (nonatomic, strong) NSMutableArray *curDataArr;
  15. @end
  16. @implementation downloadFileRecordTableView
  17. - (id)initWithFrame:(CGRect)frame {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. [self initCommon];
  21. [self initTableHeaderInSectionFun];
  22. _selectModelArr = [NSMutableArray new];
  23. _curDataArr = [NSMutableArray new];
  24. }
  25. return self;
  26. }
  27. - (void)initCommon {
  28. self.delegate = self;
  29. self.dataSource = self;
  30. self.showsVerticalScrollIndicator = NO;
  31. self.showsHorizontalScrollIndicator = NO;
  32. [self setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  33. [self setSeparatorColor:[UIColor clearColor]];
  34. [self setBackgroundColor:[UIColor clearColor]];
  35. [self setTableFooterView:[UIView new]];
  36. [self setBounces:YES];
  37. if (@available(iOS 15.0, *)) {
  38. self.sectionHeaderTopPadding = 0;
  39. }
  40. //空数据引入第三方开源处理
  41. self.emptyDataSetSource = self;
  42. self.emptyDataSetDelegate = self;
  43. }
  44. - (void)setOutSideDataArr:(NSMutableArray *)outSideDataArr{
  45. if(!outSideDataArr || outSideDataArr.count != 3){
  46. return;
  47. }
  48. _outSideDataArr = outSideDataArr;
  49. _downloadingArr = outSideDataArr[0];
  50. _downloadDoneArr = outSideDataArr[1];
  51. _downloadfailArr = outSideDataArr[2];
  52. [self RefreshAllDataFun];
  53. }
  54. - (void)RefreshAllDataFun
  55. {
  56. NSMutableArray *totalArr = [NSMutableArray new];
  57. if(_downloadingArr.count>0){
  58. [totalArr addObject:_downloadingArr];
  59. }
  60. if(_downloadfailArr.count>0){
  61. [totalArr addObject:_downloadfailArr];
  62. }
  63. if(_downloadDoneArr.count>0){
  64. [totalArr addObject:_downloadDoneArr];
  65. }
  66. _curDataArr = totalArr;
  67. [self reloadDataFun];
  68. }
  69. #pragma mark - 列表委托
  70. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  71. return _curDataArr.count;
  72. }
  73. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  74. if(section < _curDataArr.count){
  75. NSArray *curArr = _curDataArr[section];
  76. return curArr.count;
  77. }
  78. return 0;
  79. }
  80. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  81. NSInteger row = indexPath.row;
  82. NSInteger section = indexPath.section;
  83. static NSString *identifier = @"downloadFileRecordCell";
  84. downloadFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  85. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  86. if (!cell){
  87. cell = [[downloadFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  88. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  89. [cell setBackgroundColor:[UIColor clearColor]];
  90. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  91. }
  92. if(section < _curDataArr.count){
  93. NSMutableArray *curArr = _curDataArr[section];
  94. if(row < curArr.count){
  95. couldPhoneFileModel *model = curArr[row];
  96. cell.curCouldPhoneFileModel = model;
  97. cell.isEditType = _isEditType;
  98. if(_isEditType){
  99. if([_selectModelArr containsObject:model]){
  100. cell.isSelectType = YES;
  101. }
  102. else{
  103. cell.isSelectType = NO;
  104. }
  105. }
  106. KWeakSelf
  107. cell.didLongPressClick = ^{
  108. [weakSelf didLongPressClickFun];
  109. };
  110. cell.didClckSelectBut = ^(BOOL isSelect) {
  111. [weakSelf selectModelOneByOne:model BySelect:isSelect];
  112. };
  113. cell.didTapPressClick = ^{
  114. if(model.curDownloadStateType == downloadStateUploading){
  115. [weakSelf handleDownloadingStateTapFunBy:YES with:model];
  116. }
  117. else if(model.curDownloadStateType == downloadStateSuspend){
  118. [weakSelf handleDownloadingStateTapFunBy:NO with:model];
  119. }
  120. else if(model.curDownloadStateType == downloadStateFail){
  121. [weakSelf handleUploadFailStateWith:model];
  122. }
  123. };
  124. }
  125. }
  126. return cell;
  127. }
  128. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  129. return 70;
  130. }
  131. - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  132. {
  133. NSInteger curType = 0;// 0 上传中 1 失败 2 完成
  134. if(section == 2){
  135. curType = 2;
  136. }
  137. else if(section == 1){
  138. if(_downloadingArr.count == 0){
  139. curType = 2;
  140. }
  141. else if(_downloadfailArr.count == 0){
  142. curType = 2;
  143. }
  144. else{
  145. curType = 1;
  146. }
  147. }
  148. else{
  149. if(_downloadingArr.count > 0){
  150. curType = 0;
  151. }
  152. else if(_downloadfailArr.count > 0){
  153. curType = 1;
  154. }
  155. else{
  156. curType = 2;
  157. }
  158. }
  159. [self RefresHeadUIFun];
  160. if(curType == 2){
  161. return _doneHeadView;
  162. }
  163. else if(curType == 1){
  164. return _failHeadView;
  165. }
  166. else{
  167. return _downloadingHeadView;
  168. }
  169. }
  170. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  171. {
  172. return 40;
  173. }
  174. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  175. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  176. }
  177. #pragma mark 空数据
  178. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  179. NSString *imageName = @"uploadFile_noData";
  180. if(self.tag == 101){
  181. imageName = @"uploadFile_noData";
  182. }
  183. else if(self.tag == 102){
  184. imageName = @"uploadFile_noData";
  185. }
  186. return [UIImage imageNamed:imageName];
  187. }
  188. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  189. NSString *text = NSLocalizedString(@"File_upload_Record_no_data",nil);
  190. if(self.tag == 101){
  191. text = NSLocalizedString(@"File_download_Record_no_data",nil);
  192. }
  193. else if(self.tag == 102){
  194. text = NSLocalizedString(@"File_backups_Record_no_data",nil);
  195. }
  196. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  197. NSForegroundColorAttributeName: HW999999Color};
  198. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  199. }
  200. //调整图片位置
  201. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  202. return -150;
  203. }
  204. -(void)reloadDataFun{
  205. mainBlock(^{
  206. [self RefresHeadUIFun];
  207. [self reloadData];
  208. });
  209. }
  210. #pragma mark 初始化段头
  211. - (void)initTableHeaderInSectionFun
  212. {
  213. KWeakSelf
  214. if(!_downloadingHeadView){
  215. _downloadingHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  216. //headView.backgroundColor = [UIColor greenColor];
  217. NSString *leftStr = NSLocalizedString(@"File_upload_Record_uploading",nil);
  218. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  219. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  220. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadingArr.count];
  221. _downloadingHeadView.titleLabel.text = titleStr;
  222. [_downloadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  223. [_downloadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  224. _downloadingHeadView.didClickButFun = ^{
  225. [weakSelf didClickRightButtonFun:0];
  226. };
  227. }
  228. if(!_failHeadView){
  229. _failHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  230. //headView.backgroundColor = [UIColor greenColor];
  231. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  232. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  233. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadfailArr.count];
  234. _failHeadView.titleLabel.text = titleStr;
  235. [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  236. _failHeadView.didClickButFun = ^{
  237. [weakSelf didClickRightButtonFun:2];
  238. };
  239. }
  240. if(!_doneHeadView){
  241. _doneHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  242. //headView.backgroundColor = [UIColor greenColor];
  243. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  244. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  245. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadDoneArr.count];
  246. _doneHeadView.titleLabel.text = titleStr;
  247. [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  248. _doneHeadView.didClickButFun = ^{
  249. [weakSelf didClickRightButtonFun:1];
  250. };
  251. }
  252. }
  253. #pragma mark 点击头部右边按钮
  254. - (void)didClickRightButtonFun:(NSInteger)section
  255. {
  256. if(_didClickSectionHeadViewRightButton){
  257. _didClickSectionHeadViewRightButton(section);
  258. }
  259. }
  260. #pragma mark 刷新头部数据
  261. -(void)RefresHeadUIFun
  262. {
  263. if(_downloadingHeadView){
  264. NSString *leftStr = NSLocalizedString(@"File_upload_Record_uploading",nil);
  265. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  266. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  267. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadingArr.count];
  268. _downloadingHeadView.titleLabel.text = titleStr;
  269. [_downloadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  270. [_downloadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  271. if(_downloadingArr.count == 0){
  272. _downloadingHeadView.hidden = YES;
  273. }
  274. else{
  275. _downloadingHeadView.hidden = NO;
  276. }
  277. }
  278. if(_failHeadView){
  279. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  280. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  281. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadfailArr.count];
  282. _failHeadView.titleLabel.text = titleStr;
  283. [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  284. if(_downloadfailArr.count == 0){
  285. _failHeadView.hidden = YES;
  286. }
  287. else{
  288. _failHeadView.hidden = NO;
  289. }
  290. }
  291. if(_doneHeadView){
  292. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  293. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  294. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadDoneArr.count];
  295. _doneHeadView.titleLabel.text = titleStr;
  296. [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  297. if(_downloadDoneArr.count == 0){
  298. _doneHeadView.hidden = YES;
  299. }
  300. else{
  301. _doneHeadView.hidden = NO;
  302. }
  303. }
  304. }
  305. #pragma mark 点击全选
  306. - (void)setIsSelectAllType:(BOOL)isSelectAllType
  307. {
  308. //_selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
  309. _selectModelArr = [NSMutableArray new];
  310. [_selectModelArr addObjectsFromArray:_downloadingArr];
  311. [_selectModelArr addObjectsFromArray:_downloadfailArr];
  312. [_selectModelArr addObjectsFromArray:_downloadDoneArr];
  313. [self reloadDataFun];
  314. }
  315. -(void)setIsEditType:(BOOL)isEditType
  316. {
  317. _isEditType = isEditType;
  318. if(_isEditType){
  319. //_bgScrollV.scrollEnabled = NO;
  320. }
  321. else{
  322. //_bgScrollV.scrollEnabled = YES;
  323. [_selectModelArr removeAllObjects];
  324. }
  325. [self reloadDataFun];
  326. }
  327. #pragma mark cell长按时间
  328. - (void)didLongPressClickFun{
  329. self.isEditType = YES;
  330. if(self->_didLongPressClick){
  331. self->_didLongPressClick();
  332. }
  333. }
  334. #pragma mark 单个点击选中 取消
  335. - (void)selectModelOneByOne:(couldPhoneFileModel*)model BySelect:(BOOL)isSelcet
  336. {
  337. if(isSelcet){
  338. [_selectModelArr addObject:model];
  339. }
  340. else{
  341. [_selectModelArr removeObject:model];
  342. }
  343. }
  344. #pragma mark 单个点击选中后删除
  345. - (void)deleteModelOneByOneFun{
  346. if(!_selectModelArr || _selectModelArr.count==0){
  347. return;
  348. }
  349. [[downloadManager shareInstance] deleteDownloadFileRecordBy:_selectModelArr withDelCache:YES];
  350. //重新拿数据
  351. [self refreshGetDatabaseFun];
  352. }
  353. #pragma mark 删除后重新拿数据
  354. - (void)refreshGetDatabaseFun
  355. {
  356. if(_didNeedRefreshGetDatabaseFun){
  357. _didNeedRefreshGetDatabaseFun();
  358. }
  359. }
  360. #pragma mark 处理上传中的 状态点击事件
  361. - (void)handleDownloadingStateTapFunBy:(BOOL)isSuspendType with:(couldPhoneFileModel*)model
  362. {
  363. if (isSuspendType) {
  364. [[downloadManager shareInstance] suspendDownloadFileFun:NO];
  365. }
  366. else{
  367. NSMutableArray*arr = [NSMutableArray new];
  368. [arr addObject:model];
  369. [[downloadManager shareInstance] reDownloadFileFunBy:arr];
  370. }
  371. }
  372. #pragma mark 处理上传中的 状态点击事件
  373. - (void)handleUploadFailStateWith:(uploadFileDataModel*)model{
  374. // [_curDataArr removeObject:model];
  375. // [self reloadDataFun];
  376. //
  377. // if(_didClickReUploadBlock){
  378. // _didClickReUploadBlock(model);
  379. // }
  380. //
  381. // NSMutableArray*arr = [NSMutableArray new];
  382. // model.curUploadStateType = uploadStateWait;
  383. // [arr addObject:model];
  384. // [[uploadFileManager shareInstance] reUploadFileFunBy:arr];
  385. }
  386. @end