receiveDownloadRecordTableView.m 26 KB

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