From 48e6cea20766929074f9e1f14ca521c5b8219313 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 29 Sep 2017 21:54:06 -0400 Subject: [PATCH] Replace FLAnimatedImage with YYImage. // FREEBIE --- .../TSMessageAdapaters/TSAnimatedAdapter.m | 23 +++++++++---------- .../ViewControllers/FullImageViewController.m | 9 ++++---- .../ViewControllers/MediaMessageView.swift | 17 ++++++++------ 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.m b/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.m index 22a853755..16f9a5592 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.m +++ b/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.m @@ -4,7 +4,6 @@ #import "TSAnimatedAdapter.h" #import "AttachmentUploadView.h" -#import "FLAnimatedImage.h" #import "JSQMediaItem+OWS.h" #import "TSAttachmentStream.h" #import "UIColor+OWS.h" @@ -13,12 +12,13 @@ #import #import #import +#import NS_ASSUME_NONNULL_BEGIN @interface TSAnimatedAdapter () -@property (nonatomic, nullable) FLAnimatedImageView *cachedImageView; +@property (nonatomic, nullable) YYAnimatedImageView *cachedImageView; @property (nonatomic) TSAttachmentStream *attachment; @property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView; @property (nonatomic) BOOL incoming; @@ -101,20 +101,19 @@ NS_ASSUME_NONNULL_BEGIN OWSAssert([NSThread isMainThread]); if (self.cachedImageView == nil) { - // Use Flipboard FLAnimatedImage library to display gifs - NSData *fileData = [NSData dataWithContentsOfURL:[self.attachment mediaURL]]; - if (!fileData) { - DDLogError(@"%@ Could not load image: %@", [self tag], [self.attachment mediaURL]); + NSString *_Nullable filePath = [self.attachment filePath]; + if (![NSData ows_isValidImageAtPath:filePath]) { + return nil; + } + YYImage *_Nullable animatedGif = filePath ? [YYImage imageWithContentsOfFile:filePath] : nil; + if (!animatedGif) { + DDLogError(@"%@ Could not load image: %@", [self tag], filePath); UIView *view = [UIView new]; view.backgroundColor = [UIColor colorWithWhite:0.85f alpha:1.f]; return view; } - if (![fileData ows_isValidImage]) { - return nil; - } - FLAnimatedImage *animatedGif = [FLAnimatedImage animatedImageWithGIFData:fileData]; - FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init]; - imageView.animatedImage = animatedGif; + YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc] init]; + imageView.image = animatedGif; CGSize size = [self mediaViewDisplaySize]; imageView.contentMode = UIViewContentModeScaleAspectFill; imageView.frame = CGRectMake(0.0, 0.0, size.width, size.height); diff --git a/Signal/src/ViewControllers/FullImageViewController.m b/Signal/src/ViewControllers/FullImageViewController.m index cc83f00d2..5879093d9 100644 --- a/Signal/src/ViewControllers/FullImageViewController.m +++ b/Signal/src/ViewControllers/FullImageViewController.m @@ -4,7 +4,6 @@ #import "FullImageViewController.h" #import "AttachmentSharing.h" -#import "FLAnimatedImage.h" #import "TSAnimatedAdapter.h" #import "TSMessageAdapter.h" #import "TSPhotoAdapter.h" @@ -12,6 +11,7 @@ #import "UIUtil.h" #import "UIView+OWS.h" #import +#import NS_ASSUME_NONNULL_BEGIN @@ -170,10 +170,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)initializeImageView { if (self.isAnimated) { if ([self.fileData ows_isValidImage]) { - // Present the animated image using Flipboard/FLAnimatedImage - FLAnimatedImage *animatedGif = [FLAnimatedImage animatedImageWithGIFData:self.fileData]; - FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init]; - imageView.animatedImage = animatedGif; + YYImage *animatedGif = [YYImage imageWithData:self.fileData]; + YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc] init]; + imageView.image = animatedGif; imageView.frame = self.originRect; imageView.contentMode = UIViewContentModeScaleAspectFill; imageView.clipsToBounds = YES; diff --git a/Signal/src/ViewControllers/MediaMessageView.swift b/Signal/src/ViewControllers/MediaMessageView.swift index 0a9364567..4ee72444d 100644 --- a/Signal/src/ViewControllers/MediaMessageView.swift +++ b/Signal/src/ViewControllers/MediaMessageView.swift @@ -138,16 +138,19 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { private func createAnimatedPreview() { guard attachment.isValidImage else { - return - } - let data = attachment.data - // Use Flipboard FLAnimatedImage library to display gifs - guard let animatedImage = FLAnimatedImage(gifData:data) else { createGenericPreview() return } - let animatedImageView = FLAnimatedImageView() - animatedImageView.animatedImage = animatedImage + guard let dataUrl = attachment.dataUrl else { + createGenericPreview() + return + } + guard let image = YYImage(contentsOfFile:dataUrl.path) else { + createGenericPreview() + return + } + let animatedImageView = YYAnimatedImageView() + animatedImageView.image = image animatedImageView.contentMode = .scaleAspectFit self.addSubview(animatedImageView) animatedImageView.autoPinWidthToSuperview()