receiveDownloadRecordTableView.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. //
  2. // receiveDownloadRecordTableView.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/23.
  6. //
  7. #import "receiveDownloadRecordTableView.h"
  8. #import "boxDownloadFileRecordCell.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 = @"boxDownloadFileRecordCell";
  84. boxDownloadFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  85. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  86. if (!cell){
  87. cell = [[boxDownloadFileRecordCell 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. ShareFileDataModel *model = curArr[row];
  96. cell.curShareFileDataModel = 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. if(curType == 2){
  163. return _doneHeadView;
  164. }
  165. else if(curType == 1){
  166. return _failHeadView;
  167. }
  168. else{
  169. return _downloadingHeadView;
  170. }
  171. }
  172. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  173. {
  174. return 40;
  175. }
  176. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  177. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  178. }
  179. #pragma mark 空数据
  180. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  181. NSString *imageName = @"common_no_data_pic";
  182. return [UIImage imageNamed:imageName];
  183. }
  184. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  185. NSString *text = NSLocalizedString(@"common_no_data_tip",nil);
  186. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  187. NSForegroundColorAttributeName: HW999999Color};
  188. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  189. }
  190. //调整图片位置
  191. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  192. return -150;
  193. }
  194. -(void)reloadDataFun{
  195. mainBlock(^{
  196. [self RefresHeadUIFun];
  197. [self reloadData];
  198. });
  199. }
  200. #pragma mark 初始化段头
  201. - (void)initTableHeaderInSectionFun
  202. {
  203. KWeakSelf
  204. if(!_downloadingHeadView){
  205. _downloadingHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  206. //headView.backgroundColor = [UIColor greenColor];
  207. NSString *leftStr = NSLocalizedString(@"File_upload_Record_downloading",nil);
  208. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  209. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  210. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadingArr.count];
  211. _downloadingHeadView.titleLabel.text = titleStr;
  212. [_downloadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  213. [_downloadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  214. _downloadingHeadView.didClickButFun = ^{
  215. [weakSelf didClickRightButtonFun:0];
  216. };
  217. }
  218. if(!_failHeadView){
  219. _failHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  220. //headView.backgroundColor = [UIColor greenColor];
  221. NSString *leftStr = NSLocalizedString(@"File_upload_Record_download_fail",nil);
  222. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  223. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadfailArr.count];
  224. _failHeadView.titleLabel.text = titleStr;
  225. [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  226. _failHeadView.didClickButFun = ^{
  227. [weakSelf didClickRightButtonFun:2];
  228. };
  229. }
  230. if(!_doneHeadView){
  231. _doneHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  232. //headView.backgroundColor = [UIColor greenColor];
  233. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_download",nil);
  234. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  235. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadDoneArr.count];
  236. _doneHeadView.titleLabel.text = titleStr;
  237. [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  238. _doneHeadView.didClickButFun = ^{
  239. [weakSelf didClickRightButtonFun:1];
  240. };
  241. }
  242. }
  243. #pragma mark 点击头部右边按钮
  244. - (void)didClickRightButtonFun:(NSInteger)section
  245. {
  246. if(_didClickSectionHeadViewRightButton){
  247. _didClickSectionHeadViewRightButton(section);
  248. }
  249. }
  250. #pragma mark 刷新头部数据
  251. -(void)RefresHeadUIFun
  252. {
  253. if(_downloadingHeadView){
  254. NSString *leftStr = NSLocalizedString(@"File_upload_Record_downloading",nil);
  255. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  256. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  257. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadingArr.count];
  258. _downloadingHeadView.titleLabel.text = titleStr;
  259. [_downloadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  260. [_downloadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  261. if(_downloadingArr.count == 0){
  262. _downloadingHeadView.hidden = YES;
  263. }
  264. else{
  265. _downloadingHeadView.hidden = NO;
  266. }
  267. }
  268. if(_failHeadView){
  269. NSString *leftStr = NSLocalizedString(@"File_upload_Record_download_fail",nil);
  270. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  271. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadfailArr.count];
  272. _failHeadView.titleLabel.text = titleStr;
  273. [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  274. if(_downloadfailArr.count == 0){
  275. _failHeadView.hidden = YES;
  276. }
  277. else{
  278. _failHeadView.hidden = NO;
  279. }
  280. }
  281. if(_doneHeadView){
  282. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_download",nil);
  283. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  284. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadDoneArr.count];
  285. _doneHeadView.titleLabel.text = titleStr;
  286. [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  287. if(_downloadDoneArr.count == 0){
  288. _doneHeadView.hidden = YES;
  289. }
  290. else{
  291. _doneHeadView.hidden = NO;
  292. }
  293. }
  294. }
  295. #pragma mark 点击全选
  296. - (void)setIsSelectAllType:(BOOL)isSelectAllType
  297. {
  298. //_selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
  299. _selectModelArr = [NSMutableArray new];
  300. [_selectModelArr addObjectsFromArray:_downloadingArr];
  301. [_selectModelArr addObjectsFromArray:_downloadfailArr];
  302. [_selectModelArr addObjectsFromArray:_downloadDoneArr];
  303. [self reloadDataFun];
  304. }
  305. -(void)setIsEditType:(BOOL)isEditType
  306. {
  307. _isEditType = isEditType;
  308. if(_isEditType){
  309. //_bgScrollV.scrollEnabled = NO;
  310. }
  311. else{
  312. //_bgScrollV.scrollEnabled = YES;
  313. [_selectModelArr removeAllObjects];
  314. }
  315. [self reloadDataFun];
  316. }
  317. #pragma mark cell长按时间
  318. - (void)didLongPressClickFun{
  319. self.isEditType = YES;
  320. if(self->_didLongPressClick){
  321. self->_didLongPressClick();
  322. }
  323. }
  324. #pragma mark 单个点击选中 取消
  325. - (void)selectModelOneByOne:(ShareFileDataModel*)model BySelect:(BOOL)isSelcet
  326. {
  327. if(isSelcet){
  328. [_selectModelArr addObject:model];
  329. }
  330. else{
  331. [_selectModelArr removeObject:model];
  332. }
  333. }
  334. #pragma mark 单个点击选中后删除
  335. - (void)deleteModelOneByOneFun{
  336. if(!_selectModelArr || _selectModelArr.count==0){
  337. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  338. [SVProgressHUD dismiss];
  339. });
  340. return;
  341. }
  342. [[boxDownloadFileManager shareInstance] deleteBoxSaveFileRecordBy:_selectModelArr];
  343. for (ShareFileDataModel *dataModel in _selectModelArr) {
  344. [self handleTotalArrByDelete:dataModel];
  345. }
  346. [_selectModelArr removeAllObjects];
  347. [self reloadDataFun];
  348. }
  349. - (void)handleTotalArrByDelete:(ShareFileDataModel*)delModel
  350. {
  351. if(delModel.downloadBoxStateType == downloadBoxStateDone)
  352. {
  353. NSMutableArray *arr = _downloadDoneArr;
  354. [self deteleModel:delModel inArr:arr];
  355. }
  356. else if(delModel.downloadBoxStateType == downloadBoxStateFail){
  357. NSMutableArray *arr = _downloadfailArr;
  358. [self deteleModel:delModel inArr:arr];
  359. }
  360. else{
  361. NSMutableArray *arr = _downloadingArr;
  362. [self deteleModel:delModel inArr:arr];
  363. }
  364. }
  365. #pragma mark 处理删除内存数据
  366. - (void)deteleModel:(ShareFileDataModel*)delModel inArr:(NSMutableArray*)delArr{
  367. for (ShareFileDataModel *dataModel in delArr) {
  368. if(delModel.bg_id.integerValue == dataModel.bg_id.integerValue){
  369. [delArr removeObject:dataModel];
  370. break;;
  371. }
  372. }
  373. }
  374. #pragma mark 处理上传中的 状态点击事件
  375. - (void)handleDownloadingStateTapFunBy:(BOOL)isSuspendType with:(couldPhoneFileModel*)model
  376. {
  377. // if (isSuspendType) {
  378. // [[downloadManager shareInstance] suspendDownloadFileFun:NO withModel:model];
  379. // }
  380. // else{
  381. // NSMutableArray*arr = [NSMutableArray new];
  382. // [arr addObject:model];
  383. // [[downloadManager shareInstance] reDownloadFileFunBy:arr withAll:NO];
  384. // }
  385. //
  386. // [self reloadDataFun];
  387. }
  388. #pragma mark 处理上传中的 状态点击事件
  389. - (void)handleUploadFailStateWith:(couldPhoneFileModel*)model{
  390. // [_downloadfailArr removeObject:model];
  391. // [_downloadingArr addObject:model];
  392. //
  393. // [self RefreshAllDataFun];
  394. //
  395. // if(_didClickReUploadBlock){
  396. // _didClickReUploadBlock(model);
  397. // }
  398. //
  399. // NSMutableArray*arr = [NSMutableArray new];
  400. // model.curDownloadStateType = downloadStateWait;
  401. // [arr addObject:model];
  402. // [[downloadManager shareInstance] reDownloadFileFunBy:arr withAll:NO];
  403. }
  404. @end