瀏覽代碼

1.下载中和全部暂停 全部开启优化

huangxiaodong 1 年之前
父節點
當前提交
8c6aea5f6b

+ 2 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/boxDownloadFileRecordCell.h

@@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic,copy) void (^didClckSelectBut)(BOOL isSelect);
 //手势点击
 @property (nonatomic,copy) void (^didTapPressClick)(void);
+
+- (void)updateDataDownloadingBy:(ShareFileDataModel*)curShareFileDataModel;
 @end
 
 NS_ASSUME_NONNULL_END

+ 240 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/boxDownloadFileRecordCell.m

@@ -10,6 +10,7 @@
 #import "cachesFileManager.h"
 #import <SDWebImage/SDWebImage.h>
 #import "downloadThumbnailManager.h"
+#import "SGDownloadManager.h"
 
 @interface boxDownloadFileRecordCell ()
 @property(nonatomic,strong) UIImageView *fileImageView;
@@ -34,6 +35,14 @@
     
     if (self)
     {
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeIng:) name:SGDownloadTaskExeing object:nil];
+
+//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeEnd:) name:SGDownloadTaskExeEnd object:nil];
+//
+//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeError:) name:SGDownloadTaskExeError object:nil];
+
+        //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeSupend:) name:SGDownloadTaskExeSuspend object:nil];
+        
         [self drawView];
     }
     
@@ -229,6 +238,13 @@
         [self setFixedValueByModel:curShareFileDataModel];
     }
     
+//    if(_curShareFileDataModel
+//       &&(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone
+//       ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail)
+//       ){
+//        return;
+//    }
+    
     _curShareFileDataModel = curShareFileDataModel;
     
     
@@ -340,6 +356,7 @@
     else{
         _upLoadStateButton.hidden = YES;
         _progressBgView.hidden = YES;
+        _fileSpeedlabel.text = @"";
     }
     
     
@@ -452,6 +469,145 @@
     
 }
 
