receiveDownloadRecordTableView.m 26 KB

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