Cache image size and audio duration on attachments.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent b0fad7ed59
commit b1f7cf0d62

@ -5,8 +5,8 @@ target 'Signal' do
pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git' pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git'
pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git' pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git'
#pod 'AxolotlKit', path: '../SignalProtocolKit' #pod 'AxolotlKit', path: '../SignalProtocolKit'
pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' #pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git'
#pod 'SignalServiceKit', path: '../SignalServiceKit' pod 'SignalServiceKit', path: '../SignalServiceKit'
pod 'OpenSSL' pod 'OpenSSL'
pod 'JSQMessagesViewController', git: 'https://github.com/WhisperSystems/JSQMessagesViewController.git', branch: 'mkirk/position-edit-menu' pod 'JSQMessagesViewController', git: 'https://github.com/WhisperSystems/JSQMessagesViewController.git', branch: 'mkirk/position-edit-menu'
#pod 'JSQMessagesViewController' path: '../JSQMessagesViewController' #pod 'JSQMessagesViewController' path: '../JSQMessagesViewController'

@ -114,7 +114,7 @@ DEPENDENCIES:
- OpenSSL - OpenSSL
- PureLayout - PureLayout
- Reachability - Reachability
- SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`) - SignalServiceKit (from `../SignalServiceKit`)
- SocketRocket (from `https://github.com/facebook/SocketRocket.git`) - SocketRocket (from `https://github.com/facebook/SocketRocket.git`)
EXTERNAL SOURCES: EXTERNAL SOURCES:
@ -124,7 +124,7 @@ EXTERNAL SOURCES:
:branch: mkirk/position-edit-menu :branch: mkirk/position-edit-menu
:git: https://github.com/WhisperSystems/JSQMessagesViewController.git :git: https://github.com/WhisperSystems/JSQMessagesViewController.git
SignalServiceKit: SignalServiceKit:
:git: https://github.com/WhisperSystems/SignalServiceKit.git :path: ../SignalServiceKit
SocketRocket: SocketRocket:
:git: https://github.com/facebook/SocketRocket.git :git: https://github.com/facebook/SocketRocket.git
@ -135,9 +135,6 @@ CHECKOUT OPTIONS:
JSQMessagesViewController: JSQMessagesViewController:
:commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308 :commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308
:git: https://github.com/WhisperSystems/JSQMessagesViewController.git :git: https://github.com/WhisperSystems/JSQMessagesViewController.git
SignalServiceKit:
:commit: d61235825680e9b563f28cbbbaf6772c19f85674
:git: https://github.com/WhisperSystems/SignalServiceKit.git
SocketRocket: SocketRocket:
:commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf :commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf
:git: https://github.com/facebook/SocketRocket.git :git: https://github.com/facebook/SocketRocket.git
@ -164,6 +161,6 @@ SPEC CHECKSUMS:
UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d
YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266 YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266
PODFILE CHECKSUM: 48e80d7f1e049bbf544a689fdfdf33e8196c640a PODFILE CHECKSUM: 6f9ef5d9fa17469569e127a9f5719dafa11631b9
COCOAPODS: 1.2.1 COCOAPODS: 1.2.1

@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
_attachment = attachment; _attachment = attachment;
_attachmentId = attachment.uniqueId; _attachmentId = attachment.uniqueId;
_incoming = incoming; _incoming = incoming;
_imageSize = attachment.mediaURL ? [self sizeOfImageAtURL:attachment.mediaURL] : CGSizeZero; _imageSize = [attachment cachedImageSizeWithoutTransaction];
} }
return self; return self;

@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
_attachment = attachment; _attachment = attachment;
_attachmentId = attachment.uniqueId; _attachmentId = attachment.uniqueId;
_incoming = incoming; _incoming = incoming;
_imageSize = attachment.mediaURL ? [self sizeOfImageAtURL:attachment.mediaURL] : CGSizeZero; _imageSize = [attachment cachedImageSizeWithoutTransaction];
return self; return self;
} }