+//下载中最更进度
+- (void)updateDataDownloadingBy:(ShareFileDataModel*)curShareFileDataModel{
+    
+    if(_curShareFileDataModel
+       &&(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone
+       ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail)
+       ){
+        return;
+    }
+    
+    //进度设置
+    CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
+    
+    if(curShareFileDataModel.totalSize == 0){
+        curShareFileDataModel.totalSize = curShareFileDataModel.fileSize.longLongValue;
+    }
+    
+    NSInteger totalSize = curShareFileDataModel.totalSize;
+    if(totalSize == 0.0){
+        totalSize += 0.0001;
+    }
+    
+    CGFloat curProgress = curShareFileDataModel.currentSize/(totalSize*1.0);
+    
+    if(curProgress > 1){
+        curProgress = 1;
+    }
+    
+    frame.size.width =  frame.size.width * curProgress;
+    
+    if (isnan(frame.size.width))
+    {
+        HLog(@"计算出错了");
+        frame.size.width = 10.0;
+    }
+    
+//    HLog(@"%f, %f, %f, %f,",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height);
+//    HLog(@"%@",_progressSelectView);
+    
+    _progressSelectView.frame = frame;
+    //_glayer.frame = frame;
+    
+    NSString * totalSizeStr = nil;
+    NSInteger totalSize_k = totalSize / 1024;
+    if(totalSize_k < 1024){
+        totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
+    }
+    else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
+        totalSizeStr = [[NSString alloc] initWithFormat:@"%.1fMB",totalSize_k/1024.0];
+        
+    }
+    else{
+        totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
+    }
+    
+    NSString * didUploadStr = nil;
+    NSInteger didUploadSize_k = curShareFileDataModel.currentSize / 1024;
+    if(didUploadSize_k < 1024){
+        didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
+    }
+    else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
+        didUploadStr = [[NSString alloc] initWithFormat:@"%.1fMB",didUploadSize_k/1024.0];
+        
+    }
+    else{
+        didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
+    }
+    
+    if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateBegin){
+        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_wait"] forState:UIControlStateNormal];
+    }
+    else if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateDownloadloading){
+        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
+        _fileSpeedlabel.hidden = NO;
+        
+        //
+        _fileSpeedlabel.text = @"";
+        
+        if(curShareFileDataModel.preTimeInterval <= 0
+           || curShareFileDataModel.currentSize == curShareFileDataModel.preDownloadBytes){
+            //_fileSpeedlabel.text = @"--";
+        }
+        else{
+            NSTimeInterval  timers = curShareFileDataModel.curTimeInterval - curShareFileDataModel.preTimeInterval;
+            
+            if(timers > 0){
+                //long speed= 1*1024*1024 / timers;
+                
+                long speed= (curShareFileDataModel.currentSize - curShareFileDataModel.preDownloadBytes) / timers;
+                
+                NSString * speedStr = nil;
+                NSInteger speed_k = speed / (1024);
+                if(speed_k < 1024){
+                    speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
+                }
+                else {
+                    speedStr = [[NSString alloc] initWithFormat:@"%.1fMB/s",speed_k/1024.0];
+                }
+                
+                _fileSpeedlabel.text = speedStr;
+            }
+        }
+        
+        curShareFileDataModel.preTimeInterval = curShareFileDataModel.curTimeInterval;
+        curShareFileDataModel.preDownloadBytes = curShareFileDataModel.currentSize;
+    }
+    else if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateSuspend){
+        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
+    }
+    else if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail){
+        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_reStart"] forState:UIControlStateNormal];
+        _progressBgView.hidden = YES;
+    }
+    else{
+        _upLoadStateButton.hidden = YES;
+        _progressBgView.hidden = YES;
+    }
+    
+    
+    if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone){
+        NSString*tipStr = NSLocalizedString(@"File_download_Path_other_done",nil);
+        
+        if([iTools canSaveFileToAlbumByPhoto:YES withName:curShareFileDataModel.fileName]
+           ||[iTools canSaveFileToAlbumByPhoto:NO withName:curShareFileDataModel.fileName]){
+            tipStr = NSLocalizedString(@"File_download_Path_default_done",nil);
+        }
+        
+        _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@  %@",totalSizeStr,tipStr];
+    }
+    else if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail){
+        _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@",totalSizeStr];
+    }
+    else{
+        _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
+    }
+    
+}
+
+
 -(void)longPressClick:(UILongPressGestureRecognizer *)press{
     //state属性是所有手势父类提供的方法,用于记录手势的状态
     if(press.state == UIGestureRecognizerStateBegan){
@@ -498,4 +654,88 @@
     });
 }
 
+- (void)downloadTaskExeIng:(NSNotification *)notification
+{
+    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+    
+    NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+
+    //HLog(@"%@\n %@",urlString,_curShareFileDataModel.fileUrl);
+    if (![urlString isEqualToString:_curShareFileDataModel.fileUrl]
+        ||model.totalSize == model.currentSize) { // 不是这一个任务
+        return;
+    }
+    
+    if(_curShareFileDataModel
+       &&(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone
+       ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail)
+       ){
+        return;
+    }
+    
+    _curShareFileDataModel.downloadBoxStateType = downloadBoxStateDownloadloading;
+    _curShareFileDataModel.currentSize = model.currentSize;
+    _curShareFileDataModel.curTimeInterval = [[NSDate date] timeIntervalSince1970];
+    
+    mainBlock(^{
+        [self updateDataDownloadingBy:self->_curShareFileDataModel];
+    });
+    HLog(@"下载中");
+}
+
+- (void)downloadTaskExeSupend:(NSNotification *)notification
+{
+    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+    NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+    if (![urlString isEqualToString:_curShareFileDataModel.fileUrl]) { // 不是这一个任务
+        return;
+    }
+    
+    HLog(@"%@",_curShareFileDataModel);
+    if(_curShareFileDataModel
+       &&(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone
+       ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail)
+       ){
+        return;
+    }
+        
+    _curShareFileDataModel.downloadBoxStateType = downloadBoxStateSuspend;
+
+    mainBlock(^{
+        [self updateDataDownloadingBy:self->_curShareFileDataModel];
+    });
+    HLog(@"暂停/下载等待中");
+}
+
+//- (void)downloadTaskExeEnd:(NSNotification *)notification
+//{
+//    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+//    
+//    if (![model.url isEqualToString:_curShareFileDataModel.fileUrl]) { // 不是这一个任务
+//        return;
+//    }
+//    
+//    _curShareFileDataModel.downloadBoxStateType = downloadBoxStateDone;
+//    mainBlock(^{
+//        [self updateDataDownloadingBy:self->_curShareFileDataModel];
+//    });
+//    HLog(@"下载成功");
+//}
+
+//- (void)downloadTaskExeError:(NSNotification *)notification
+//{
+//    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+//    
+//    if (![model.url isEqualToString:_curShareFileDataModel.fileUrl]) { // 不是这一个任务
+//        return;
+//    }
+//    
+//    _curShareFileDataModel.downloadBoxStateType = downloadBoxStateFail;
+//    mainBlock(^{
+//        [self updateDataDownloadingBy:self->_curShareFileDataModel];
+//    });
+//    HLog(@"下载失败");
+//}
+
+
 @end

