receiveDownloadRecordTableView.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. //
  2. // receiveDownloadRecordTableView.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/23.
  6. //
  7. #import "receiveDownloadRecordTableView.h"
  8. #import "downloadFileRecordCell.h"
  9. #import "UIScrollView+EmptyDataSet.h"
  10. #import "uploadFileRecordTableViewHeadView.h"
  11. @interface receiveDownloadRecordTableView()<UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  12. {
  13. }
  14. @property (nonatomic, strong) NSMutableArray *curDataArr;
  15. @end
  16. @implementation receiveDownloadRecordTableView
  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. model.curDownloadStateType = downloadStateSuspend;
  116. [weakSelf handleDownloadingStateTapFunBy:YES with:model];
  117. }
  118. else if(model.curDownloadStateType == downloadStateSuspend){
  119. model.curDownloadStateType = downloadStateUploading;
  120. [weakSelf handleDownloadingStateTapFunBy:NO with:model];
  121. }
  122. else if(model.curDownloadStateType == downloadStateFail){
  123. [weakSelf handleUploadFailStateWith:model];
  124. }
  125. };
  126. }
  127. }
  128. return cell;
  129. }
  130. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  131. return 70;
  132. }
  133. - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  134. {
  135. NSInteger curType = 0;// 0 上传中 1 失败 2 完成
  136. if(section == 2){
  137. curType = 2;
  138. }
  139. else if(section == 1){
  140. if(_downloadingArr.count == 0){
  141. curType = 2;
  142. }
  143. else if(_downloadfailArr.count == 0){
  144. curType = 2;
  145. }
  146. else{
  147. curType = 1;
  148. }
  149. }
  150. else{
  151. if(_downloadingArr.count > 0){
  152. curType = 0;
  153. }
  154. else if(_downloadfailArr.count > 0){
  155. curType = 1;
  156. }
  157. else{
  158. curType = 2;
  159. }
  160. }
  161. [self RefresHeadUIFun];
  162. return [UIView new];
  163. // if(curType == 2){
  164. // return _doneHeadView;
  165. // }
  166. // else if(curType == 1){
  167. // return _failHeadView;
  168. // }
  169. // else{
  170. // return _downloadingHeadView;
  171. // }
  172. }
  173. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  174. {
  175. return 40;
  176. }
  177. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  178. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  179. }
  180. #pragma mark 空数据
  181. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  182. NSString *imageName = @"common_no_data_pic";
  183. return [UIImage imageNamed:imageName];
  184. }
  185. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  186. NSString *text = NSLocalizedString(@"common_no_data_tip",nil);
  187. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  188. NSForegroundColorAttributeName: HW999999Color};
  189. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  190. }
  191. //调整图片位置
  192. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  193. return -150;
  194. }
  195. -(void)reloadDataFun{
  196. mainBlock(^{
  197. [self RefresHeadUIFun];
  198. [self reloadData];
  199. });
  200. }
  201. #pragma mark 初始化段头
  202. - (void)initTableHeaderInSectionFun
  203. {
  204. KWeakSelf
  205. // if(!_downloadingHeadView){
  206. // _downloadingHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  207. // //headView.backgroundColor = [UIColor greenColor];
  208. //
  209. // NSString *leftStr = NSLocalizedString(@"File_upload_Record_downloading",nil);
  210. // NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  211. // NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  212. // NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadingArr.count];
  213. //
  214. // _downloadingHeadView.titleLabel.text = titleStr;
  215. // [_downloadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  216. // [_downloadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  217. //
  218. // _downloadingHeadView.didClickButFun = ^{
  219. // [weakSelf didClickRightButtonFun:0];
  220. // };
  221. // }
  222. //
  223. //
  224. // if(!_failHeadView){
  225. // _failHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  226. // //headView.backgroundColor = [UIColor greenColor];
  227. //
  228. // NSString *leftStr = NSLocalizedString(@"File_upload_Record_download_fail",nil);
  229. // NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  230. // NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadfailArr.count];
  231. //
  232. // _failHeadView.titleLabel.text = titleStr;
  233. // [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  234. //
  235. // _failHeadView.didClickButFun = ^{
  236. // [weakSelf didClickRightButtonFun:2];
  237. // };
  238. // }
  239. //
  240. // if(!_doneHeadView){
  241. // _doneHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  242. // //headView.backgroundColor = [UIColor greenColor];
  243. //
  244. // NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_download",nil);
  245. // NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  246. // NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadDoneArr.count];
  247. //
  248. // _doneHeadView.titleLabel.text = titleStr;
  249. // [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  250. //
  251. // _doneHeadView.didClickButFun = ^{
  252. // [weakSelf didClickRightButtonFun:1];
  253. // };
  254. // }
  255. //
  256. //
  257. }
  258. #pragma mark 点击头部右边按钮
  259. - (void)didClickRightButtonFun:(NSInteger)section
  260. {
  261. if(_didClickSectionHeadViewRightButton){
  262. _didClickSectionHeadViewRightButton(section);
  263. }
  264. }
  265. #pragma mark 刷新头部数据
  266. -(void)RefresHeadUIFun
  267. {
  268. // if(_downloadingHeadView){
  269. // NSString *leftStr = NSLocalizedString(@"File_upload_Record_downloading",nil);
  270. // NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  271. // NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  272. // NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadingArr.count];
  273. //
  274. // _downloadingHeadView.titleLabel.text = titleStr;
  275. // [_downloadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  276. // [_downloadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  277. //
  278. // if(_downloadingArr.count == 0){
  279. // _downloadingHeadView.hidden = YES;
  280. // }
  281. // else{
  282. // _downloadingHeadView.hidden = NO;
  283. // }
  284. // }
  285. //
  286. //
  287. // if(_failHeadView){
  288. // NSString *leftStr = NSLocalizedString(@"File_upload_Record_download_fail",nil);
  289. // NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  290. // NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadfailArr.count];
  291. //
  292. // _failHeadView.titleLabel.text = titleStr;
  293. // [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  294. //
  295. // if(_downloadfailArr.count == 0){
  296. // _failHeadView.hidden = YES;
  297. // }
  298. // else{
  299. // _failHeadView.hidden = NO;
  300. // }
  301. // }
  302. //
  303. // if(_doneHeadView){
  304. // NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_download",nil);
  305. // NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  306. // NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadDoneArr.count];
  307. //
  308. // _doneHeadView.titleLabel.text = titleStr;
  309. // [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  310. //
  311. // if(_downloadDoneArr.count == 0){
  312. // _doneHeadView.hidden = YES;
  313. // }
  314. // else{
  315. // _doneHeadView.hidden = NO;
  316. // }
  317. // }
  318. }
  319. #pragma mark 点击全选
  320. - (void)setIsSelectAllType:(BOOL)isSelectAllType
  321. {
  322. //_selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
  323. _selectModelArr = [NSMutableArray new];
  324. [_selectModelArr addObjectsFromArray:_downloadingArr];
  325. [_selectModelArr addObjectsFromArray:_downloadfailArr];
  326. [_selectModelArr addObjectsFromArray:_downloadDoneArr];
  327. [self reloadDataFun];
  328. }
  329. -(void)setIsEditType:(BOOL)isEditType
  330. {
  331. _isEditType = isEditType;
  332. if(_isEditType){
  333. //_bgScrollV.scrollEnabled = NO;
  334. }
  335. else{
  336. //_bgScrollV.scrollEnabled = YES;
  337. [_selectModelArr removeAllObjects];
  338. }
  339. [self reloadDataFun];
  340. }
  341. #pragma mark cell长按时间
  342. - (void)didLongPressClickFun{
  343. self.isEditType = YES;
  344. if(self->_didLongPressClick){
  345. self->_didLongPressClick();
  346. }
  347. }
  348. #pragma mark 单个点击选中 取消
  349. - (void)selectModelOneByOne:(couldPhoneFileModel*)model BySelect:(BOOL)isSelcet
  350. {
  351. if(isSelcet){
  352. [_selectModelArr addObject:model];
  353. }
  354. else{
  355. [_selectModelArr removeObject:model];
  356. }
  357. }
  358. #pragma mark 单个点击选中后删除
  359. - (void)deleteModelOneByOneFun{
  360. if(!_selectModelArr || _selectModelArr.count==0){
  361. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  362. [SVProgressHUD dismiss];
  363. });
  364. return;
  365. }
  366. //[[downloadManager shareInstance] deleteDownloadFileRecordBy:_selectModelArr withDelCache:YES];
  367. [_selectModelArr removeAllObjects];
  368. //重新拿数据
  369. [self refreshGetDatabaseFun];
  370. }
  371. #pragma mark 删除后重新拿数据
  372. - (void)refreshGetDatabaseFun
  373. {
  374. if(_didNeedRefreshGetDatabaseFun){
  375. _didNeedRefreshGetDatabaseFun();
  376. }
  377. }
  378. #pragma mark 处理上传中的 状态点击事件
  379. - (void)handleDownloadingStateTapFunBy:(BOOL)isSuspendType with:(couldPhoneFileModel*)model
  380. {
  381. // if (isSuspendType) {
  382. // [[downloadManager shareInstance] suspendDownloadFileFun:NO withModel:model];
  383. // }
  384. // else{
  385. // NSMutableArray*arr = [NSMutableArray new];
  386. // [arr addObject:model];
  387. // [[downloadManager shareInstance] reDownloadFileFunBy:arr withAll:NO];
  388. // }
  389. //
  390. // [self reloadDataFun];
  391. }
  392. #pragma mark 处理上传中的 状态点击事件
  393. - (void)handleUploadFailStateWith:(couldPhoneFileModel*)model{
  394. // [_downloadfailArr removeObject:model];
  395. // [_downloadingArr addObject:model];
  396. //
  397. // [self RefreshAllDataFun];
  398. //
  399. // if(_didClickReUploadBlock){
  400. // _didClickReUploadBlock(model);
  401. // }
  402. //
  403. // NSMutableArray*arr = [NSMutableArray new];
  404. // model.curDownloadStateType = downloadStateWait;
  405. // [arr addObject:model];
  406. // [[downloadManager shareInstance] reDownloadFileFunBy:arr withAll:NO];
  407. }
  408. @end