Pārlūkot izejas kodu

1.下载全部暂停和单个暂停优化

huangxiaodong 1 gadu atpakaļ
vecāks
revīzija
6eae2790ff

+ 1 - 1
创维盒子/双子星云手机/AppDelegate/SceneDelegate.m

@@ -686,7 +686,7 @@
     [uploadFileManager shareInstance].fileModelDataArr = [NSMutableArray new];
     [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateWait;
     
-    [[downloadManager shareInstance] suspendDownloadFileFun:YES];
+    [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
     [downloadManager shareInstance].databaseArr = [NSMutableArray new];
     [downloadManager shareInstance].downLoadFileModelDataArr = [NSMutableArray new];
     

+ 1 - 1
创维盒子/双子星云手机/Class/Set/ChangeDevice/QRCodeScanForChangeDeviceViewController.m

@@ -278,7 +278,7 @@ bool isDownType22 = YES;
 {
     
     [[uploadFileManager shareInstance] suspendUploadFileFun:YES withModel:nil];
-    [[downloadManager shareInstance] suspendDownloadFileFun:YES];
+    [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
     [[backupsFileManager shareInstance] suspendBackupsFileFun];
     
     NSString *resStr = resultStr;

+ 1 - 1
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/downloadManager.h

@@ -34,7 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)DownloadFileDoneOneFileFun;
 - (void)DownloadFileFailOneFileFun;
 - (void)DownloadFileChangeingOneFileFun;
-- (void)suspendDownloadFileFun:(BOOL)isSuspendAll;
+- (void)suspendDownloadFileFun:(BOOL)isSuspendAll withModel:(couldPhoneFileModel*)model;
 - (void)reDownloadFileFunBy:(NSMutableArray*)arr withAll:(BOOL)isAllType;
 
 //删除本地数据库记录

+ 59 - 52
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/downloadManager.m

@@ -390,23 +390,42 @@ static downloadManager * cur_downloadManager = nil;
     [lock unlock];
 }
 
-- (void)suspendDownloadFileFun:(BOOL)isSuspendAll
+- (void)suspendDownloadFileFun:(BOOL)isSuspendAll withModel:(couldPhoneFileModel*)model
 {
-    _isSuspendType = YES;
     
     if(isSuspendAll){
-        for (couldPhoneFileModel *couldPhoneFileMod in _downLoadFileModelDataArr) {
-            couldPhoneFileMod.curDownloadStateType = downloadStateSuspend;
-        }
-        [_downLoadFileModelDataArr removeAllObjects];
-        
+        _isSuspendType = YES;
         [[NSNotificationCenter defaultCenter] postNotificationName:downloadFileSuspendAllNotification object:nil];
+        
+//        for (couldPhoneFileModel *couldPhoneFileMod in _downLoadFileModelDataArr) {
+//            couldPhoneFileMod.curDownloadStateType = downloadStateSuspend;
+//        }
+        
+        [self changeDownloadState:downloadStateSuspend withModelArr:_downLoadFileModelDataArr complete:^(BOOL isSuccess) {
+            [self->_downLoadFileModelDataArr removeAllObjects];
+        }];
+        
     }
     else{
-        [_downLoadFileModelDataArr removeObject:_curDownloadFileModel];
         
-        _reDownloadIngSelectIndex = -1;
-        [self beginDownloadFileFun];
+        couldPhoneFileModel *curModel = _curDownloadFileModel;
+        if(model){
+            curModel = model;
+        }
+        else{
+            _isSuspendType = YES;
+        }
+
+        [self changeDownloadState:downloadStateSuspend withModelArr:@[curModel] complete:^(BOOL isSuccess) {
+            [self->_downLoadFileModelDataArr removeObject:model];
+            
+            if(curModel.bg_id.integerValue == self->_curDownloadFileModel.bg_id.integerValue){
+                //开启下一个任务
+                _reDownloadIngSelectIndex = -1;
+                [self beginDownloadFileFun];
+            }
+            
+        }];
     }
 }
 
@@ -421,49 +440,23 @@ static downloadManager * cur_downloadManager = nil;
         _isNewAddTaskType = YES;
         _downLoadFileModelDataArr = [NSMutableArray arrayWithArray:Arr];
         _reDownloadIngSelectIndex = -1;
-        [self beginDownloadFileFun];
-        return;
+        
+    }
+    else{
+        _isNewAddTaskType = NO;
+        _reDownloadIngSelectIndex = 0;
+        
+        NSMutableArray *curArr = [NSMutableArray arrayWithArray:Arr];
+      
+        for (uploadFileDataModel*addModel in curArr){
+            [_downLoadFileModelDataArr insertObject:addModel atIndex:0];
+        
+        }
     }
     
-    _isNewAddTaskType = NO;
-    _reDownloadIngSelectIndex = 0;
-    
-    NSMutableArray *curArr = [NSMutableArray arrayWithArray:Arr];
-    //_downLoadFileModelDataArr = curArr;
-    for (uploadFileDataModel*addModel in curArr){
-        [_downLoadFileModelDataArr insertObject:addModel atIndex:0];
-        [self beginDownloadFileFun];
-    }
-    
-//    for (uploadFileDataModel*addModel in Arr) {
-//        
-//        BOOL needAddModel = YES;
-//        
-//        for (int i=0;i< _downLoadFileModelDataArr.count;i++)
-//        {
-//            couldPhoneFileModel*preModel = _downLoadFileModelDataArr[i];
-//            
-//            if(addModel.bg_id.integerValue == preModel.bg_id.integerValue)
-//            {
-//                needAddModel = NO;
-//                
-//                if(_reDownloadIngSelectIndex == 0){
-//                    _reDownloadIngSelectIndex = i;
-//                    
-//                    if(i==0){
-//                        _reDownloadIngSelectIndex = -1;
-//                    }
-//                }
-//                
-//                break;
-//            }
-//        }
-//        
-//        if(needAddModel){
-//            [_downLoadFileModelDataArr addObject:addModel];
-//            _reDownloadIngSelectIndex = _downLoadFileModelDataArr.count -1;
-//        }
-//    }
+    [self changeDownloadState:downloadStateUploading withModelArr:_downLoadFileModelDataArr complete:^(BOOL isSuccess) {
+        
+    }];
     
     [self beginDownloadFileFun];
 }