+ 108 - 55
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveDownloadRecordTableView.m

@@ -30,13 +30,11 @@
         _selectModelArr = [NSMutableArray new];
         _curDataArr = [NSMutableArray new];
         
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeIng:) name:SGDownloadTaskExeing object:nil];
+        //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeIng:) name:SGDownloadTaskExeing object:nil];
 
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeEnd:) name:SGDownloadTaskExeEnd object:nil];
 
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeError:) name:SGDownloadTaskExeError object:nil];
-
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeSupend:) name:SGDownloadTaskExeSuspend object:nil];
     }
     return self;
 }
@@ -140,7 +138,9 @@
         
         if(row < curArr.count){
             ShareFileDataModel *model = curArr[row];
+            
             cell.curShareFileDataModel = model;
+            
             cell.isEditType = _isEditType;
 
             if(_isEditType){
@@ -519,7 +519,15 @@
     }
     else{
         HLog(@"startDownLoadWithUrl");
+        
+        //因为这个框架 底层设置超过设置最大数(暂时设置为1 后续改) 就会把点击 开启的暂停
+        [[SGDownloadManager shareManager] suspendAllDownloadTask];
+        
         [[SGDownloadManager shareManager] startDownLoadWithUrl:requestURLEncodedString];
+        
+//        [[SGDownloadManager shareManager] downloadWithURL:[NSURL URLWithString:requestURLEncodedString] fileType:1 fileSize:0 complete:^(NSDictionary *respose, NSError *error) {
+//            HLog(@"%@---%@",respose, error);
+//        }];
     }
     
     //[self reloadDataFun];
@@ -540,6 +548,10 @@
     
     NSString *urlString = model.fileUrl;
     NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+    
+    //因为这个框架 底层设置超过设置最大数(暂时设置为1 后续改) 就会把点击 开启的暂停
+    [[SGDownloadManager shareManager] suspendAllDownloadTask];
+    
     [[SGDownloadManager shareManager] startDownLoadWithUrl:requestURLEncodedString];
     
 }
@@ -564,11 +576,21 @@
     else{
         HLog(@"startAllDownloadTask");
         
+        ShareFileDataModel*firstmodel = nil;
         for (ShareFileDataModel*dataModel in _downloadingArr) {
             dataModel.downloadBoxStateType = downloadBoxStateDownloadloading;
+            if(!firstmodel){
+                firstmodel = dataModel;
+            }
         }
         
-        [[SGDownloadManager shareManager] startAllDownloadTask];
+        NSString *urlString = firstmodel.fileUrl;
+        NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+        if(urlString){
+            [[SGDownloadManager shareManager] startDownLoadWithUrl:requestURLEncodedString];
+        }
+        
+        //[[SGDownloadManager shareManager] startAllDownloadTask];
     }
 }
 #pragma mark 点击上传成功的清空记录
@@ -634,44 +656,44 @@
 }
 
 #pragma mark 下载回调