@ -24,7 +24,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface TSVideoAttachmentAdapter () @interface TSVideoAttachmentAdapter ()
@property (nonatomic) UIImage *image;
@property (nonatomic, nullable) UIView *cachedMediaView; @property (nonatomic, nullable) UIView *cachedMediaView;
@property (nonatomic) TSAttachmentStream *attachment; @property (nonatomic) TSAttachmentStream *attachment;
@property (nonatomic, nullable) UIButton *audioPlayPauseButton; @property (nonatomic, nullable) UIButton *audioPlayPauseButton;
@ -36,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) CGFloat audioProgressSeconds; @property (nonatomic) CGFloat audioProgressSeconds;
@property (nonatomic) CGFloat audioDurationSeconds; @property (nonatomic) CGFloat audioDurationSeconds;
@property (nonatomic) BOOL isPaused; @property (nonatomic) BOOL isPaused;
@property (nonatomic) CGSize imageSize;
// See comments on OWSMessageMediaAdapter. // See comments on OWSMessageMediaAdapter.
@property (nonatomic, nullable, weak) id lastPresentingCell; @property (nonatomic, nullable, weak) id lastPresentingCell;
@ -50,12 +50,12 @@ NS_ASSUME_NONNULL_BEGIN
self = [super initWithFileURL:[attachment mediaURL] isReadyToPlay:YES]; self = [super initWithFileURL:[attachment mediaURL] isReadyToPlay:YES];
if (self) { if (self) {
_image = attachment.image;
_cachedMediaView = nil; _cachedMediaView = nil;
_attachmentId = attachment.uniqueId; _attachmentId = attachment.uniqueId;
_contentType = attachment.contentType; _contentType = attachment.contentType;
_attachment = attachment; _attachment = attachment;
_incoming = incoming; _incoming = incoming;
_imageSize = [attachment cachedImageSizeWithoutTransaction];
} }
return self; return self;
} }
@ -224,7 +224,11 @@ NS_ASSUME_NONNULL_BEGIN
CGSize size = [self mediaViewDisplaySize]; CGSize size = [self mediaViewDisplaySize];
UIImageView *imageView = [[UIImageView alloc] initWithImage:self.image]; UIImage *image = self.attachment.image;
if (!image) {
return nil;
}
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeScaleAspectFill; imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.frame = CGRectMake(0.0f, 0.0f, size.width, size.height); imageView.frame = CGRectMake(0.0f, 0.0f, size.width, size.height);
imageView.clipsToBounds = YES; imageView.clipsToBounds = YES;
@ -261,7 +265,7 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssert([self isAudio]); OWSAssert([self isAudio]);
[self ensureAudioDurationSeconds]; self.audioDurationSeconds = [self.attachment cachedAudioDurationSecondsWithoutTransaction];
CGSize viewSize = [self mediaViewDisplaySize]; CGSize viewSize = [self mediaViewDisplaySize];
UIColor *textColor = [self audioTextColor]; UIColor *textColor = [self audioTextColor];
@ -351,30 +355,13 @@ NS_ASSUME_NONNULL_BEGIN
return mediaView; return mediaView;
} }
- (void)ensureAudioDurationSeconds
{
if (self.audioDurationSeconds == 0.f) {
NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:self.fileURL error:&error];
if (error && [error.domain isEqualToString:NSOSStatusErrorDomain]
&& (error.code == kAudioFileInvalidFileError || error.code == kAudioFileStreamError_InvalidFile)) {
// Ignore "invalid audio file" errors.
return;
}
OWSAssert(!error);
if (!error) {
self.audioDurationSeconds = (CGFloat)[audioPlayer duration];
}
}
}
- (CGSize)mediaViewDisplaySize { - (CGSize)mediaViewDisplaySize {
CGSize size = [super mediaViewDisplaySize]; CGSize size = [super mediaViewDisplaySize];
if ([self isAudio]) { if ([self isAudio]) {
size.width = [self ows_maxMediaBubbleWidth:size]; size.width = [self ows_maxMediaBubbleWidth:size];
size.height = (CGFloat)ceil(self.audioBubbleHeight); size.height = (CGFloat)ceil(self.audioBubbleHeight);
} else if ([self isVideo]) { } else if ([self isVideo]) {
return [self ows_adjustBubbleSize:size forImage:self.image]; return [self ows_adjustBubbleSize:size forImageSize:self.imageSize];
} }
return size; return size;
} }

Loading…
Cancel
Save