receiveDownloadRecordTableView.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. //
  2. // receiveDownloadRecordTableView.m
  3. // Private-X
  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 "customDownloadManager.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:nasShareDownloadTaskFinishedNotification 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 *leftText = NSLocalizedString(@"common_no_data_tip",nil);
  239. NSString *rightText = NSLocalizedString(@"share_download_notData_Tips",nil);
  240. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@\n\n%@",leftText,rightText];
  241. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  242. NSRange leftRange = NSMakeRange([totalStr rangeOfString:leftText].location, [totalStr rangeOfString:leftText].length);
  243. UIColor *leftColor =[UIColor hwColor:@"#666666" alpha:1.0];
  244. [attrStr addAttribute:NSForegroundColorAttributeName value:leftColor range:leftRange];
  245. [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.0] range:leftRange];
  246. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightText].location, [totalStr rangeOfString:rightText].length);
  247. UIColor *noteColor =[UIColor hwColor:@"#959799" alpha:1.0];
  248. [attrStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
  249. [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  250. // 创建一个NSMutableParagraphStyle对象
  251. // NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  252. // paragraphStyle.lineSpacing = 10; // 行间距设置为10
  253. // [attrStr addAttribute:NSParagraphStyleAttributeName
  254. // value:paragraphStyle
  255. // range:NSMakeRange(0, totalStr.length)];
  256. return attrStr;
  257. }
  258. //调整图片位置
  259. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  260. return -150;
  261. }
  262. -(void)reloadDataFun{
  263. mainBlock(^{
  264. [self RefresHeadUIFun];
  265. [self reloadData];
  266. });
  267. }
  268. #pragma mark 初始化段头
  269. - (void)initTableHeaderInSectionFun
  270. {
  271. KWeakSelf
  272. if(!_downloadingHeadView){
  273. _downloadingHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  274. //headView.backgroundColor = [UIColor greenColor];
  275. NSString *leftStr = NSLocalizedString(@"File_upload_Record_downloading",nil);
  276. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  277. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  278. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadingArr.count];
  279. _downloadingHeadView.titleLabel.text = titleStr;
  280. [_downloadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  281. [_downloadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  282. _downloadingHeadView.didClickButFun = ^{
  283. [weakSelf didClickRightButtonFun:0];
  284. };
  285. }
  286. if(!_failHeadView){
  287. _failHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  288. //headView.backgroundColor = [UIColor greenColor];
  289. NSString *leftStr = NSLocalizedString(@"File_upload_Record_download_fail",nil);
  290. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  291. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadfailArr.count];
  292. _failHeadView.titleLabel.text = titleStr;
  293. [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  294. _failHeadView.didClickButFun = ^{
  295. [weakSelf didClickRightButtonFun:2];
  296. };
  297. }
  298. if(!_doneHeadView){
  299. _doneHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  300. //headView.backgroundColor = [UIColor greenColor];
  301. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_download",nil);
  302. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  303. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadDoneArr.count];
  304. _doneHeadView.titleLabel.text = titleStr;
  305. [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  306. _doneHeadView.didClickButFun = ^{
  307. [weakSelf didClickRightButtonFun:1];
  308. };
  309. }
  310. }
  311. #pragma mark 点击头部右边按钮
  312. - (void)didClickRightButtonFun:(NSInteger)section
  313. {
  314. if(_didClickSectionHeadViewRightButton){
  315. _didClickSectionHeadViewRightButton(section);
  316. }
  317. [self didClikRightButInUploadTableVieFunBy:section];
  318. }
  319. #pragma mark 下载文件列表的头部点击事件
  320. - (void)didClikRightButInUploadTableVieFunBy:(NSInteger)section
  321. {
  322. if(section == 0){
  323. [self didClickAllSuspendInLoadingFun];
  324. }
  325. else if(section == 1){//成功
  326. [self didClickClearRecordInDoneFun];
  327. }
  328. else if(section == 2){//失败
  329. [self didClickClearRecordInFailFun];
  330. }
  331. }
  332. #pragma mark 刷新头部数据
  333. -(void)RefresHeadUIFun
  334. {
  335. if(_downloadingHeadView){
  336. NSString *leftStr = NSLocalizedString(@"File_upload_Record_downloading",nil);
  337. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  338. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  339. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadingArr.count];
  340. _downloadingHeadView.titleLabel.text = titleStr;
  341. [_downloadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  342. [_downloadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  343. if(_downloadingArr.count == 0){
  344. _downloadingHeadView.hidden = YES;
  345. }
  346. else{
  347. _downloadingHeadView.hidden = NO;
  348. }
  349. BOOL isDownloadingType = YES;
  350. for (ShareFileDataModel*model in _downloadingArr) {
  351. if(model.downloadBoxStateType != downloadBoxStateDownloadloading){
  352. isDownloadingType = NO;
  353. break;
  354. }
  355. }
  356. //根据 isDownloadingType判断是否为全部下载状态
  357. if(isDownloadingType){
  358. _downloadingHeadView.rightButton.selected = NO;
  359. }
  360. else{
  361. _downloadingHeadView.rightButton.selected = YES;
  362. }
  363. }
  364. if(_failHeadView){
  365. NSString *leftStr = NSLocalizedString(@"File_upload_Record_download_fail",nil);
  366. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  367. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadfailArr.count];
  368. _failHeadView.titleLabel.text = titleStr;
  369. [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  370. if(_downloadfailArr.count == 0){
  371. _failHeadView.hidden = YES;
  372. }
  373. else{
  374. _failHeadView.hidden = NO;
  375. }
  376. }
  377. if(_doneHeadView){
  378. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_download",nil);
  379. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  380. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadDoneArr.count];
  381. _doneHeadView.titleLabel.text = titleStr;
  382. [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  383. if(_downloadDoneArr.count == 0){
  384. _doneHeadView.hidden = YES;
  385. }
  386. else{
  387. _doneHeadView.hidden = NO;
  388. }
  389. }
  390. }
  391. #pragma mark 点击全选
  392. - (void)setIsSelectAllType:(BOOL)isSelectAllType
  393. {
  394. //_selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
  395. _selectModelArr = [NSMutableArray new];
  396. if(isSelectAllType){
  397. [_selectModelArr addObjectsFromArray:_downloadingArr];
  398. [_selectModelArr addObjectsFromArray:_downloadfailArr];
  399. [_selectModelArr addObjectsFromArray:_downloadDoneArr];
  400. }
  401. [self reloadDataFun];
  402. }
  403. -(void)setIsEditType:(BOOL)isEditType
  404. {
  405. _isEditType = isEditType;
  406. if(_isEditType){
  407. //_bgScrollV.scrollEnabled = NO;
  408. }
  409. else{
  410. //_bgScrollV.scrollEnabled = YES;
  411. [_selectModelArr removeAllObjects];
  412. }
  413. [self reloadDataFun];
  414. }
  415. #pragma mark cell长按时间
  416. - (void)didLongPressClickFun{
  417. self.isEditType = YES;
  418. if(self->_didLongPressClick){
  419. self->_didLongPressClick();
  420. }
  421. }
  422. #pragma mark 单个点击选中 取消
  423. - (void)selectModelOneByOne:(ShareFileDataModel*)model BySelect:(BOOL)isSelcet
  424. {
  425. if(isSelcet){
  426. [_selectModelArr addObject:model];
  427. }
  428. else{
  429. [_selectModelArr removeObject:model];
  430. }
  431. }
  432. #pragma mark 单个点击选中后删除
  433. - (void)deleteModelOneByOneFun{
  434. if(!_selectModelArr || _selectModelArr.count==0){
  435. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  436. [SVProgressHUD dismiss];
  437. });
  438. return;
  439. }
  440. [[boxDownloadFileManager shareInstance] deleteBoxSaveFileRecordBy:_selectModelArr];
  441. for (ShareFileDataModel *dataModel in _selectModelArr) {
  442. [self handleTotalArrByDelete:dataModel];
  443. }
  444. [_selectModelArr removeAllObjects];
  445. [self reloadDataFun];
  446. }
  447. - (void)handleTotalArrByDelete:(ShareFileDataModel*)delModel
  448. {
  449. if(delModel.downloadBoxStateType == downloadBoxStateDone)
  450. {
  451. NSMutableArray *arr = _downloadDoneArr;
  452. [self deteleModel:delModel inArr:arr];
  453. }
  454. else if(delModel.downloadBoxStateType == downloadBoxStateFail){
  455. NSMutableArray *arr = _downloadfailArr;
  456. [self deteleModel:delModel inArr:arr];
  457. }
  458. else{
  459. NSMutableArray *arr = _downloadingArr;
  460. [self deteleModel:delModel inArr:arr];
  461. }
  462. }
  463. #pragma mark 处理删除内存数据
  464. - (void)deteleModel:(ShareFileDataModel*)delModel inArr:(NSMutableArray*)delArr{
  465. for (ShareFileDataModel *dataModel in delArr) {
  466. if(delModel.bg_id.integerValue == dataModel.bg_id.integerValue){
  467. [delArr removeObject:dataModel];
  468. break;;
  469. }
  470. }
  471. }
  472. #pragma mark 处理上传中的 状态点击事件
  473. - (void)handleDownloadingStateTapFunBy:(BOOL)isSuspendType with:(ShareFileDataModel*)model AtIndexPath:(NSIndexPath *)indexPath
  474. {
  475. //boxDownloadFileRecordCell * cell = [self cellForRowAtIndexPath:indexPath];
  476. HLog(@"%d",isSuspendType);
  477. if(isSuspendType){
  478. HLog(@"supendDownloadWithUrl");
  479. [[boxDownloadFileManager shareInstance] suspendDownloadFileFun:NO withModel:model];
  480. }
  481. else{
  482. HLog(@"startDownLoadWithUrl");
  483. NSMutableArray *curArr = [NSMutableArray arrayWithArray:@[model]];
  484. [[boxDownloadFileManager shareInstance] reDownloadFileFunBy:curArr withAll:NO];
  485. }
  486. //[self reloadDataFun];
  487. if(indexPath){
  488. [self reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  489. }
  490. }
  491. #pragma mark 处理上传中的 状态点击事件
  492. - (void)handleUploadFailStateWith:(ShareFileDataModel*)model AtIndexPath:(NSIndexPath *)indexPath{
  493. [_downloadfailArr removeObject:model];
  494. model.downloadBoxStateType = downloadBoxStateDownloadloading;
  495. [_downloadingArr addObject:model];
  496. [self RefreshAllDataFun];
  497. [[boxDownloadFileManager shareInstance] updataBoxSaveDataInFailBy:model];
  498. //boxDownloadFileRecordCell * cell = [self cellForRowAtIndexPath:indexPath];
  499. NSMutableArray *curArr = [NSMutableArray arrayWithArray:@[model]];
  500. [[boxDownloadFileManager shareInstance] reDownloadFileFunBy:curArr withAll:NO];
  501. }
  502. #pragma mark 点击上传中的全部暂停
  503. - (void)didClickAllSuspendInLoadingFun
  504. {
  505. //HLog(@"%@\n hhh %d",_downloadingHeadView,_downloadingHeadView.rightButton.selected);
  506. _downloadingHeadView.rightButton.selected = !_downloadingHeadView.rightButton.selected;
  507. if(_downloadingHeadView.rightButton.selected){
  508. HLog(@"suspendAllDownloadTask");
  509. for (ShareFileDataModel*dataModel in _downloadingArr) {
  510. dataModel.downloadBoxStateType = downloadBoxStateSuspend;
  511. }
  512. [[boxDownloadFileManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
  513. [self reloadData];
  514. }
  515. else{
  516. HLog(@"startAllDownloadTask");
  517. for (ShareFileDataModel*dataModel in _downloadingArr) {
  518. dataModel.downloadBoxStateType = downloadBoxStateDownloadloading;
  519. }
  520. [[boxDownloadFileManager shareInstance] reDownloadFileFunBy:nil withAll:YES];
  521. [self reloadData];
  522. }
  523. }
  524. #pragma mark 点击上传成功的清空记录
  525. - (void)didClickClearRecordInDoneFun
  526. {
  527. /*弹窗提示二次确认*/
  528. KWeakSelf
  529. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
  530. msg:NSLocalizedString(@"File_upload_Record_clear_done_Tip_msg",nil)
  531. imageStr:@""
  532. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  533. okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
  534. didClickOk:^{
  535. [weakSelf ClearAllRecordInDoneFun];
  536. } didClickCancel:^{
  537. }];
  538. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  539. [[iTools appRootViewController] presentViewController:nextVC animated:YES completion:^{
  540. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  541. }];
  542. }
  543. - (void)ClearAllRecordInDoneFun
  544. {
  545. [[boxDownloadFileManager shareInstance] deleteBoxSaveFileRecordBy:_downloadDoneArr];
  546. [_downloadDoneArr removeAllObjects];
  547. [self RefreshAllDataFun];
  548. }
  549. #pragma mark 点击上传失败的清空记录
  550. - (void)didClickClearRecordInFailFun
  551. {
  552. /*弹窗提示二次确认*/
  553. KWeakSelf
  554. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
  555. msg:NSLocalizedString(@"File_upload_Record_clear_fail_Tip_msg",nil)
  556. imageStr:@""
  557. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  558. okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
  559. didClickOk:^{
  560. [weakSelf ClearAllRecordInFailFun];
  561. } didClickCancel:^{
  562. }];
  563. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  564. [[iTools appRootViewController] presentViewController:nextVC animated:YES completion:^{
  565. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  566. }];
  567. }
  568. - (void)ClearAllRecordInFailFun
  569. {
  570. [[boxDownloadFileManager shareInstance] deleteBoxSaveFileRecordBy:_downloadfailArr];
  571. [_downloadfailArr removeAllObjects];
  572. [self RefreshAllDataFun];
  573. }
  574. #pragma mark 下载完成
  575. - (void)downloadTaskFinishedNoti:(NSNotification *)notification
  576. {
  577. customDownloadOperation *model = notification.object;
  578. NSString *url = model.url;
  579. KWeakSelf
  580. if (model.downloadState == customDownloadStateCompleted) {
  581. HLog(@"下载完成");
  582. mainBlock(^{
  583. [weakSelf handldDownloadDoneDataBy:url];
  584. });
  585. }
  586. else if (model.downloadState == customDownloadStateFailed){
  587. HLog(@"下载失败");
  588. mainBlock(^{
  589. [weakSelf handldDownloadFailDataBy:url];
  590. });
  591. }
  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. [[boxDownloadFileManager shareInstance] checkDownloadDonePlistInfoFun];
  614. //重新下载
  615. [[boxDownloadFileManager shareInstance] firstReDownloadAllFileFun];
  616. }
  617. #pragma mark 下载失败数据回调处理
  618. - (void)handldDownloadFailDataBy:(NSString*)url
  619. {
  620. NSString * urlString = [url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  621. for (ShareFileDataModel*dataModel in _downloadingArr) {
  622. //HLog(@"22222222 %@\n%@",urlString,dataModel.fileUrl);
  623. if([urlString isEqualToString:dataModel.fileUrl]){
  624. //dataModel.totalSize = model.totalSize;
  625. //dataModel.currentSize = model.currentSize;
  626. dataModel.downloadBoxStateType = downloadBoxStateFail;
  627. [_downloadfailArr insertObject:dataModel atIndex:0];
  628. [_downloadingArr removeObject:dataModel];
  629. break;
  630. }
  631. }
  632. [self RefreshAllDataFun];
  633. }
  634. #pragma mark 下载完成数据回调处理
  635. - (void)handldDownloadDoneDataBy:(NSString*)url
  636. {
  637. //解码
  638. NSString * urlString = [url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  639. for (ShareFileDataModel*dataModel in _downloadingArr) {
  640. HLog(@"22222222 %@\n%@",urlString,dataModel.fileUrl);
  641. if([urlString isEqualToString:dataModel.fileUrl]){
  642. dataModel.downloadBoxStateType = downloadBoxStateDone;
  643. [_downloadDoneArr insertObject:dataModel atIndex:0];
  644. [_downloadingArr removeObject:dataModel];
  645. break;
  646. }
  647. }
  648. [self RefreshAllDataFun];
  649. }
  650. @end