-- (void)downloadTaskExeIng:(NSNotification *)notification
-{
-    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
-    HLog(@"下载中 %lld",model.currentSize);
-    
-    //下载失败返回 61个字节? 没有报错 特殊处理
-//    if(model.currentSize == model.totalSize
-//       && model.currentSize < 200){
-//        
-//        if(model.totalSize == 0){
-//            model.downloadState = DownloadStateFailed;
-//            [[NSNotificationCenter defaultCenter] postNotificationName:SGDownloadTaskExeError object:model];
-//        }
-//        
-//        NSString * pathStr= model.fullPath;
-//        NSData * jsonData = [[NSData alloc] initWithContentsOfFile:pathStr];
-//        if(jsonData){
-//            NSDictionary *myDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
-//            
-//            if(myDictionary){
-//                HLog(@"%@",myDictionary);
-//            }
-//        }
-//        
-//    }
-    
-    KWeakSelf
-    mainBlock(^{
-        [weakSelf handldDownloadingDataBy:model];
-    });
-    
-}
-
-- (void)downloadTaskExeSupend:(NSNotification *)notification
-{
-    //SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
-    HLog(@"暂停/下载等待中");
-}
+//- (void)downloadTaskExeIng:(NSNotification *)notification
+//{
+//    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+//    HLog(@"下载中  %lld  %@",model.currentSize,model.fileName);
+//    
+//    //下载失败返回 61个字节? 没有报错 特殊处理
+////    if(model.currentSize == model.totalSize
+////       && model.currentSize < 200){
+////        
+////        if(model.totalSize == 0){
+////            model.downloadState = DownloadStateFailed;
+////            [[NSNotificationCenter defaultCenter] postNotificationName:SGDownloadTaskExeError object:model];
+////        }
+////        
+////        NSString * pathStr= model.fullPath;
+////        NSData * jsonData = [[NSData alloc] initWithContentsOfFile:pathStr];
+////        if(jsonData){
+////            NSDictionary *myDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
+////            
+////            if(myDictionary){
+////                HLog(@"%@",myDictionary);
+////            }
+////        }
+////        
+////    }
+//    
+//    KWeakSelf
+//    mainBlock(^{
+//        [weakSelf handldDownloadingDataBy:model];
+//    });
+//    
+//}
+
+//- (void)downloadTaskExeSupend:(NSNotification *)notification
+//{
+//    //SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+//    HLog(@"暂停/下载等待中");
+//}
 
 - (void)downloadTaskExeEnd:(NSNotification *)notification
 {
@@ -683,7 +705,7 @@
         [weakSelf handldDownloadDoneToSaveBy:model];
         
     });
-    HLog(@"下载成功");
+    HLog(@"下载成功 %@",model.fileName);
 }
 
 - (void)downloadTaskExeError:(NSNotification *)notification
@@ -700,6 +722,7 @@
 #pragma mark 第一次进来 检测重新下载
 - (void)reDownLoadAgainFun
 {
+    return;
     if(_reDownLoadAgainType){
         return;
     }
@@ -713,6 +736,7 @@
         if(curModel.downloadBoxStateType != downloadBoxStateSuspend)
         {
             [handleDownloadArr addObject:curModel];
+            break;//只开一个 完成后再添加先任务
         }
     }
     
@@ -751,6 +775,7 @@
     //解码
     NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 
