Browse Source

1.nas 下载刷新还原到cell处理

huangxiaodong 1 year ago
parent
commit
a884eb01de

+ 11 - 1
创维盒子/Pods/YCDownloadSession/YCDownloadSession/YCDownloadItem.m

@@ -58,6 +58,8 @@ NSString * const kDownloadTaskDownloadingNoti = @"kDownloadTaskDownloadingNoti";
     return [[YCDownloadItem alloc] initWithUrl:url fileId:fileId];
 }
 
+//设置一个变量 让下载通知不要发那么频发
+static int  YCDownloadingNotI = 0;
 #pragma mark - Handler
 - (void)downloadProgress:(YCDownloadTask *)task downloadedSize:(int64_t)downloadedSize fileSize:(int64_t)fileSize {
     
@@ -71,7 +73,15 @@ NSString * const kDownloadTaskDownloadingNoti = @"kDownloadTaskDownloadingNoti";
     }
     
     //hxd add not 20240603
-    [[NSNotificationCenter defaultCenter] postNotificationName:kDownloadTaskDownloadingNoti object:self];
+    if(YCDownloadingNotI == 0){
+        [[NSNotificationCenter defaultCenter] postNotificationName:kDownloadTaskDownloadingNoti object:self];
+    }
+    else if(YCDownloadingNotI >= 10){
+        YCDownloadingNotI = 0;
+        return;
+    }
+    
+    YCDownloadingNotI++;
 }
 
 - (void)downloadStatusChanged:(YCDownloadStatus)status downloadTask:(YCDownloadTask *)task {

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

@@ -35,7 +35,7 @@
     
     if (self)
     {
-//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskDownloadingNoti:) name:kDownloadTaskDownloadingNoti object:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskDownloadingNoti:) name:kDownloadTaskDownloadingNoti object:nil];
         [self drawView];
     }
     
@@ -661,18 +661,18 @@
 }
 
 //#pragma mark 下载通知
-//- (void)downloadTaskDownloadingNoti:(NSNotification *)notification
-//{
-//    YCDownloadItem *item = notification.object;
-//    if(!item)return;
-//    
-//    if (item.downloadStatus != YCDownloadStatusDownloading) {
-//        return;
-//    }
-//    mainBlock(^{
-//        [self downloadItem:item downloadedSize:item.downloadedSize totalSize:item.fileSize];
-//    });
-//}
+- (void)downloadTaskDownloadingNoti:(NSNotification *)notification
+{
+    YCDownloadItem *item = notification.object;
+    if(!item)return;
+    
+    if (item.downloadStatus != YCDownloadStatusDownloading) {
+        return;
+    }
+    mainBlock(^{
+        [self downloadItem:item downloadedSize:item.downloadedSize totalSize:item.fileSize];
+    });
+}
 
 #pragma mark 下载代理
 - (void)downloadItemStatusChanged:(YCDownloadItem *)item {

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

@@ -33,7 +33,7 @@
         
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskFinishedNotification object:nil];
         
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskDownloadingNoti:) name:kDownloadTaskDownloadingNoti object:nil];
+        //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskDownloadingNoti:) name:kDownloadTaskDownloadingNoti object:nil];
     }
     return self;
 }
@@ -732,16 +732,46 @@
     NSString * urlString = [item.downloadURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
     //HLog(@"下载中:%lld --- %lld \n%@\n%@",downloadedSize,totalSize,urlString,_curShareFileDataModel.fileUrl);
     
+    boxDownloadFileRecordCell * curCell= nil;
+    
     for (ShareFileDataModel*model in _downloadingArr) {
         if([model.fileUrl isEqualToString:urlString]){
             //model.downloadBoxStateType = downloadBoxStateDownloadloading;
             model.currentSize = item.downloadedSize;
             model.curTimeInterval = [[NSDate date] timeIntervalSince1970];
+            
+            NSArray *subViews = [self subviews];
+            
+            for (boxDownloadFileRecordCell *cell in subViews) {
+                if([cell isKindOfClass:[boxDownloadFileRecordCell class]]){
+                    ShareFileDataModel* preModel = cell.curShareFileDataModel;
+                    if(preModel && [preModel.fileUrl isEqualToString:model.fileUrl]){
+                        curCell = cell;
+                        break;
+                    }
+                }
+            }
+            
             break;
         }
     }
     
-    [self reloadData];
+    //[self reloadData];
+    //[self reloadSections:[[NSIndexSet alloc] initWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
+    
+    if(curCell){
+        NSIndexPath *index = [self indexPathForCell:curCell];
+        if(index){
+            [self reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
+        }
+        else{
+            [self reloadData];
+        }
+    }
+    else{
+        [self reloadData];
+    }
+
 }