@@ -513,7 +506,7 @@ static downloadManager * cur_downloadManager = nil;
         
         if(couldPhoneFileMod.bg_id.integerValue == _curDownloadFileModel.bg_id.integerValue){
             isDelUploadingModel = YES;
-            [self suspendDownloadFileFun:NO];
+            [self suspendDownloadFileFun:NO withModel:_curDownloadFileModel];
         }
 
     }
@@ -529,6 +522,20 @@ static downloadManager * cur_downloadManager = nil;
     
 }
 
+//修改文件上传的状态
+- (void)changeDownloadState:(downloadStateType)curDownloadStateType  withModelArr:(NSArray*)modelArr  complete:(custom_complete_B)complete
+{
+   
+    for (couldPhoneFileModel * model in modelArr) {
+        model.curDownloadStateType = curDownloadStateType;
+    }
+    
+    [couldPhoneFileModel bg_saveOrUpdateArrayAsync:modelArr complete:^(BOOL isSuccess) {
+        complete(YES);
+    }];
+   
+}
+
 //检查是否需要重新下载
 - (void)checkReDownloadFileFun
 {

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

@@ -698,10 +698,9 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
     
     _isSuspendType = NO;
     
-    for (uploadFileDataModel*model in Arr) {
-        model.curUploadStateType = uploadStateUploading;
-    }
-    
+//    for (uploadFileDataModel*model in Arr) {
+//        model.curUploadStateType = uploadStateUploading;
+//    }
     
     [self changeUploadState:uploadStateUploading withModelArr:Arr complete:^(BOOL isSuccess) {
         [self reUploadFileSecondBy:Arr withAll:isAllType];

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

@@ -971,7 +971,7 @@
     _midTableView.downloadingHeadView.rightButton.selected = !_midTableView.downloadingHeadView.rightButton.selected;
     
     if(_midTableView.downloadingHeadView.rightButton.selected){
-        [[downloadManager shareInstance] suspendDownloadFileFun:YES];
+        [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
     }
     else{
         NSMutableArray *leftArr = _midTableView.downloadingArr;

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

@@ -462,7 +462,7 @@
 - (void)handleDownloadingStateTapFunBy:(BOOL)isSuspendType with:(couldPhoneFileModel*)model
 {
     if (isSuspendType) {
-        [[downloadManager shareInstance] suspendDownloadFileFun:NO];
+        [[downloadManager shareInstance] suspendDownloadFileFun:NO withModel:model];
     }
     else{
         NSMutableArray*arr = [NSMutableArray new];

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

@@ -112,7 +112,7 @@
         if(!isCanUseCellular){//不允许流量上传
             //
             if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN){
-                [[downloadManager shareInstance] suspendDownloadFileFun:YES];
+                [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
                 mainBlock(^{
                     [[NSNotificationCenter defaultCenter] postNotificationName:downloadFileSuspendAllNotification object:nil];
                     [[iToast makeText:NSLocalizedString(@"File_Transfer_By_Cellular_tip",nil)] show];

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

@@ -404,7 +404,7 @@
                 [[downloadManager shareInstance] DownloadFileFailOneFileFun];
             }
             else if(failType == 0xcd ){
-                [[downloadManager shareInstance] suspendDownloadFileFun:YES];
+                [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
                 NSString *tipStr = NSLocalizedString(@"disk_not_find_tip",nil);
                 mainBlock(^{
                     [[iToast makeText:tipStr] show];