+    ShareFileDataModel* curDataModel = nil;
     for (ShareFileDataModel*dataModel in _downloadingArr) {
         //HLog(@"22222222 %@\n%@",urlString,dataModel.fileUrl);
         if([urlString isEqualToString:dataModel.fileUrl]){
@@ -758,6 +783,7 @@
             dataModel.currentSize = model.currentSize;
             dataModel.curTimeInterval = [[NSDate date] timeIntervalSince1970];
             
+            curDataModel = dataModel;
             if(dataModel.downloadBoxStateType == downloadBoxStateSuspend
                || dataModel.downloadBoxStateType == downloadBoxStateDone){
                 canReloadData = NO;
@@ -767,9 +793,28 @@
         }
     }
     
-    if (canReloadData) {
+    if (canReloadData && curDataModel) {
         [self reloadData];
+        //[self reloadOneCellDataBy:curDataModel];
+    }
+}
+
+
+#pragma mark 刷新单个cell的数据
+- (void)reloadOneCellDataBy:(ShareFileDataModel*)dataModel{
+    
+    boxDownloadFileRecordCell *cell = [self viewWithTag:200 + dataModel.bg_id.integerValue];
+    
+    if(![cell isKindOfClass:[boxDownloadFileRecordCell class]]){
+        return;
+    }
+    
+    if (![cell.curShareFileDataModel.fileUrl isEqualToString:dataModel.fileUrl]) {
+        return;
     }
+    
+    [cell updateDataDownloadingBy:dataModel];
+    
 }
 
 #pragma mark 下载完成数据回调处理
@@ -808,22 +853,22 @@
         {//可以保持到相册
             UIImage *image = [UIImage imageWithContentsOfFile:pathStr];
             if(image){
-                [self loadImageFinished:image with:pathStr];
+                [self loadImageFinished:image with:pathStr withUrl:model.url];
             }
                 
         }
         else if([iTools canSaveFileToAlbumByPhoto:NO withName:lastName]){//可以保持到相册
-            [self loadVideoFinishedBy:pathStr];
+            [self loadVideoFinishedBy:pathStr withUrl:model.url];
             
         }
         else{//保存到文件
-            [self loadOtherDataFinishedBy:pathStr];
+            [self loadOtherDataFinishedBy:pathStr withUrl:model.url];
         }
     }
 }
 
 
-- (void)loadImageFinished:(UIImage *)image with:(NSString*)fullPath
+- (void)loadImageFinished:(UIImage *)image with:(NSString*)fullPath withUrl:(NSString*)url
 {
     [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
          //写入图片到相册
@@ -833,8 +878,9 @@
          //NSLog(@"success = %d, error = %@", success, error);
          if (success) {
              HLog(@"已将图片保存至相册");
-             //删除记录的时间再处理
-             //[[NSFileManager defaultManager] removeItemAtPath:fullPath error:nil];
+             //
+             [[NSFileManager defaultManager] removeItemAtPath:fullPath error:nil];
+             [[SGDownloadManager shareManager] cancelDownloadWithUrl:url];
          } else {
              HLog(@"未能将图片保存至相册");
          }
@@ -842,7 +888,7 @@
     }];
 }
 
-- (void)loadVideoFinishedBy:(NSString*)fullPath
+- (void)loadVideoFinishedBy:(NSString*)fullPath withUrl:(NSString*)url
 {
     NSString*pathStr = fullPath;
     
@@ -853,8 +899,9 @@
     } completionHandler:^(BOOL success, NSError * _Nullable error) {
         if (success) {
             HLog(@"已将视频保存至相册");
-            //删除记录的时间再处理
-            //[[NSFileManager defaultManager] removeItemAtPath:pathStr error:nil];
+            //
+            [[NSFileManager defaultManager] removeItemAtPath:pathStr error:nil];
+            [[SGDownloadManager shareManager] cancelDownloadWithUrl:url];
         } else {
             HLog(@"未能将视频保存至相册");
         }
@@ -865,9 +912,15 @@
 }
 
 //下载音频 文件等
-- (void)loadOtherDataFinishedBy:(NSString*)fullPath
+- (void)loadOtherDataFinishedBy:(NSString*)fullPath withUrl:(NSString*)url
 {
-    [[NSNotificationCenter defaultCenter] postNotificationName:NotLoadOtherDataFinished object:fullPath userInfo:nil];
+    NSMutableDictionary *dict = [NSMutableDictionary new];
+    if(fullPath && url){
+        [dict setValue:fullPath forKey:@"fullPath"];
+        [dict setValue:url forKey:@"url"];
+    }
+    
+    [[NSNotificationCenter defaultCenter] postNotificationName:NotLoadOtherDataFinished object:dict userInfo:nil];
 }
 
 @end

+ 47 - 18
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/boxDownloadFileManager.m

