Use new thumbnails in conversation cells.

pull/1/head
Matthew Chen 7 years ago
parent 3437361d70
commit cf469da943

@ -655,6 +655,7 @@ NS_ASSUME_NONNULL_BEGIN
mediaView:(UIView *)mediaView mediaView:(UIView *)mediaView
cacheKey:(NSString *)cacheKey cacheKey:(NSString *)cacheKey
shouldSkipCache:(BOOL)shouldSkipCache shouldSkipCache:(BOOL)shouldSkipCache
canLoadAsync:(BOOL)canLoadAsync
{ {
OWSAssert(self.attachmentStream); OWSAssert(self.attachmentStream);
OWSAssert(mediaView); OWSAssert(mediaView);
@ -676,7 +677,7 @@ NS_ASSUME_NONNULL_BEGIN
if (!shouldSkipCache) { if (!shouldSkipCache) {
[self.cellMediaCache setObject:cellMedia forKey:cacheKey]; [self.cellMediaCache setObject:cellMedia forKey:cacheKey];
} }
} else { } else if (!canLoadAsync) {
DDLogError(@"%@ Failed to load cell media: %@", [self logTag], [self.attachmentStream originalMediaURL]); DDLogError(@"%@ Failed to load cell media: %@", [self logTag], [self.attachmentStream originalMediaURL]);
self.viewItem.didCellMediaFailToLoad = YES; self.viewItem.didCellMediaFailToLoad = YES;
[self showAttachmentErrorViewWithMediaView:mediaView]; [self showAttachmentErrorViewWithMediaView:mediaView];
@ -836,6 +837,8 @@ NS_ASSUME_NONNULL_BEGIN
stillImageView.backgroundColor = [UIColor whiteColor]; stillImageView.backgroundColor = [UIColor whiteColor];
[self addAttachmentUploadViewIfNecessary]; [self addAttachmentUploadViewIfNecessary];
__weak UIImageView *weakImageView = stillImageView;
__weak OWSMessageBubbleView *weakSelf = self; __weak OWSMessageBubbleView *weakSelf = self;
self.loadCellContentBlock = ^{ self.loadCellContentBlock = ^{
OWSMessageBubbleView *strongSelf = weakSelf; OWSMessageBubbleView *strongSelf = weakSelf;
@ -853,13 +856,17 @@ NS_ASSUME_NONNULL_BEGIN
BOOL shouldSkipCache = BOOL shouldSkipCache =
[OWSFileSystem fileSizeOfPath:strongSelf.attachmentStream.originalFilePath].unsignedIntegerValue [OWSFileSystem fileSizeOfPath:strongSelf.attachmentStream.originalFilePath].unsignedIntegerValue
< kMaxCachableSize; < kMaxCachableSize;
stillImageView.image = [strongSelf tryToLoadCellMedia:^{ stillImageView.image = [strongSelf
OWSCAssert([strongSelf.attachmentStream isImage]); tryToLoadCellMedia:^{
return strongSelf.attachmentStream.originalImage; OWSCAssert([strongSelf.attachmentStream isImage]);
} return [strongSelf.attachmentStream thumbnailImageMediumWithCompletion:^(UIImage *image) {
mediaView:stillImageView weakImageView.image = image;
cacheKey:strongSelf.attachmentStream.uniqueId }];
shouldSkipCache:shouldSkipCache]; }
mediaView:stillImageView
cacheKey:strongSelf.attachmentStream.uniqueId
shouldSkipCache:shouldSkipCache
canLoadAsync:YES];
}; };
self.unloadCellContentBlock = ^{ self.unloadCellContentBlock = ^{
OWSMessageBubbleView *strongSelf = weakSelf; OWSMessageBubbleView *strongSelf = weakSelf;
@ -895,19 +902,21 @@ NS_ASSUME_NONNULL_BEGIN
if (animatedImageView.image) { if (animatedImageView.image) {
return; return;
} }
animatedImageView.image = [strongSelf tryToLoadCellMedia:^{ animatedImageView.image = [strongSelf
OWSCAssert([strongSelf.attachmentStream isAnimated]); tryToLoadCellMedia:^{
OWSCAssert([strongSelf.attachmentStream isAnimated]);
NSString *_Nullable filePath = [strongSelf.attachmentStream originalFilePath];
YYImage *_Nullable animatedImage = nil; NSString *_Nullable filePath = [strongSelf.attachmentStream originalFilePath];
if (strongSelf.attachmentStream.isValidImage && filePath) { YYImage *_Nullable animatedImage = nil;
animatedImage = [YYImage imageWithContentsOfFile:filePath]; if (strongSelf.attachmentStream.isValidImage && filePath) {
animatedImage = [YYImage imageWithContentsOfFile:filePath];
}
return animatedImage;
} }
return animatedImage; mediaView:animatedImageView
} cacheKey:strongSelf.attachmentStream.uniqueId
mediaView:animatedImageView shouldSkipCache:NO
cacheKey:strongSelf.attachmentStream.uniqueId canLoadAsync:NO];
shouldSkipCache:NO];
}; };
self.unloadCellContentBlock = ^{ self.unloadCellContentBlock = ^{
OWSMessageBubbleView *strongSelf = weakSelf; OWSMessageBubbleView *strongSelf = weakSelf;
@ -976,14 +985,16 @@ NS_ASSUME_NONNULL_BEGIN
if (stillImageView.image) { if (stillImageView.image) {
return; return;
} }
stillImageView.image = [strongSelf tryToLoadCellMedia:^{ stillImageView.image = [strongSelf
OWSCAssert([strongSelf.attachmentStream isVideo]); tryToLoadCellMedia:^{
OWSCAssert([strongSelf.attachmentStream isVideo]);
return strongSelf.attachmentStream.originalImage; return strongSelf.attachmentStream.originalImage;
} }
mediaView:stillImageView mediaView:stillImageView
cacheKey:strongSelf.attachmentStream.uniqueId cacheKey:strongSelf.attachmentStream.uniqueId
shouldSkipCache:NO]; shouldSkipCache:NO
canLoadAsync:NO];
}; };
self.unloadCellContentBlock = ^{ self.unloadCellContentBlock = ^{
OWSMessageBubbleView *strongSelf = weakSelf; OWSMessageBubbleView *strongSelf = weakSelf;

Loading…
Cancel
Save