From 0be12da3dd09e4da0847d248cd9b7a9a7c531b8a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 5 Sep 2018 14:17:26 -0400 Subject: [PATCH] Use thumbnails in media views. --- .../MediaGalleryViewController.swift | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Signal/src/ViewControllers/MediaGalleryViewController.swift b/Signal/src/ViewControllers/MediaGalleryViewController.swift index cc79ccaa2..688425928 100644 --- a/Signal/src/ViewControllers/MediaGalleryViewController.swift +++ b/Signal/src/ViewControllers/MediaGalleryViewController.swift @@ -8,17 +8,28 @@ public enum GalleryDirection { case before, after, around } -public struct MediaGalleryItem: Equatable, Hashable { +public class MediaGalleryItem: Equatable, Hashable { let logTag = "[MediaGalleryItem]" let message: TSMessage let attachmentStream: TSAttachmentStream let galleryDate: GalleryDate + var presentationImage: UIImage? + init(message: TSMessage, attachmentStream: TSAttachmentStream) { self.message = message self.attachmentStream = attachmentStream self.galleryDate = GalleryDate(message: message) + + self.presentationImage = attachmentStream.thumbnailImageLarge(success: { [weak self] (image) in + guard let strongSelf = self else { + return + } + strongSelf.presentationImage = image + }, failure: { + Logger.warn("Could not load presentation image.") + }) } var isVideo: Bool { @@ -38,15 +49,6 @@ public struct MediaGalleryItem: Equatable, Hashable { return attachmentStream.thumbnailImageSmall(success: async, failure: {}) } - var fullSizedImage: UIImage { - guard let image = attachmentStream.originalImage else { - owsFail("\(logTag) in \(#function) unexpectedly unable to build attachment image") - return UIImage() - } - - return image - } - // MARK: Equatable public static func == (lhs: MediaGalleryItem, rhs: MediaGalleryItem) -> Bool { @@ -304,7 +306,7 @@ class MediaGalleryViewController: OWSNavigationController, MediaGalleryDataSourc // loadView hasn't necessarily been called yet. self.loadViewIfNeeded() - self.presentationView.image = initialDetailItem.fullSizedImage + self.presentationView.image = initialDetailItem.presentationImage self.applyInitialMediaViewConstraints() // Restore presentationView.alpha in case a previous dismiss left us in a bad state. @@ -481,7 +483,7 @@ class MediaGalleryViewController: OWSNavigationController, MediaGalleryDataSourc // it sits on the screen in the conversation view. let changedItems = currentItem != self.initialDetailItem if changedItems { - self.presentationView.image = currentItem.fullSizedImage + self.presentationView.image = currentItem.presentationImage self.applyOffscreenMediaViewConstraints() } else { self.applyInitialMediaViewConstraints()