@@ -39,20 +39,47 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
 //添加保存记录
 - (void)addBoxDownloadRecordFunBy:(NSArray*)arr complete:(custom_complete_B)complete{
     if(arr && arr.count >0 ){
-        
-        for (ShareFileDataModel*model in arr) {
-            model.bg_tableName = share_box_download_tableName;
-        }
-        
-        KWeakSelf
-        //[ShareFileDataModel bg_saveOrUpdateArray:arr];
-        [ShareFileDataModel bg_saveOrUpdateArrayAsync:arr complete:^(BOOL isSuccess) {
-            [weakSelf beginDownloadFilesByUrls:arr];
-            complete(isSuccess);
+        //1.排重处理
+        [self getDataInDatabaseFun:NO complete:^(NSMutableArray * _Nonnull Arr) {
+            [self filterDownloadingTaskFunWithNewTaskArr:arr complete:complete];
         }];
+    }
+}
+
+- (void)filterDownloadingTaskFunWithNewTaskArr:(NSArray*)taskArr complete:(custom_complete_B)complete
+{
+    NSMutableArray *addTaskArr = [NSMutableArray new];
+    
+    NSMutableArray * downloadingArr = [NSMutableArray new];
+    if(_databaseArr && _databaseArr.count == 3){
+        downloadingArr = _databaseArr[0];
+    }
+    
+    
+    for (ShareFileDataModel*model in taskArr) {
+        BOOL canAdd = YES;
         
+        if(downloadingArr.count > 0){
+            for (ShareFileDataModel*downloadingModel in downloadingArr) {
+                if([downloadingModel.fileUrl isEqualToString:model.fileUrl]){
+                    canAdd = NO;
+                    break;
+                }
+            }
+        }
         
+        if(canAdd){
+            model.bg_tableName = share_box_download_tableName;
+            [addTaskArr addObject:model];
+        }
     }
+    
+    KWeakSelf
+    //[ShareFileDataModel bg_saveOrUpdateArray:arr];
+    [ShareFileDataModel bg_saveOrUpdateArrayAsync:addTaskArr complete:^(BOOL isSuccess) {
+        [weakSelf beginDownloadFilesByUrls:addTaskArr];
+        complete(isSuccess);
+    }];
 }
 
 #pragma mark 读取数据库数据
@@ -183,7 +210,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
             if (dataModel.bg_id.integerValue == model.bg_id.integerValue) {
                 [failArr removeObject:model];
                 [ingArr addObject:dataModel];
-                
+                break;
             }
         }
     }
@@ -214,6 +241,8 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
 //            HLog(@"%@---%@",respose, error);
 //        }];
         
+        //[SGDownloadManager shareManager].
+        
         [[SGDownloadManager shareManager] downloadWithURL:curUrl fileType:1 fileSize:0 complete:^(NSDictionary *respose, NSError *error) {
             HLog(@"%@---%@",respose, error);
         }];
@@ -224,24 +253,24 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
 
 }
 
-- (void)downloadTaskExeIng:(NSNotification *)notification
-{
-    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
-    [self handldDownloadingDataBy:model];
-}
+//- (void)downloadTaskExeIng:(NSNotification *)notification
+//{
+//    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+//    [self handldDownloadingDataBy:model];
+//}
 
 - (void)downloadTaskExeEnd:(NSNotification *)notification
 {
     SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
     [self handldDownloadDoneDataBy:model];
-    HLog(@"下载成功");
+    //HLog(@"下载成功");
 }
 
 - (void)downloadTaskExeError:(NSNotification *)notification
 {
     SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
     [self handldDownloadFailDataBy:model];
-    HLog(@"下载失败");
+    //HLog(@"下载失败");
 }
 
 #pragma mark 下载中数据回调处理

+ 2 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileRecordViewController.h

@@ -9,6 +9,8 @@
 #import "TZImageManager.h"
 #import "TZAssetModel+imageData.h"
 #import "downloadThumbnailManager.h"
+#import "SGDownloadManager.h"
+
 NS_ASSUME_NONNULL_BEGIN
 
 @interface uploadFileRecordViewController : BaseViewController

+ 34 - 8
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileRecordViewController.m

