From 748b243156f5cbf7f0a6f6ee88c2c52f166537bd Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 5 Sep 2018 13:47:37 -0400 Subject: [PATCH] Restore full-screen thumbnails. --- .../Cells/OWSMessageBubbleView.m | 20 +++++++++++++++++-- .../Messages/Attachments/TSAttachmentStream.h | 1 + .../Messages/Attachments/TSAttachmentStream.m | 18 ++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m index b449b77db..62d9e6074 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m @@ -837,9 +837,8 @@ NS_ASSUME_NONNULL_BEGIN stillImageView.backgroundColor = [UIColor whiteColor]; [self addAttachmentUploadViewIfNecessary]; - __weak UIImageView *weakImageView = stillImageView; - __weak OWSMessageBubbleView *weakSelf = self; + __weak UIImageView *weakImageView = stillImageView; self.loadCellContentBlock = ^{ OWSMessageBubbleView *strongSelf = weakSelf; if (!strongSelf) { @@ -980,6 +979,7 @@ NS_ASSUME_NONNULL_BEGIN }]; __weak OWSMessageBubbleView *weakSelf = self; + __weak UIImageView *weakImageView = stillImageView; self.loadCellContentBlock = ^{ OWSMessageBubbleView *strongSelf = weakSelf; if (!strongSelf) { @@ -990,6 +990,22 @@ NS_ASSUME_NONNULL_BEGIN return; } stillImageView.image = [strongSelf + tryToLoadCellMedia:^{ + OWSCAssert([strongSelf.attachmentStream isImage]); + return [strongSelf.attachmentStream + thumbnailImageMediumWithSuccess:^(UIImage *image) { + weakImageView.image = image; + } + failure:^{ + DDLogError(@"Could not load thumbnail."); + }]; + } + mediaView:stillImageView + cacheKey:strongSelf.attachmentStream.uniqueId + shouldSkipCache:shouldSkipCache + canLoadAsync:YES]; + + tryToLoadCellMedia:^{ OWSCAssert([strongSelf.attachmentStream isVideo]); diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.h b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.h index 09e6f3f2a..158c42e04 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.h +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.h @@ -89,6 +89,7 @@ typedef void (^OWSThumbnailFailure)(void); failure:(OWSThumbnailFailure)failure; - (nullable UIImage *)thumbnailImageSmallWithSuccess:(OWSThumbnailSuccess)success failure:(OWSThumbnailFailure)failure; - (nullable UIImage *)thumbnailImageMediumWithSuccess:(OWSThumbnailSuccess)success failure:(OWSThumbnailFailure)failure; +- (nullable UIImage *)thumbnailImageLargeWithSuccess:(OWSThumbnailSuccess)success failure:(OWSThumbnailFailure)failure; - (nullable UIImage *)thumbnailImageSmallSync; // This method should only be invoked by OWSThumbnailService. diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m index 83009a87a..e9976ae85 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m @@ -15,6 +15,13 @@ NS_ASSUME_NONNULL_BEGIN const NSUInteger kThumbnailDimensionPointsSmall = 200; const NSUInteger kThumbnailDimensionPointsMedium = 450; +// This size is large enough to render full screen. +const NSUInteger ThumbnailDimensionPointsLarge() +{ + CGSize screenSizePoints = UIScreen.mainScreen.bounds.size; + const CGFloat kMinZoomFactor = 2.f; + return MAX(screenSizePoints.width * kMinZoomFactor, screenSizePoints.height * kMinZoomFactor); +} typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail); @@ -625,8 +632,10 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail); NSUInteger thumbnailDimensionPoints; if (maxDimensionHint <= kThumbnailDimensionPointsSmall) { thumbnailDimensionPoints = kThumbnailDimensionPointsSmall; - } else { + } else if (maxDimensionHint <= kThumbnailDimensionPointsMedium) { thumbnailDimensionPoints = kThumbnailDimensionPointsMedium; + } else { + thumbnailDimensionPoints = ThumbnailDimensionPointsLarge(); } return [self thumbnailImageWithThumbnailDimensionPoints:thumbnailDimensionPoints success:success failure:failure]; @@ -646,6 +655,13 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail); failure:failure]; } +- (nullable UIImage *)thumbnailImageLargeWithSuccess:(OWSThumbnailSuccess)success failure:(OWSThumbnailFailure)failure +{ + return [self thumbnailImageWithThumbnailDimensionPoints:ThumbnailDimensionPointsLarge() + success:success + failure:failure]; +} + - (nullable UIImage *)thumbnailImageWithThumbnailDimensionPoints:(NSUInteger)thumbnailDimensionPoints success:(OWSThumbnailSuccess)success failure:(OWSThumbnailFailure)failure