소스 검색

Merge pull request #815 from deltachat/async_gallery

Gallery: video thumbnails are generated in background thread
cyBerta 5 년 전
부모
커밋
c25cec0f7f
1개의 변경된 파일10개의 추가작업 그리고 2개의 파일을 삭제
  1. 10 2
      deltachat-ios/View/Cell/GalleryCell.swift

+ 10 - 2
deltachat-ios/View/Cell/GalleryCell.swift

@@ -46,13 +46,21 @@ class GalleryCell: UICollectionViewCell {
         guard let viewtype = msg.viewtype, let fileUrl = msg.fileURL else {
             return
         }
-
         switch viewtype {
         case .image:
             imageView.image = msg.image
             playButtonView.isHidden = true
         case .video:
-            imageView.image = DcUtils.generateThumbnailFromVideo(url: fileUrl)
+            let key = fileUrl.absoluteString
+            if let image = ThumbnailCache.shared.restoreImage(key: key) {
+                imageView.image = image
+            } else {
+                imageView.loadVideoThumbnail(from: fileUrl, placeholderImage: nil) { thumbnail in
+                    if let image = thumbnail {
+                        ThumbnailCache.shared.storeImage(image: image, key: key)
+                    }
+                }
+            }
             playButtonView.isHidden = false
         case .gif:
             imageView.sd_setImage(with: fileUrl, placeholderImage: nil)