@@ -52,6 +52,8 @@
 @property (nonatomic,assign) BOOL didGetUploadDataType;
 @property (nonatomic,assign) BOOL didGetDownloadDataType;
 @property (nonatomic,assign) BOOL didGetbackupsloadDataType;
+
+@property (nonatomic, copy) NSString *h5ShareDownloadUrl;
 @end
 
 @implementation uploadFileRecordViewController
@@ -1125,16 +1127,34 @@
 
 - (void)loadOtherDataFinishedFun:(NSNotification*)not
 {
-    NSString *fullPath = [not object];
-    if(fullPath
-       && [fullPath isKindOfClass:[NSString class]]
-       && fullPath.length >0){
-        [self loadOtherDataFinishedBy:fullPath];
+    //NSString *fullPath = [not object];
+    
+    NSDictionary *dict = [not object];
+    
+    if(dict
+       && ([dict isKindOfClass:[NSDictionary class]]
+           ||[dict isKindOfClass:[NSMutableDictionary class]])
+       ){
+        NSString * fullPath = nil;
+        NSString * url = nil;
+        if ([[dict allKeys] containsObject:@"fullPath"]) {
+            fullPath = dict[@"fullPath"];
+        }
+        
+        if ([[dict allKeys] containsObject:@"url"]) {
+            url = dict[@"url"];
+        }
+        
+        if(fullPath && url){
+            [self loadOtherDataFinishedBy:fullPath with:url];
+        }
+        
+        
     }
 }
 
 //下载音频 文件等
-- (void)loadOtherDataFinishedBy:(NSString*)fullPath
+- (void)loadOtherDataFinishedBy:(NSString*)fullPath with:(NSString*)url
 {
     
     NSString*filePath = fullPath;
@@ -1144,6 +1164,8 @@
         return;
     }
     
+    _h5ShareDownloadUrl = url;
+    
     NSURL * fileURL = [NSURL fileURLWithPath:filePath];
     
     UIDocumentPickerViewController *documentPickerVC = [[UIDocumentPickerViewController alloc] initWithURL:fileURL inMode:UIDocumentPickerModeExportToService];
@@ -1176,8 +1198,12 @@
                 // 上传
                 NSLog(@"fileName : %@-- %@", fileName,pathStr);
                 
-                //删除记录的时间再处理
-                //[[NSFileManager defaultManager] removeItemAtPath:pathStr error:nil];;
+                //
+                [[NSFileManager defaultManager] removeItemAtPath:pathStr error:nil];
+                if(_h5ShareDownloadUrl){
+                    [[SGDownloadManager shareManager] cancelDownloadWithUrl:_h5ShareDownloadUrl];
+                }
+                
             }
         }];
         [urls.firstObject stopAccessingSecurityScopedResource];

+ 1 - 1
创维盒子/双子星云手机/Vendor/DownLoadManager/SGDwonload/SGCacheManager.m

@@ -117,7 +117,7 @@ static dispatch_semaphore_t _semaphore;
 + (BOOL)saveFileInfoWithDict:(NSDictionary *)dict {
     
     // 多账号下载 判断是否需要缓存记录
-    HLog(@"%@", dict);
+    //HLog(@"%@", dict);
     if ([[dict allKeys] containsObject:@"fullPath"]) {
         NSArray *fileArray = [[dict objectForKey:@"fullPath"] pathComponents];
         NSString *filePathAccount = @"0";

+ 2 - 1
创维盒子/双子星云手机/Vendor/DownLoadManager/SGDwonload/SGDownloadQueue.m

@@ -23,7 +23,8 @@
 - (instancetype)init {
 
     if (self = [super init]) {
-        _maxCount = 3;
+        //_maxCount = 3;
+        _maxCount = 1;
         [self registeNotification];
     }
     return self;

+ 1 - 1
创维盒子/双子星云手机/Vendor/DownLoadManager/SGDwonload/SGDownloadSession.m

@@ -102,7 +102,7 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
           dataTask:(NSURLSessionDataTask *)dataTask
 didReceiveResponse:(NSURLResponse *)response
  completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
-    
+    HLog(@"%@",response);
     // 将响应交给列队处理
     [self.queue dataTask:dataTask didReceiveResponse:response];