receiveDownloadRecordTableView.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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. #import <YCDownloadSession.h>
  12. @interface receiveDownloadRecordTableView()<UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  13. {
  14. }
  15. @property (nonatomic, strong) NSMutableArray *curDataArr;
  16. @end
  17. @implementation receiveDownloadRecordTableView
  18. - (id)initWithFrame:(CGRect)frame {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self initCommon];
  22. [self initTableHeaderInSectionFun];
  23. _selectModelArr = [NSMutableArray new];
  24. _curDataArr = [NSMutableArray new];
  25. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskFinishedNotification object:nil];
  26. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskDownloadingNoti:) name:kDownloadTaskDownloadingNoti object:nil];
  27. }
  28. return self;
  29. }
  30. - (void)initCommon {
  31. self.delegate = self;
  32. self.dataSource = self;
  33. self.showsVerticalScrollIndicator = NO;
  34. self.showsHorizontalScrollIndicator = NO;
  35. [self setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  36. [self setSeparatorColor:[UIColor clearColor]];
  37. [self setBackgroundColor:[UIColor clearColor]];
  38. [self setTableFooterView:[UIView new]];
  39. [self setBounces:YES];
  40. if (@available(iOS 15.0, *)) {
  41. self.sectionHeaderTopPadding = 0;
  42. }
  43. //空数据引入第三方开源处理
  44. self.emptyDataSetSource = self;
  45. self.emptyDataSetDelegate = self;
  46. }
  47. - (void)setOutSideDataArr:(NSMutableArray *)outSideDataArr{
  48. if(!outSideDataArr || outSideDataArr.count != 3){
  49. return;
  50. }
  51. _outSideDataArr = outSideDataArr;
  52. _downloadingArr = [NSMutableArray new];
  53. for (ShareFileDataModel*model in outSideDataArr[0]) {
  54. [_downloadingArr addObject:model];
  55. }
  56. if(![boxDownloadFileManager shareInstance].isFirstAutoStartType){
  57. for (ShareFileDataModel*model in _downloadingArr) {
  58. if(model.downloadBoxStateType != downloadBoxStateSuspend){
  59. model.downloadBoxStateType = downloadBoxStateDownloadloading;
  60. }
  61. }
  62. }
  63. _downloadDoneArr = [NSMutableArray new];
  64. for (ShareFileDataModel*model in outSideDataArr[1]) {
  65. [_downloadDoneArr addObject:model];
  66. }
  67. _downloadfailArr = [NSMutableArray new];
  68. for (ShareFileDataModel*model in outSideDataArr[2]) {
  69. [_downloadfailArr addObject:model];
  70. }
  71. [self RefreshAllDataFun];
  72. }
  73. - (void)RefreshAllDataFun
  74. {
  75. NSMutableArray *totalArr = [NSMutableArray new];
  76. if(_downloadingArr.count>0){
  77. [totalArr addObject:_downloadingArr];
  78. }
  79. if(_downloadfailArr.count>0){
  80. [totalArr addObject:_downloadfailArr];
  81. }
  82. if(_downloadDoneArr.count>0){
  83. [totalArr addObject:_downloadDoneArr];
  84. }
  85. _curDataArr = totalArr;
  86. [self reloadDataFun];
  87. }
  88. #pragma mark - 列表委托
  89. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  90. return _curDataArr.count;
  91. }
  92. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  93. if(section < _curDataArr.count){
  94. NSArray *curArr = _curDataArr[section];
  95. return curArr.count;
  96. }
  97. return 0;
  98. }
  99. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  100. NSInteger row = indexPath.row;
  101. NSInteger section = indexPath.section;
  102. static NSString *identifier = @"boxDownloadFileRecordCell";
  103. boxDownloadFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  104. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  105. if (!cell){
  106. cell = [[boxDownloadFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  107. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  108. [cell setBackgroundColor:[UIColor clearColor]];
  109. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  110. }
  111. if(section < _curDataArr.count){
  112. NSMutableArray *curArr = _curDataArr[section];
  113. if(row < curArr.count){
  114. ShareFileDataModel *model = curArr[row];
  115. cell.curShareFileDataModel = model;
  116. cell.isEditType = _isEditType;
  117. // NSString *urlString = model.fileUrl;
  118. // NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  119. //
  120. // NSArray *urlallDownItemArr = [YCDownloadManager itemsWithDownloadUrl:requestURLEncodedString];
  121. // HLog(@"hxd urlallDownItemArr count: %ld --- %@",urlallDownItemArr.count,requestURLEncodedString);
  122. // if (urlallDownItemArr.count > 0 && section == 0 && model.downloadBoxStateType != downloadBoxStateDone) {
  123. // if (urlallDownItemArr.count == 1) {
  124. // YCDownloadItem * item = urlallDownItemArr.firstObject;
  125. // cell.item = item;
  126. // item.delegate = cell;
  127. // HLog(@"hxd downloadStatus:%ld %@",item.downloadStatus,item.downloadURL);
  128. // if(item.downloadStatus == YCDownloadStatusFinished){
  129. // [[NSNotificationCenter defaultCenter] postNotificationName:kDownloadTaskFinishedNoti object:item];
  130. // }
  131. // }
  132. // else{
  133. // for (YCDownloadItem *item in urlallDownItemArr) {
  134. // HLog(@"hxd downloadStatus:%ld %@",item.downloadStatus,item.downloadURL);
  135. // if (item.downloadStatus != YCDownloadStatusFinished
  136. // && item.downloadStatus != YCDownloadStatusFailed
  137. // //&& model.downloadBoxStateType == downloadBoxStateDownloadloading
  138. // ) {
  139. // cell.item = item;
  140. // item.delegate = cell;
  141. // break;
  142. // }
  143. // }
  144. // }
  145. //
  146. // }
  147. // else{
  148. //// cell.item.delegate = nil;
  149. //// cell.item = nil;
  150. // }
  151. if(_isEditType){
  152. if([_selectModelArr containsObject:model]){
  153. cell.isSelectType = YES;
  154. }
  155. else{
  156. cell.isSelectType = NO;
  157. }
  158. }
  159. KWeakSelf
  160. cell.didLongPressClick = ^{
  161. [weakSelf didLongPressClickFun];
  162. };
  163. cell.didClckSelectBut = ^(BOOL isSelect) {
  164. [weakSelf selectModelOneByOne:model BySelect:isSelect];
  165. };
  166. cell.didTapPressClick = ^{
  167. HLog(@"%@",model);
  168. if(model.downloadBoxStateType == downloadBoxStateDownloadloading){
  169. model.downloadBoxStateType = downloadBoxStateSuspend;
  170. [weakSelf handleDownloadingStateTapFunBy:YES with:model AtIndexPath:indexPath];
  171. }
  172. else if(model.downloadBoxStateType == downloadBoxStateSuspend){
  173. model.downloadBoxStateType = downloadBoxStateDownloadloading;
  174. [weakSelf handleDownloadingStateTapFunBy:NO with:model AtIndexPath:indexPath];
  175. }
  176. else if(model.downloadBoxStateType == downloadBoxStateFail){
  177. [weakSelf handleUploadFailStateWith:model AtIndexPath:indexPath];
  178. }
  179. };
  180. }
  181. }
  182. return cell;
  183. }
  184. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  185. return 70;
  186. }
  187. - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  188. {
  189. NSInteger curType = 0;// 0 上传中 1 失败 2 完成
  190. if(section == 2){
  191. curType = 2;
  192. }
  193. else if(section == 1){
  194. if(_downloadingArr.count == 0){
  195. curType = 2;
  196. }
  197. else if(_downloadfailArr.count == 0){
  198. curType = 2;
  199. }
  200. else{
  201. curType = 1;
  202. }
  203. }
  204. else{
  205. if(_downloadingArr.count > 0){
  206. curType = 0;
  207. }
  208. else if(_downloadfailArr.count > 0){
  209. curType = 1;
  210. }
  211. else{
  212. curType = 2;
  213. }
  214. }
  215. [self RefresHeadUIFun];
  216. if(curType == 2){
  217. return _doneHeadView;
  218. }
  219. else if(curType == 1){
  220. return _failHeadView;
  221. }
  222. else{
  223. return _downloadingHeadView;
  224. }
  225. }
  226. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  227. {
  228. return 40;
  229. }
  230. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  231. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  232. }
  233. #pragma mark 空数据
  234. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  235. NSString *imageName = @"common_no_data_pic";
  236. return [UIImage imageNamed:imageName];
  237. }
  238. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  239. NSString *text = NSLocalizedString(@"common_no_data_tip",nil);
  240. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  241. NSForegroundColorAttributeName: HW999999Color};
  242. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  243. }
  244. //调整图片位置
  245. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  246. return -150;
  247. }
  248. -(void)reloadDataFun{
  249. mainBlock(^{
  250. [self RefresHeadUIFun];
  251. [self reloadData];
  252. });
  253. }
  254. #pragma mark 初始化段头
  255. - (void)initTableHeaderInSectionFun
  256. {
  257. KWeakSelf
  258. if(!_downloadingHeadView){
  259. _downloadingHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  260. //headView.backgroundColor = [UIColor greenColor];
  261. NSString *leftStr = NSLocalizedString(@"File_upload_Record_downloading",nil);
  262. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  263. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  264. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadingArr.count];
  265. _downloadingHeadView.titleLabel.text = titleStr;
  266. [_downloadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  267. [_downloadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  268. _downloadingHeadView.didClickButFun = ^{
  269. [weakSelf didClickRightButtonFun:0];
  270. };
  271. }
  272. if(!_failHeadView){
  273. _failHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  274. //headView.backgroundColor = [UIColor greenColor];
  275. NSString *leftStr = NSLocalizedString(@"File_upload_Record_download_fail",nil);
  276. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  277. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadfailArr.count];
  278. _failHeadView.titleLabel.text = titleStr;
  279. [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  280. _failHeadView.didClickButFun = ^{
  281. [weakSelf didClickRightButtonFun:2];
  282. };
  283. }
  284. if(!_doneHeadView){
  285. _doneHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  286. //headView.backgroundColor = [UIColor greenColor];
  287. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_download",nil);
  288. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  289. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadDoneArr.count];
  290. _doneHeadView.titleLabel.text = titleStr;
  291. [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  292. _doneHeadView.didClickButFun = ^{
  293. [weakSelf didClickRightButtonFun:1];
  294. };
  295. }
  296. }
  297. #pragma mark 点击头部右边按钮
  298. - (void)didClickRightButtonFun:(NSInteger)section
  299. {
  300. if(_didClickSectionHeadViewRightButton){
  301. _didClickSectionHeadViewRightButton(section);
  302. }
  303. [self didClikRightButInUploadTableVieFunBy:section];
  304. }
  305. #pragma mark 下载文件列表的头部点击事件
  306. - (void)didClikRightButInUploadTableVieFunBy:(NSInteger)section
  307. {
  308. if(section == 0){
  309. [self didClickAllSuspendInLoadingFun];
  310. }
  311. else if(section == 1){//成功
  312. [self didClickClearRecordInDoneFun];
  313. }
  314. else if(section == 2){//失败
  315. [self didClickClearRecordInFailFun];
  316. }
  317. }
  318. #pragma mark 刷新头部数据
  319. -(void)RefresHeadUIFun
  320. {
  321. if(_downloadingHeadView){
  322. NSString *leftStr = NSLocalizedString(@"File_upload_Record_downloading",nil);
  323. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  324. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  325. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadingArr.count];
  326. _downloadingHeadView.titleLabel.text = titleStr;
  327. [_downloadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  328. [_downloadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  329. if(_downloadingArr.count == 0){
  330. _downloadingHeadView.hidden = YES;
  331. }
  332. else{
  333. _downloadingHeadView.hidden = NO;
  334. }
  335. BOOL isDownloadingType = YES;
  336. for (ShareFileDataModel*model in _downloadingArr) {
  337. if(model.downloadBoxStateType != downloadBoxStateDownloadloading){
  338. isDownloadingType = NO;
  339. break;
  340. }
  341. }
  342. //根据 isDownloadingType判断是否为全部下载状态
  343. if(isDownloadingType){
  344. _downloadingHeadView.rightButton.selected = NO;
  345. }
  346. else{
  347. _downloadingHeadView.rightButton.selected = YES;
  348. }
  349. }
  350. if(_failHeadView){
  351. NSString *leftStr = NSLocalizedString(@"File_upload_Record_download_fail",nil);
  352. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  353. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadfailArr.count];
  354. _failHeadView.titleLabel.text = titleStr;
  355. [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  356. if(_downloadfailArr.count == 0){
  357. _failHeadView.hidden = YES;
  358. }
  359. else{
  360. _failHeadView.hidden = NO;
  361. }
  362. }
  363. if(_doneHeadView){
  364. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_download",nil);
  365. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  366. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadDoneArr.count];
  367. _doneHeadView.titleLabel.text = titleStr;
  368. [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  369. if(_downloadDoneArr.count == 0){
  370. _doneHeadView.hidden = YES;
  371. }
  372. else{
  373. _doneHeadView.hidden = NO;
  374. }
  375. }
  376. }
  377. #pragma mark 点击全选
  378. - (void)setIsSelectAllType:(BOOL)isSelectAllType
  379. {
  380. //_selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
  381. _selectModelArr = [NSMutableArray new];
  382. if(isSelectAllType){
  383. [_selectModelArr addObjectsFromArray:_downloadingArr];
  384. [_selectModelArr addObjectsFromArray:_downloadfailArr];
  385. [_selectModelArr addObjectsFromArray:_downloadDoneArr];
  386. }
  387. [self reloadDataFun];
  388. }
  389. -(void)setIsEditType:(BOOL)isEditType
  390. {
  391. _isEditType = isEditType;
  392. if(_isEditType){
  393. //_bgScrollV.scrollEnabled = NO;
  394. }
  395. else{
  396. //_bgScrollV.scrollEnabled = YES;
  397. [_selectModelArr removeAllObjects];
  398. }
  399. [self reloadDataFun];
  400. }
  401. #pragma mark cell长按时间
  402. - (void)didLongPressClickFun{
  403. self.isEditType = YES;
  404. if(self->_didLongPressClick){
  405. self->_didLongPressClick();
  406. }
  407. }
  408. #pragma mark 单个点击选中 取消
  409. - (void)selectModelOneByOne:(ShareFileDataModel*)model BySelect:(BOOL)isSelcet
  410. {
  411. if(isSelcet){
  412. [_selectModelArr addObject:model];
  413. }
  414. else{
  415. [_selectModelArr removeObject:model];
  416. }
  417. }
  418. #pragma mark 单个点击选中后删除
  419. - (void)deleteModelOneByOneFun{
  420. if(!_selectModelArr || _selectModelArr.count==0){
  421. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  422. [SVProgressHUD dismiss];
  423. });
  424. return;
  425. }
  426. [[boxDownloadFileManager shareInstance] deleteBoxSaveFileRecordBy:_selectModelArr];
  427. for (ShareFileDataModel *dataModel in _selectModelArr) {
  428. [self handleTotalArrByDelete:dataModel];
  429. }
  430. [_selectModelArr removeAllObjects];
  431. [self reloadDataFun];
  432. }
  433. - (void)handleTotalArrByDelete:(ShareFileDataModel*)delModel
  434. {
  435. if(delModel.downloadBoxStateType == downloadBoxStateDone)
  436. {
  437. NSMutableArray *arr = _downloadDoneArr;
  438. [self deteleModel:delModel inArr:arr];
  439. }
  440. else if(delModel.downloadBoxStateType == downloadBoxStateFail){
  441. NSMutableArray *arr = _downloadfailArr;
  442. [self deteleModel:delModel inArr:arr];
  443. }
  444. else{
  445. NSMutableArray *arr = _downloadingArr;
  446. [self deteleModel:delModel inArr:arr];
  447. }
  448. }
  449. #pragma mark 处理删除内存数据
  450. - (void)deteleModel:(ShareFileDataModel*)delModel inArr:(NSMutableArray*)delArr{
  451. for (ShareFileDataModel *dataModel in delArr) {
  452. if(delModel.bg_id.integerValue == dataModel.bg_id.integerValue){
  453. [delArr removeObject:dataModel];
  454. break;;
  455. }
  456. }
  457. }
  458. #pragma mark 处理上传中的 状态点击事件
  459. - (void)handleDownloadingStateTapFunBy:(BOOL)isSuspendType with:(ShareFileDataModel*)model AtIndexPath:(NSIndexPath *)indexPath
  460. {
  461. boxDownloadFileRecordCell * cell = [self cellForRowAtIndexPath:indexPath];
  462. HLog(@"%d",isSuspendType);
  463. if(isSuspendType){
  464. HLog(@"supendDownloadWithUrl");
  465. [[boxDownloadFileManager shareInstance] suspendDownloadFileFun:NO withModel:model withItem:cell.item];
  466. }
  467. else{
  468. HLog(@"startDownLoadWithUrl");
  469. [[boxDownloadFileManager shareInstance] reDownloadFileFunBy:@[model] withAll:NO withItem:cell.item];
  470. }
  471. //[self reloadDataFun];
  472. if(indexPath){
  473. [self reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  474. }
  475. }
  476. #pragma mark 处理上传中的 状态点击事件
  477. - (void)handleUploadFailStateWith:(ShareFileDataModel*)model AtIndexPath:(NSIndexPath *)indexPath{
  478. [_downloadfailArr removeObject:model];
  479. model.downloadBoxStateType = downloadBoxStateDownloadloading;
  480. [_downloadingArr addObject:model];
  481. [self RefreshAllDataFun];
  482. [[boxDownloadFileManager shareInstance] updataBoxSaveDataInFailBy:model];
  483. boxDownloadFileRecordCell * cell = [self cellForRowAtIndexPath:indexPath];
  484. [[boxDownloadFileManager shareInstance] reDownloadFileFunBy:@[model] withAll:NO withItem:cell.item];
  485. }
  486. #pragma mark 点击上传中的全部暂停
  487. - (void)didClickAllSuspendInLoadingFun
  488. {
  489. //HLog(@"%@\n hhh %d",_downloadingHeadView,_downloadingHeadView.rightButton.selected);
  490. _downloadingHeadView.rightButton.selected = !_downloadingHeadView.rightButton.selected;
  491. if(_downloadingHeadView.rightButton.selected){
  492. HLog(@"suspendAllDownloadTask");
  493. for (ShareFileDataModel*dataModel in _downloadingArr) {
  494. dataModel.downloadBoxStateType = downloadBoxStateSuspend;
  495. }
  496. [[boxDownloadFileManager shareInstance] suspendDownloadFileFun:YES withModel:nil withItem:nil];
  497. [self reloadData];
  498. }
  499. else{
  500. HLog(@"startAllDownloadTask");
  501. for (ShareFileDataModel*dataModel in _downloadingArr) {
  502. dataModel.downloadBoxStateType = downloadBoxStateDownloadloading;
  503. }
  504. [[boxDownloadFileManager shareInstance] reDownloadFileFunBy:nil withAll:YES withItem:nil];
  505. [self reloadData];
  506. }
  507. }
  508. #pragma mark 点击上传成功的清空记录
  509. - (void)didClickClearRecordInDoneFun
  510. {
  511. /*弹窗提示二次确认*/
  512. KWeakSelf
  513. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
  514. msg:NSLocalizedString(@"File_upload_Record_clear_done_Tip_msg",nil)
  515. imageStr:nil
  516. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  517. okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
  518. didClickOk:^{
  519. [weakSelf ClearAllRecordInDoneFun];
  520. } didClickCancel:^{
  521. }];
  522. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  523. [[iTools appRootViewController] presentViewController:nextVC animated:YES completion:^{
  524. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  525. }];
  526. }
  527. - (void)ClearAllRecordInDoneFun
  528. {
  529. [[boxDownloadFileManager shareInstance] deleteBoxSaveFileRecordBy:_downloadDoneArr];
  530. [_downloadDoneArr removeAllObjects];
  531. [self RefreshAllDataFun];
  532. }
  533. #pragma mark 点击上传失败的清空记录
  534. - (void)didClickClearRecordInFailFun
  535. {
  536. /*弹窗提示二次确认*/
  537. KWeakSelf
  538. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
  539. msg:NSLocalizedString(@"File_upload_Record_clear_fail_Tip_msg",nil)
  540. imageStr:nil
  541. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  542. okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
  543. didClickOk:^{
  544. [weakSelf ClearAllRecordInFailFun];
  545. } didClickCancel:^{
  546. }];
  547. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  548. [[iTools appRootViewController] presentViewController:nextVC animated:YES completion:^{
  549. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  550. }];
  551. }
  552. - (void)ClearAllRecordInFailFun
  553. {
  554. [[boxDownloadFileManager shareInstance] deleteBoxSaveFileRecordBy:_downloadfailArr];
  555. [_downloadfailArr removeAllObjects];
  556. [self RefreshAllDataFun];
  557. }
  558. #pragma mark 下载完成
  559. - (void)downloadTaskFinishedNoti:(NSNotification *)notification
  560. {
  561. YCDownloadItem *item = notification.object;
  562. KWeakSelf
  563. if (item.downloadStatus == YCDownloadStatusFinished) {
  564. HLog(@"下载完成");
  565. mainBlock(^{
  566. [weakSelf handldDownloadDoneDataBy:item];
  567. });
  568. }
  569. else if (item.downloadStatus == YCDownloadStatusFailed){
  570. HLog(@"下载失败");
  571. mainBlock(^{
  572. [weakSelf handldDownloadFailDataBy:item];
  573. });
  574. }
  575. }
  576. #pragma mark 下载通知
  577. - (void)downloadTaskDownloadingNoti:(NSNotification *)notification
  578. {
  579. YCDownloadItem *item = notification.object;
  580. if(!item)return;
  581. if (item.downloadStatus != YCDownloadStatusDownloading) {
  582. return;
  583. }
  584. //解码
  585. NSString * urlString = [item.downloadURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  586. //HLog(@"下载中:%lld --- %lld \n%@\n%@",downloadedSize,totalSize,urlString,_curShareFileDataModel.fileUrl);
  587. for (ShareFileDataModel*model in _downloadingArr) {
  588. if([model.fileUrl isEqualToString:urlString]){
  589. model.currentSize = item.downloadedSize;
  590. model.curTimeInterval = [[NSDate date] timeIntervalSince1970];
  591. break;
  592. }
  593. }
  594. [self reloadData];
  595. }
  596. //- (void)downloadTaskExeEnd:(NSNotification *)notification
  597. //{
  598. // SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
  599. //
  600. // KWeakSelf
  601. // mainBlock(^{
  602. // [weakSelf handldDownloadDoneDataBy:model];
  603. // [weakSelf handldDownloadDoneToSaveBy:model];
  604. //
  605. // });
  606. // HLog(@"下载成功 %@",model.fileName);
  607. //}
  608. //- (void)downloadTaskExeError:(NSNotification *)notification
  609. //{
  610. // SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
  611. //
  612. // KWeakSelf
  613. // mainBlock(^{
  614. // [weakSelf handldDownloadFailDataBy:model];
  615. // });
  616. // HLog(@"下载失败");
  617. //}
  618. #pragma mark 第一次进来 检测重新下载
  619. - (void)reDownLoadAgainFun
  620. {
  621. if([boxDownloadFileManager shareInstance].isFirstAutoStartType){
  622. return;
  623. }
  624. else{
  625. [boxDownloadFileManager shareInstance].isFirstAutoStartType = YES;
  626. }
  627. //重新下载
  628. //[YCDownloadManager resumeAllDownloadTask];
  629. NSArray *allDownItemArr = [YCDownloadManager downloadList];
  630. for (YCDownloadItem *item in allDownItemArr) {
  631. if (item.downloadStatus != YCDownloadStatusFailed
  632. && item.downloadStatus != YCDownloadStatusFinished
  633. && item.downloadStatus != YCDownloadStatusPaused) {
  634. //[YCDownloadManager startDownloadWithItem:item];
  635. [YCDownloadManager resumeDownloadWithItem:item];
  636. }
  637. }
  638. }
  639. #pragma mark 下载失败数据回调处理
  640. - (void)handldDownloadFailDataBy:(YCDownloadItem*)item
  641. {
  642. for (ShareFileDataModel*dataModel in _downloadingArr) {
  643. NSString * urlString = [item.downloadURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  644. HLog(@"22222222 %@\n%@",urlString,dataModel.fileUrl);
  645. if([urlString isEqualToString:dataModel.fileUrl]){
  646. //dataModel.totalSize = model.totalSize;
  647. dataModel.currentSize = item.downloadedSize;
  648. dataModel.downloadBoxStateType = downloadBoxStateFail;
  649. [_downloadfailArr insertObject:dataModel atIndex:0];
  650. [_downloadingArr removeObject:dataModel];
  651. break;
  652. }
  653. }
  654. [self RefreshAllDataFun];
  655. }
  656. #pragma mark 下载完成数据回调处理
  657. - (void)handldDownloadDoneDataBy:(YCDownloadItem*)item
  658. {
  659. //解码
  660. NSString * urlString = [item.downloadURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  661. for (ShareFileDataModel*dataModel in _downloadingArr) {
  662. HLog(@"22222222 %@\n%@",urlString,dataModel.fileUrl);
  663. if([urlString isEqualToString:dataModel.fileUrl]){
  664. dataModel.downloadBoxStateType = downloadBoxStateDone;
  665. [_downloadDoneArr insertObject:dataModel atIndex:0];
  666. [_downloadingArr removeObject:dataModel];
  667. break;
  668. }
  669. }
  670. [self RefreshAllDataFun];
  671. }
  672. @end