Browse Source

1.nas 下载图片刷新闪烁问题

huangxiaodong 1 year ago
parent
commit
4d1758271f

+ 57 - 36
创维盒子/双子星云手机/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];
     }
     
@@ -221,8 +221,9 @@
     _progressBgView.hidden = NO;
     _upLoadStateButton.hidden = NO;
     
-    if (!_curShareFileDataModel
-        || ![_curShareFileDataModel.fileUrl isEqualToString:curShareFileDataModel.fileUrl]) {
+    if (!_curShareFileDataModel ||
+         ![_curShareFileDataModel.fileUrl isEqualToString:curShareFileDataModel.fileUrl])
+    {
         
         if(_curShareFileDataModel){
             HLog(@"%@\n%@",_curShareFileDataModel.fileUrl,curShareFileDataModel.fileUrl);
@@ -385,6 +386,10 @@
 #pragma mark setImage
 - (void)setFixedValueByModel:(ShareFileDataModel *)curShareFileDataModel
 {
+    if ([_fileNamelabel.text isEqualToString:curShareFileDataModel.fileName]) {
+        return;
+    }
+    
     _fileNamelabel.text = curShareFileDataModel.fileName;
     
     NSArray *nameArr= [curShareFileDataModel.fileName componentsSeparatedByString:@"."];
@@ -417,16 +422,25 @@
             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) {
-                if(image){
-                    //HLog(@"11图片1:%@",imageURL.absoluteString);
-                }
-                else{
-                    //HLog(@"11图片0:%@",imageURL.absoluteString);
-                }
-                
-            }];
+            __block UIImage * defaultImage = [UIImage imageNamed:@"uploadFile_image"];
+            
+            UIImage *cacheImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:fileUrl];
+            if(cacheImage){
+                _fileImageView.image = cacheImage;
+            }
+            else{
+                [_fileImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
+                    if(image){
+                        //HLog(@"11图片1:%@",imageURL.absoluteString);
+                    }
+                    else{
+                        //HLog(@"11图片0:%@",imageURL.absoluteString);
+                        self->_fileImageView.image = defaultImage;
+                    }
+                    
+                }];
+            }
+
         }
         else if ([iTools isVideoFilewithName:lastName]) {//JPG、JPEG、PNG、GIF、BMP、SVG、TIFF、HEIC。
             //MP4、AVI、FLV、WMV、MKV、TS、MOV、RMVB。
@@ -434,16 +448,23 @@
             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) {
-                if(image){
-                    //HLog(@"11图片1:%@",imageURL.absoluteString);
-                }
-                else{
-                    //HLog(@"11图片0:%@",imageURL.absoluteString);
-                }
-                
-            }];
+            __block UIImage * defaultImage = [UIImage imageNamed:@"uploadFile_Video"];
+            UIImage *cacheImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:fileUrl];
+            if(cacheImage){
+                _fileImageView.image = cacheImage;
+            }
+            else{
+                [_fileImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
+                    if(image){
+                        //HLog(@"11图片1:%@",imageURL.absoluteString);
+                    }
+                    else{
+                        //HLog(@"11图片0:%@",imageURL.absoluteString);
+                        self->_fileImageView.image = defaultImage;
+                    }
+                    
+                }];
+            }
         }
         else{
             _fileImageView.image = [UIImage imageNamed:@"uploadFile_other"];
@@ -639,19 +660,19 @@
     });
 }
 
-#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];
-    });
-}
+//#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];
+//    });
+//}
 
 #pragma mark 下载代理
 - (void)downloadItemStatusChanged:(YCDownloadItem *)item {

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

@@ -32,6 +32,8 @@
         _curDataArr = [NSMutableArray new];
         
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskFinishedNotification object:nil];
+        
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskDownloadingNoti:) name:kDownloadTaskDownloadingNoti object:nil];
     }
     return self;
 }
@@ -148,7 +150,6 @@
         
         if(row < curArr.count){
             ShareFileDataModel *model = curArr[row];
-            
             cell.curShareFileDataModel = model;
             
             cell.isEditType = _isEditType;
@@ -716,39 +717,31 @@
     }
 }
 
-#pragma mark 下载回调
-//- (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];
-//    });
-//    
-//}
+
+#pragma mark 下载通知
+- (void)downloadTaskDownloadingNoti:(NSNotification *)notification
+{
+    YCDownloadItem *item = notification.object;
+    if(!item)return;
+    
+    if (item.downloadStatus != YCDownloadStatusDownloading) {
+        return;
+    }
+    
+    //解码
+    NSString * urlString = [item.downloadURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+    //HLog(@"下载中:%lld --- %lld \n%@\n%@",downloadedSize,totalSize,urlString,_curShareFileDataModel.fileUrl);
+    
+    for (ShareFileDataModel*model in _downloadingArr) {
+        if([model.fileUrl isEqualToString:urlString]){
+            model.currentSize = item.downloadedSize;
+            model.curTimeInterval = [[NSDate date] timeIntervalSince1970];
+            break;
+        }
+    }
+    
+    [self reloadData];
+}