소스 검색

1.下载逻辑优化

huangxiaodong 1 년 전
부모
커밋
27e8708637

+ 6 - 0
创维盒子/Pods/YCDownloadSession/YCDownloadSession/YCDownloadManager.m

@@ -245,6 +245,12 @@ static id _instance;
     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:item.downloadURL]];
     YCDownloadTask *task = [[YCDownloader downloader] downloadWithRequest:request progress:item.progressHandler completion:item.completionHandler priority:priority];
     item.taskId = task.taskId;
+    
+    //hxd 20240605 item 变多
+    if(oldItem){
+        [YCDownloadDB removeItemWithTaskId:oldItem.taskId];
+    }
+    
     [YCDownloadDB saveItem:item];
     [self resumeDownloadWithItem:item];
 }

+ 2 - 2
创维盒子/双子星云手机.xcodeproj/project.pbxproj

@@ -5224,7 +5224,7 @@
 				CODE_SIGN_IDENTITY = "Apple Development";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Manual;
-				CURRENT_PROJECT_VERSION = 16;
+				CURRENT_PROJECT_VERSION = 17;
 				DEVELOPMENT_TEAM = "";
 				"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6SV76WTUUR;
 				FRAMEWORK_SEARCH_PATHS = (
@@ -5305,7 +5305,7 @@
 				CODE_SIGN_IDENTITY = "Apple Development";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Manual;
-				CURRENT_PROJECT_VERSION = 16;
+				CURRENT_PROJECT_VERSION = 17;
 				DEVELOPMENT_TEAM = "";
 				"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6SV76WTUUR;
 				FRAMEWORK_SEARCH_PATHS = (

+ 3 - 0
创维盒子/双子星云手机/AppDelegate/Config/Notification.h

@@ -150,4 +150,7 @@
 #pragma mark 下载其它类型文件完成
 //#define NotLoadOtherDataFinished  @"loadOtherDataFinished"
 
+/* nas下载完成 通知*/
+#define nasDownloadTaskFinishedNotification                 @"nasDownloadTaskFinishedNot"
+
 #endif /* Notification_h */

+ 2 - 2
创维盒子/双子星云手机/Class/Set/previewFile/model/ShareRecordModel.h

@@ -19,8 +19,8 @@ typedef enum{
 }shareSaveBoxStateType;
 
 typedef enum{
-    downloadBoxStateBegin = 0,
-    downloadBoxStateDownloadloading,//占位 未用到
+    //downloadBoxStateBegin = 0,
+    downloadBoxStateDownloadloading = 0,//占位 未用到
     downloadBoxStateSuspend,//
     downloadBoxStateDone,
     downloadBoxStateFail,

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

@@ -194,8 +194,8 @@
     else{
         self.selectButton.hidden = YES;
         
-        if(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateBegin
-           ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDownloadloading
+        if(//_curShareFileDataModel.downloadBoxStateType == downloadBoxStateBegin
+           _curShareFileDataModel.downloadBoxStateType == downloadBoxStateDownloadloading
            ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateSuspend){
             _upLoadStateButton.hidden = NO;
         }
@@ -301,10 +301,11 @@
         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){
+//    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;
         
@@ -414,6 +415,7 @@
             //MP4、AVI、FLV、WMV、MKV、TS、MOV、RMVB。
             
             NSString *fileUrl = curShareFileDataModel.headUrl;
+            HLog(@"11图片1:%@",fileUrl);
             fileUrl = [fileUrl  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
             UIImage * defaultImage = [UIImage imageNamed:@"uploadFile_image"];
             [_fileImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:defaultImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
@@ -430,6 +432,7 @@
             //MP4、AVI、FLV、WMV、MKV、TS、MOV、RMVB。
             
             NSString *fileUrl = curShareFileDataModel.headUrl;
+            HLog(@"11图片1:%@",fileUrl);
             fileUrl = [fileUrl  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
             UIImage * defaultImage = [UIImage imageNamed:@"uploadFile_Video"];
             [_fileImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:defaultImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
@@ -518,10 +521,11 @@
         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){
+//    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;
         
@@ -659,18 +663,18 @@
     NSString * urlString = [item.downloadURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
     HLog(@"下载中:%lld --- %lld \n%@\n%@",downloadedSize,totalSize,urlString,_curShareFileDataModel.fileUrl);
     
-    if (![urlString isEqualToString:_curShareFileDataModel.fileUrl]
-        ||downloadedSize== totalSize) { // 不是这一个任务
-        return;
-    }
-    
     if(_curShareFileDataModel
-       &&(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone
-       ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail)
+       &&(_curShareFileDataModel.downloadBoxStateType != downloadBoxStateDownloadloading)
        ){
+        HLog(@"当前状态 -- %u",_curShareFileDataModel.downloadBoxStateType);
         return;
     }
     
+    if (![urlString isEqualToString:_curShareFileDataModel.fileUrl]
+        ||downloadedSize == totalSize) { // 不是这一个任务
+        return;
+    }
+
     _curShareFileDataModel.downloadBoxStateType = downloadBoxStateDownloadloading;
     _curShareFileDataModel.currentSize = downloadedSize;
     _curShareFileDataModel.curTimeInterval = [[NSDate date] timeIntervalSince1970];

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

@@ -64,8 +64,11 @@
     _outSideDataArr = outSideDataArr;
     
     _downloadingArr = [NSMutableArray arrayWithArray:outSideDataArr[0]];
-    for (ShareFileDataModel*model in _downloadingArr) {
-        model.downloadBoxStateType = downloadBoxStateDownloadloading;
+    
+    if(![boxDownloadFileManager shareInstance].isFirstAutoStartType){
+        for (ShareFileDataModel*model in _downloadingArr) {
+            model.downloadBoxStateType = downloadBoxStateDownloadloading;
+        }
     }
     
     _downloadDoneArr = [NSMutableArray arrayWithArray:outSideDataArr[1]];
@@ -403,6 +406,22 @@
         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;
+        }
     }
     
         
@@ -669,16 +688,17 @@
 #pragma mark 下载完成
 - (void)downloadTaskFinishedNoti:(NSNotification *)notification
 {
-    HLog(@"下载完成或者失败");
-    
+   
     YCDownloadItem *item = notification.object;
     KWeakSelf
     if (item.downloadStatus == YCDownloadStatusFinished) {
+        HLog(@"下载完成");
         mainBlock(^{
             [weakSelf handldDownloadDoneDataBy:item];
         });
     }
     else if (item.downloadStatus == YCDownloadStatusFailed){
+        HLog(@"下载失败");
         mainBlock(^{
             [weakSelf handldDownloadFailDataBy:item];
         });
@@ -757,17 +777,16 @@
     }
     
     //重新下载
-    [YCDownloadManager resumeAllDownloadTask];
-    
-//    NSArray *allDownItemArr = [YCDownloadManager downloadList];
-//    for (YCDownloadItem *item in allDownItemArr) {
-//        if (item.downloadStatus != YCDownloadStatusFailed
-//            && item.downloadStatus != YCDownloadStatusFinished) {
-//            //[YCDownloadManager startDownloadWithItem:item];
-//            //[YCDownloadManager resumeDownloadWithItem:item];
-//            [YCDownloadManager startDownloadWithItem:item];
-//        }
-//    }
+    //[YCDownloadManager resumeAllDownloadTask];
+    
+    NSArray *allDownItemArr = [YCDownloadManager downloadList];
+    for (YCDownloadItem *item in allDownItemArr) {
+        if (item.downloadStatus != YCDownloadStatusFailed
+            && item.downloadStatus != YCDownloadStatusFinished) {
+            //[YCDownloadManager startDownloadWithItem:item];
+            [YCDownloadManager resumeDownloadWithItem:item];
+        }
+    }
 }
 
 #pragma mark 下载失败数据回调处理

+ 17 - 1
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveView.m

@@ -238,7 +238,8 @@
             if ([updataModel.url isEqualToString:model.fileUrl]) {
                 if (updataModel.curStatus == 0
                     || updataModel.curStatus == 3) {
-                    //不用处理
+                    //检测文件是否存在
+                    [self checkBoxSaveFileUrlStateBy:model];
                 }
                 else if (updataModel.curStatus == 1) {
                     //成功
@@ -274,4 +275,19 @@
     _downloadRecordTableView.outSideDataArr = arr;
     [_downloadRecordTableView reDownLoadAgainFun];
 }
+
+#pragma mark 检测保存盒子的url是否存在
+- (void)checkBoxSaveFileUrlStateBy:(ShareFileDataModel*)dataModel{
+    
+    KWeakSelf
+   [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:dataModel.fileUrl  success:^(id  _Nonnull responseObject) {
+       
+       SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
+       if(model && model.status == 0){
+           
+       }
+   } failure:^(NSError * _Nonnull error) {
+       HLog(@"%@",error);
+   }];
+}
 @end

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

@@ -343,6 +343,10 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
     
     if (item.downloadStatus == YCDownloadStatusFinished) {
         [self handldDownloadDoneDataBy:item];
+        
+        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+            [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskFinishedNotification object:item];
+        });
     }
     else if (item.downloadStatus == YCDownloadStatusFailed){
         [self handldDownloadFailDataBy:item];
@@ -422,6 +426,10 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
             for (ShareFileDataModel*model in downloadingArr) {
                 model.downloadBoxStateType = downloadBoxStateSuspend;
             }
+            
+            [ShareFileDataModel bg_updateArrayAsync:downloadingArr complete:^(BOOL isSuccess) {
+                            
+            }];
         }
         
         [YCDownloadManager pauseAllDownloadTask];
@@ -429,7 +437,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
     else if(dataModel){//暂停指定任务
         NSString *urlString = dataModel.fileUrl;
         NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-        
+        HLog(@"%@",urlString);
         if(item && [item.downloadURL isEqualToString:requestURLEncodedString]){
             [YCDownloadManager pauseDownloadWithItem:item];
         }
@@ -441,6 +449,8 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
                 [YCDownloadManager pauseDownloadWithItem:item];
             }
             else{
+                HLog(@"%ld\n%@",allDownItemArr.count,allDownItemArr);
+
                 for (YCDownloadItem *item in allDownItemArr) {
                     if (item.downloadStatus == YCDownloadStatusFinished) {//这里有问题
                         [YCDownloadManager stopDownloadWithItem:item];
@@ -463,6 +473,10 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
                     break;
                 }
             }
+            
+            [ShareFileDataModel bg_updateArrayAsync:downloadingArr complete:^(BOOL isSuccess) {
+                            
+            }];
         }
     }
 }
@@ -472,8 +486,16 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
 {
  
     if(isAllType){
-        [YCDownloadManager resumeAllDownloadTask];
+        //[YCDownloadManager resumeAllDownloadTask];
 
+        NSArray *allDownItemArr = [YCDownloadManager downloadList];
+        for (YCDownloadItem *item in allDownItemArr) {
+            if (item.downloadStatus != YCDownloadStatusFailed
+                && item.downloadStatus != YCDownloadStatusFinished) {
+                //[YCDownloadManager startDownloadWithItem:item];
+                [YCDownloadManager resumeDownloadWithItem:item];
+            }
+        }
     }
     else{
         
@@ -485,7 +507,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
         }
         NSString *urlString = dataModel.fileUrl;
         NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-        
+        HLog(@"%@",urlString);
         if (item && [item.downloadURL isEqualToString:requestURLEncodedString]) {
             [YCDownloadManager resumeDownloadWithItem:item];
         }

+ 1 - 1
创维盒子/双子星云手机/CloudPlayer/PlayerViewController.mm

@@ -2626,7 +2626,7 @@ BOOL inReconnect = NO;
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getBaseInfoFun) name:getbaseInfoBeginNotification object:nil];
     
     //某一个YCDownloadItem下载成功通知
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:kDownloadTaskFinishedNoti object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskFinishedNotification object:nil];
 }
 
 - (void)removeNSNotification

+ 1 - 1
创维盒子/双子星云手机/CloudPlayer/View/PlayerView.m

@@ -71,7 +71,7 @@ ShowImageViewDelegate>{
                   inRect:CGRectMake(0, 0, glkshowImageView.drawableWidth, glkshowImageView.drawableHeight)
                 fromRect:[ciImage extent]];
     
-    //[self->glkshowImageView display];
+    [self->glkshowImageView display];
 }
 
 - (void)showIMage