123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813 |
- //
- // receiveDownloadRecordTableView.m
- // 双子星云手机
- //
- // Created by xd h on 2024/5/23.
- //
- #import "receiveDownloadRecordTableView.h"
- #import "boxDownloadFileRecordCell.h"
- #import "UIScrollView+EmptyDataSet.h"
- #import "uploadFileRecordTableViewHeadView.h"
- #import "customDownloadManager.h"
- @interface receiveDownloadRecordTableView()<UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
- {
-
- }
- @property (nonatomic, strong) NSMutableArray *curDataArr;
- @end
- @implementation receiveDownloadRecordTableView
- - (id)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self initCommon];
- [self initTableHeaderInSectionFun];
- _selectModelArr = [NSMutableArray new];
- _curDataArr = [NSMutableArray new];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasShareDownloadTaskFinishedNotification object:nil];
-
- }
- return self;
- }
- - (void)initCommon {
- self.delegate = self;
- self.dataSource = self;
- self.showsVerticalScrollIndicator = NO;
- self.showsHorizontalScrollIndicator = NO;
- [self setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
- [self setSeparatorColor:[UIColor clearColor]];
- [self setBackgroundColor:[UIColor clearColor]];
- [self setTableFooterView:[UIView new]];
- [self setBounces:YES];
- if (@available(iOS 15.0, *)) {
- self.sectionHeaderTopPadding = 0;
- }
-
- //空数据引入第三方开源处理
- self.emptyDataSetSource = self;
- self.emptyDataSetDelegate = self;
- }
- - (void)setOutSideDataArr:(NSMutableArray *)outSideDataArr{
-
- if(!outSideDataArr || outSideDataArr.count != 3){
- return;
- }
-
- _outSideDataArr = outSideDataArr;
-
- _downloadingArr = [NSMutableArray new];
- for (ShareFileDataModel*model in outSideDataArr[0]) {
- [_downloadingArr addObject:model];
- }
-
- if(![boxDownloadFileManager shareInstance].isFirstAutoStartType){
- for (ShareFileDataModel*model in _downloadingArr) {
- if(model.downloadBoxStateType != downloadBoxStateSuspend){
- model.downloadBoxStateType = downloadBoxStateDownloadloading;
- }
- }
- }
-
- _downloadDoneArr = [NSMutableArray new];
- for (ShareFileDataModel*model in outSideDataArr[1]) {
- [_downloadDoneArr addObject:model];
- }
-
-
- _downloadfailArr = [NSMutableArray new];
- for (ShareFileDataModel*model in outSideDataArr[2]) {
- [_downloadfailArr addObject:model];
- }
-
- [self RefreshAllDataFun];
- }
- - (void)RefreshAllDataFun
- {
- NSMutableArray *totalArr = [NSMutableArray new];
-
- if(_downloadingArr.count>0){
- [totalArr addObject:_downloadingArr];
- }
-
- if(_downloadfailArr.count>0){
- [totalArr addObject:_downloadfailArr];
- }
-
- if(_downloadDoneArr.count>0){
- [totalArr addObject:_downloadDoneArr];
- }
-
- _curDataArr = totalArr;
-
- [self reloadDataFun];
- }
- #pragma mark - 列表委托
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return _curDataArr.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-
- if(section < _curDataArr.count){
- NSArray *curArr = _curDataArr[section];
- return curArr.count;
- }
-
- return 0;
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- NSInteger row = indexPath.row;
- NSInteger section = indexPath.section;
- static NSString *identifier = @"boxDownloadFileRecordCell";
-
- boxDownloadFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- if (!cell){
- cell = [[boxDownloadFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
- [cell setBackgroundColor:[UIColor clearColor]];
- [cell setAccessoryType:(UITableViewCellAccessoryNone)];
- }
-
- if(section < _curDataArr.count){
- NSMutableArray *curArr = _curDataArr[section];
-
- if(row < curArr.count){
- ShareFileDataModel *model = curArr[row];
- cell.curShareFileDataModel = model;
-
- cell.isEditType = _isEditType;
-
- // NSString *urlString = model.fileUrl;
- // NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- //
- // NSArray *urlallDownItemArr = [YCDownloadManager itemsWithDownloadUrl:requestURLEncodedString];
- // HLog(@"hxd urlallDownItemArr count: %ld --- %@",urlallDownItemArr.count,requestURLEncodedString);
- // if (urlallDownItemArr.count > 0 && section == 0 && model.downloadBoxStateType != downloadBoxStateDone) {
- // if (urlallDownItemArr.count == 1) {
- // YCDownloadItem * item = urlallDownItemArr.firstObject;
- // cell.item = item;
- // item.delegate = cell;
- // HLog(@"hxd downloadStatus:%ld %@",item.downloadStatus,item.downloadURL);
- // if(item.downloadStatus == YCDownloadStatusFinished){
- // [[NSNotificationCenter defaultCenter] postNotificationName:kDownloadTaskFinishedNoti object:item];
- // }
- // }
- // else{
- // for (YCDownloadItem *item in urlallDownItemArr) {
- // HLog(@"hxd downloadStatus:%ld %@",item.downloadStatus,item.downloadURL);
- // if (item.downloadStatus != YCDownloadStatusFinished
- // && item.downloadStatus != YCDownloadStatusFailed
- // //&& model.downloadBoxStateType == downloadBoxStateDownloadloading
- // ) {
- // cell.item = item;
- // item.delegate = cell;
- // break;
- // }
- // }
- // }
- //
- // }
- // else{
- //// cell.item.delegate = nil;
- //// cell.item = nil;
- // }
-
-
-
- if(_isEditType){
- if([_selectModelArr containsObject:model]){
- cell.isSelectType = YES;
- }
- else{
- cell.isSelectType = NO;
- }
- }
-
- KWeakSelf
- cell.didLongPressClick = ^{
- [weakSelf didLongPressClickFun];
- };
- cell.didClckSelectBut = ^(BOOL isSelect) {
- [weakSelf selectModelOneByOne:model BySelect:isSelect];
- };
- cell.didTapPressClick = ^{
- HLog(@"%@",model);
- if(model.downloadBoxStateType == downloadBoxStateDownloadloading){
- model.downloadBoxStateType = downloadBoxStateSuspend;
- [weakSelf handleDownloadingStateTapFunBy:YES with:model AtIndexPath:indexPath];
- }
- else if(model.downloadBoxStateType == downloadBoxStateSuspend){
- model.downloadBoxStateType = downloadBoxStateDownloadloading;
- [weakSelf handleDownloadingStateTapFunBy:NO with:model AtIndexPath:indexPath];
- }
- else if(model.downloadBoxStateType == downloadBoxStateFail){
- [weakSelf handleUploadFailStateWith:model AtIndexPath:indexPath];
- }
- };
- }
- }
-
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 70;
- }
- - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- NSInteger curType = 0;// 0 上传中 1 失败 2 完成
- if(section == 2){
- curType = 2;
- }
- else if(section == 1){
- if(_downloadingArr.count == 0){
- curType = 2;
- }
- else if(_downloadfailArr.count == 0){
- curType = 2;
- }
- else{
- curType = 1;
- }
- }
- else{
- if(_downloadingArr.count > 0){
- curType = 0;
- }
- else if(_downloadfailArr.count > 0){
- curType = 1;
- }
- else{
- curType = 2;
- }
- }
-
-
- [self RefresHeadUIFun];
-
- if(curType == 2){
- return _doneHeadView;
- }
- else if(curType == 1){
- return _failHeadView;
- }
- else{
- return _downloadingHeadView;
- }
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 40;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- }
- #pragma mark 空数据
- - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
-
- NSString *imageName = @"common_no_data_pic";
-
- return [UIImage imageNamed:imageName];
- }
- - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
-
- NSString *leftText = NSLocalizedString(@"common_no_data_tip",nil);
- NSString *rightText = NSLocalizedString(@"share_download_notData_Tips",nil);
- NSString *totalStr = [[NSString alloc] initWithFormat:@"%@\n\n%@",leftText,rightText];
-
- NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
-
- NSRange leftRange = NSMakeRange([totalStr rangeOfString:leftText].location, [totalStr rangeOfString:leftText].length);
- UIColor *leftColor =[UIColor hwColor:@"#666666" alpha:1.0];
- [attrStr addAttribute:NSForegroundColorAttributeName value:leftColor range:leftRange];
- [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.0] range:leftRange];
-
- NSRange redRange = NSMakeRange([totalStr rangeOfString:rightText].location, [totalStr rangeOfString:rightText].length);
- UIColor *noteColor =[UIColor hwColor:@"#959799" alpha:1.0];
- [attrStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
- [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
-
- // 创建一个NSMutableParagraphStyle对象
- // NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- // paragraphStyle.lineSpacing = 10; // 行间距设置为10
- // [attrStr addAttribute:NSParagraphStyleAttributeName
- // value:paragraphStyle
- // range:NSMakeRange(0, totalStr.length)];
-
- return attrStr;
- }
- //调整图片位置
- - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
- return -150;
- }
- -(void)reloadDataFun{
- mainBlock(^{
- [self RefresHeadUIFun];
- [self reloadData];
- });
- }
- #pragma mark 初始化段头
- - (void)initTableHeaderInSectionFun
- {
- KWeakSelf
- if(!_downloadingHeadView){
- _downloadingHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
- //headView.backgroundColor = [UIColor greenColor];
-
- NSString *leftStr = NSLocalizedString(@"File_upload_Record_downloading",nil);
- NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
- NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
- NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadingArr.count];
- _downloadingHeadView.titleLabel.text = titleStr;
- [_downloadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
- [_downloadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
-
- _downloadingHeadView.didClickButFun = ^{
- [weakSelf didClickRightButtonFun:0];
- };
- }
-
- if(!_failHeadView){
- _failHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
- //headView.backgroundColor = [UIColor greenColor];
-
- NSString *leftStr = NSLocalizedString(@"File_upload_Record_download_fail",nil);
- NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
- NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadfailArr.count];
- _failHeadView.titleLabel.text = titleStr;
- [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
-
- _failHeadView.didClickButFun = ^{
- [weakSelf didClickRightButtonFun:2];
- };
- }
-
- if(!_doneHeadView){
- _doneHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
- //headView.backgroundColor = [UIColor greenColor];
-
- NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_download",nil);
- NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
- NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadDoneArr.count];
- _doneHeadView.titleLabel.text = titleStr;
- [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
-
- _doneHeadView.didClickButFun = ^{
- [weakSelf didClickRightButtonFun:1];
- };
- }
-
-
- }
- #pragma mark 点击头部右边按钮
- - (void)didClickRightButtonFun:(NSInteger)section
- {
- if(_didClickSectionHeadViewRightButton){
- _didClickSectionHeadViewRightButton(section);
- }
-
- [self didClikRightButInUploadTableVieFunBy:section];
- }
- #pragma mark 下载文件列表的头部点击事件
- - (void)didClikRightButInUploadTableVieFunBy:(NSInteger)section
- {
- if(section == 0){
- [self didClickAllSuspendInLoadingFun];
- }
- else if(section == 1){//成功
- [self didClickClearRecordInDoneFun];
- }
- else if(section == 2){//失败
- [self didClickClearRecordInFailFun];
- }
- }
- #pragma mark 刷新头部数据
- -(void)RefresHeadUIFun
- {
- if(_downloadingHeadView){
- NSString *leftStr = NSLocalizedString(@"File_upload_Record_downloading",nil);
- NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
- NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
- NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadingArr.count];
- _downloadingHeadView.titleLabel.text = titleStr;
- [_downloadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
- [_downloadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
-
- if(_downloadingArr.count == 0){
- _downloadingHeadView.hidden = YES;
- }
- else{
- _downloadingHeadView.hidden = NO;
- }
-
- BOOL isDownloadingType = YES;
- for (ShareFileDataModel*model in _downloadingArr) {
- if(model.downloadBoxStateType != downloadBoxStateDownloadloading){
- isDownloadingType = NO;
- break;
- }
- }
-
- //根据 isDownloadingType判断是否为全部下载状态
- if(isDownloadingType){
- _downloadingHeadView.rightButton.selected = NO;
- }
- else{
- _downloadingHeadView.rightButton.selected = YES;
- }
- }
-
-
- if(_failHeadView){
- NSString *leftStr = NSLocalizedString(@"File_upload_Record_download_fail",nil);
- NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
- NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadfailArr.count];
- _failHeadView.titleLabel.text = titleStr;
- [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
-
- if(_downloadfailArr.count == 0){
- _failHeadView.hidden = YES;
- }
- else{
- _failHeadView.hidden = NO;
- }
- }
-
- if(_doneHeadView){
- NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_download",nil);
- NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
- NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_downloadDoneArr.count];
- _doneHeadView.titleLabel.text = titleStr;
- [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
-
- if(_downloadDoneArr.count == 0){
- _doneHeadView.hidden = YES;
- }
- else{
- _doneHeadView.hidden = NO;
- }
- }
- }
- #pragma mark 点击全选
- - (void)setIsSelectAllType:(BOOL)isSelectAllType
- {
- //_selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
-
- _selectModelArr = [NSMutableArray new];
- if(isSelectAllType){
- [_selectModelArr addObjectsFromArray:_downloadingArr];
- [_selectModelArr addObjectsFromArray:_downloadfailArr];
- [_selectModelArr addObjectsFromArray:_downloadDoneArr];
- }
-
- [self reloadDataFun];
- }
- -(void)setIsEditType:(BOOL)isEditType
- {
- _isEditType = isEditType;
-
- if(_isEditType){
- //_bgScrollV.scrollEnabled = NO;
- }
- else{
- //_bgScrollV.scrollEnabled = YES;
- [_selectModelArr removeAllObjects];
-
- }
-
- [self reloadDataFun];
- }
- #pragma mark cell长按时间
- - (void)didLongPressClickFun{
- self.isEditType = YES;
- if(self->_didLongPressClick){
- self->_didLongPressClick();
- }
- }
- #pragma mark 单个点击选中 取消
- - (void)selectModelOneByOne:(ShareFileDataModel*)model BySelect:(BOOL)isSelcet
- {
- if(isSelcet){
- [_selectModelArr addObject:model];
- }
- else{
- [_selectModelArr removeObject:model];
- }
- }
- #pragma mark 单个点击选中后删除
- - (void)deleteModelOneByOneFun{
- if(!_selectModelArr || _selectModelArr.count==0){
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- });
- return;
- }
-
- [[boxDownloadFileManager shareInstance] deleteBoxSaveFileRecordBy:_selectModelArr];
-
- for (ShareFileDataModel *dataModel in _selectModelArr) {
- [self handleTotalArrByDelete:dataModel];
- }
-
- [_selectModelArr removeAllObjects];
- [self reloadDataFun];
- }
- - (void)handleTotalArrByDelete:(ShareFileDataModel*)delModel
- {
- if(delModel.downloadBoxStateType == downloadBoxStateDone)
- {
- NSMutableArray *arr = _downloadDoneArr;
- [self deteleModel:delModel inArr:arr];
- }
- else if(delModel.downloadBoxStateType == downloadBoxStateFail){
- NSMutableArray *arr = _downloadfailArr;
- [self deteleModel:delModel inArr:arr];
- }
- else{
- NSMutableArray *arr = _downloadingArr;
- [self deteleModel:delModel inArr:arr];
- }
-
- }
- #pragma mark 处理删除内存数据
- - (void)deteleModel:(ShareFileDataModel*)delModel inArr:(NSMutableArray*)delArr{
-
- for (ShareFileDataModel *dataModel in delArr) {
- if(delModel.bg_id.integerValue == dataModel.bg_id.integerValue){
- [delArr removeObject:dataModel];
- break;;
- }
- }
-
- }
- #pragma mark 处理上传中的 状态点击事件
- - (void)handleDownloadingStateTapFunBy:(BOOL)isSuspendType with:(ShareFileDataModel*)model AtIndexPath:(NSIndexPath *)indexPath
- {
- //boxDownloadFileRecordCell * cell = [self cellForRowAtIndexPath:indexPath];
-
- HLog(@"%d",isSuspendType);
-
- if(isSuspendType){
- HLog(@"supendDownloadWithUrl");
- [[boxDownloadFileManager shareInstance] suspendDownloadFileFun:NO withModel:model];
- }
- else{
- HLog(@"startDownLoadWithUrl");
- NSMutableArray *curArr = [NSMutableArray arrayWithArray:@[model]];
- [[boxDownloadFileManager shareInstance] reDownloadFileFunBy:curArr withAll:NO];
- }
-
- //[self reloadDataFun];
- if(indexPath){
- [self reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
- }
- }
- #pragma mark 处理上传中的 状态点击事件
- - (void)handleUploadFailStateWith:(ShareFileDataModel*)model AtIndexPath:(NSIndexPath *)indexPath{
-
- [_downloadfailArr removeObject:model];
- model.downloadBoxStateType = downloadBoxStateDownloadloading;
- [_downloadingArr addObject:model];
- [self RefreshAllDataFun];
-
- [[boxDownloadFileManager shareInstance] updataBoxSaveDataInFailBy:model];
-
- //boxDownloadFileRecordCell * cell = [self cellForRowAtIndexPath:indexPath];
- NSMutableArray *curArr = [NSMutableArray arrayWithArray:@[model]];
- [[boxDownloadFileManager shareInstance] reDownloadFileFunBy:curArr withAll:NO];
-
- }
- #pragma mark 点击上传中的全部暂停
- - (void)didClickAllSuspendInLoadingFun
- {
- //HLog(@"%@\n hhh %d",_downloadingHeadView,_downloadingHeadView.rightButton.selected);
-
- _downloadingHeadView.rightButton.selected = !_downloadingHeadView.rightButton.selected;
-
- if(_downloadingHeadView.rightButton.selected){
- HLog(@"suspendAllDownloadTask");
- for (ShareFileDataModel*dataModel in _downloadingArr) {
- dataModel.downloadBoxStateType = downloadBoxStateSuspend;
- }
-
- [[boxDownloadFileManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
-
- [self reloadData];
- }
- else{
- HLog(@"startAllDownloadTask");
- for (ShareFileDataModel*dataModel in _downloadingArr) {
- dataModel.downloadBoxStateType = downloadBoxStateDownloadloading;
- }
-
- [[boxDownloadFileManager shareInstance] reDownloadFileFunBy:nil withAll:YES];
- [self reloadData];
- }
- }
- #pragma mark 点击上传成功的清空记录
- - (void)didClickClearRecordInDoneFun
- {
- /*弹窗提示二次确认*/
- KWeakSelf
- ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
- msg:NSLocalizedString(@"File_upload_Record_clear_done_Tip_msg",nil)
- imageStr:@""
- cancelTitle:NSLocalizedString(@"other_cancel",nil)
- okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
- didClickOk:^{
- [weakSelf ClearAllRecordInDoneFun];
- } didClickCancel:^{
-
- }];
- nextVC.modalPresentationStyle = UIModalPresentationCustom;
-
- [[iTools appRootViewController] presentViewController:nextVC animated:YES completion:^{
- nextVC.view.superview.backgroundColor = [UIColor clearColor];
- }];
- }
- - (void)ClearAllRecordInDoneFun
- {
- [[boxDownloadFileManager shareInstance] deleteBoxSaveFileRecordBy:_downloadDoneArr];
-
- [_downloadDoneArr removeAllObjects];
- [self RefreshAllDataFun];
- }
- #pragma mark 点击上传失败的清空记录
- - (void)didClickClearRecordInFailFun
- {
- /*弹窗提示二次确认*/
- KWeakSelf
- ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
- msg:NSLocalizedString(@"File_upload_Record_clear_fail_Tip_msg",nil)
- imageStr:@""
- cancelTitle:NSLocalizedString(@"other_cancel",nil)
- okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
- didClickOk:^{
- [weakSelf ClearAllRecordInFailFun];
- } didClickCancel:^{
-
- }];
- nextVC.modalPresentationStyle = UIModalPresentationCustom;
-
- [[iTools appRootViewController] presentViewController:nextVC animated:YES completion:^{
- nextVC.view.superview.backgroundColor = [UIColor clearColor];
- }];
- }
- - (void)ClearAllRecordInFailFun
- {
- [[boxDownloadFileManager shareInstance] deleteBoxSaveFileRecordBy:_downloadfailArr];
-
- [_downloadfailArr removeAllObjects];
- [self RefreshAllDataFun];
- }
- #pragma mark 下载完成
- - (void)downloadTaskFinishedNoti:(NSNotification *)notification
- {
- customDownloadOperation *model = notification.object;
- NSString *url = model.url;
- KWeakSelf
- if (model.downloadState == customDownloadStateCompleted) {
- HLog(@"下载完成");
- mainBlock(^{
- [weakSelf handldDownloadDoneDataBy:url];
- });
- }
- else if (model.downloadState == customDownloadStateFailed){
- HLog(@"下载失败");
- mainBlock(^{
- [weakSelf handldDownloadFailDataBy:url];
- });
- }
- }
- //- (void)downloadTaskExeError:(NSNotification *)notification
- //{
- // SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
- //
- // KWeakSelf
- // mainBlock(^{
- // [weakSelf handldDownloadFailDataBy:model];
- // });
- // HLog(@"下载失败");
- //}
- #pragma mark 第一次进来 检测重新下载
- - (void)reDownLoadAgainFun
- {
-
- if([boxDownloadFileManager shareInstance].isFirstAutoStartType){
- return;
- }
- else{
- [boxDownloadFileManager shareInstance].isFirstAutoStartType = YES;
- }
-
- //检测是否还有没保存的任务
- [[boxDownloadFileManager shareInstance] checkDownloadDonePlistInfoFun];
-
- //重新下载
- [[boxDownloadFileManager shareInstance] firstReDownloadAllFileFun];
- }
- #pragma mark 下载失败数据回调处理
- - (void)handldDownloadFailDataBy:(NSString*)url
- {
- NSString * urlString = [url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- for (ShareFileDataModel*dataModel in _downloadingArr) {
-
- //HLog(@"22222222 %@\n%@",urlString,dataModel.fileUrl);
- if([urlString isEqualToString:dataModel.fileUrl]){
- //dataModel.totalSize = model.totalSize;
- //dataModel.currentSize = model.currentSize;
- dataModel.downloadBoxStateType = downloadBoxStateFail;
-
- [_downloadfailArr insertObject:dataModel atIndex:0];
- [_downloadingArr removeObject:dataModel];
-
- break;
- }
- }
- [self RefreshAllDataFun];
- }
- #pragma mark 下载完成数据回调处理
- - (void)handldDownloadDoneDataBy:(NSString*)url
- {
- //解码
- NSString * urlString = [url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- for (ShareFileDataModel*dataModel in _downloadingArr) {
- HLog(@"22222222 %@\n%@",urlString,dataModel.fileUrl);
- if([urlString isEqualToString:dataModel.fileUrl]){
- dataModel.downloadBoxStateType = downloadBoxStateDone;
- [_downloadDoneArr insertObject:dataModel atIndex:0];
- [_downloadingArr removeObject:dataModel];
- break;
- }
- }
-
- [self RefreshAllDataFun];
- }
- @end
|