Преглед изворни кода

cache drafted video thumbnails

cyberta пре 4 година
родитељ
комит
dc7827acd5
1 измењених фајлова са 14 додато и 8 уклоњено
  1. 14 8
      deltachat-ios/Chat/Views/MediaPreview.swift

+ 14 - 8
deltachat-ios/Chat/Views/MediaPreview.swift

@@ -39,17 +39,23 @@ class MediaPreview: DraftPreview {
             })
             })
             isHidden = false
             isHidden = false
         } else if draft.draftViewType == DC_MSG_VIDEO, let path = draft.draftAttachment {
         } else if draft.draftViewType == DC_MSG_VIDEO, let path = draft.draftAttachment {
-            self.isHidden = false
-            DispatchQueue.global(qos: .userInteractive).async {
-                let thumbnailImage = DcUtils.generateThumbnailFromVideo(url: URL(fileURLWithPath: path, isDirectory: false))
-                if let thumbnailImage = thumbnailImage {
-                    DispatchQueue.main.async { [weak self] in
-                        guard let self = self else { return }
-                        self.contentImageView.image = thumbnailImage
-                        self.setAspectRatio(image: thumbnailImage)
+            if let image = ThumbnailCache.shared.restoreImage(key: path) {
+                self.contentImageView.image = image
+                self.setAspectRatio(image: image)
+            } else {
+                DispatchQueue.global(qos: .userInteractive).async {
+                    let thumbnailImage = DcUtils.generateThumbnailFromVideo(url: URL(fileURLWithPath: path, isDirectory: false))
+                    if let thumbnailImage = thumbnailImage {
+                        DispatchQueue.main.async { [weak self] in
+                            guard let self = self else { return }
+                            self.contentImageView.image = thumbnailImage
+                            self.setAspectRatio(image: thumbnailImage)
+                            ThumbnailCache.shared.storeImage(image: thumbnailImage, key: path)
+                        }
                     }
                     }
                 }
                 }
             }
             }
+            self.isHidden = false
         } else {
         } else {
             isHidden = true
             isHidden = true
         }
         }