receiveDownloadRecordTableView.m 27 KB

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