mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Cache image size and audio duration on attachments.
// FREEBIE
This commit is contained in:
parent
b0fad7ed59
commit
b1f7cf0d62
5 changed files with 16 additions and 32 deletions
4
Podfile
4
Podfile
|
@ -5,8 +5,8 @@ target 'Signal' do
|
|||
pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git'
|
||||
pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git'
|
||||
#pod 'AxolotlKit', path: '../SignalProtocolKit'
|
||||
pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git'
|
||||
#pod 'SignalServiceKit', path: '../SignalServiceKit'
|
||||
#pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git'
|
||||
pod 'SignalServiceKit', path: '../SignalServiceKit'
|
||||
pod 'OpenSSL'
|
||||
pod 'JSQMessagesViewController', git: 'https://github.com/WhisperSystems/JSQMessagesViewController.git', branch: 'mkirk/position-edit-menu'
|
||||
#pod 'JSQMessagesViewController' path: '../JSQMessagesViewController'
|
||||
|
|
|
@ -114,7 +114,7 @@ DEPENDENCIES:
|
|||
- OpenSSL
|
||||
- PureLayout
|
||||
- Reachability
|
||||
- SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`)
|
||||
- SignalServiceKit (from `../SignalServiceKit`)
|
||||
- SocketRocket (from `https://github.com/facebook/SocketRocket.git`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
|
@ -124,7 +124,7 @@ EXTERNAL SOURCES:
|
|||
:branch: mkirk/position-edit-menu
|
||||
:git: https://github.com/WhisperSystems/JSQMessagesViewController.git
|
||||
SignalServiceKit:
|
||||
:git: https://github.com/WhisperSystems/SignalServiceKit.git
|
||||
:path: ../SignalServiceKit
|
||||
SocketRocket:
|
||||
:git: https://github.com/facebook/SocketRocket.git
|
||||
|
||||
|
@ -135,9 +135,6 @@ CHECKOUT OPTIONS:
|
|||
JSQMessagesViewController:
|
||||
:commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308
|
||||
:git: https://github.com/WhisperSystems/JSQMessagesViewController.git
|
||||
SignalServiceKit:
|
||||
:commit: d61235825680e9b563f28cbbbaf6772c19f85674
|
||||
:git: https://github.com/WhisperSystems/SignalServiceKit.git
|
||||
SocketRocket:
|
||||
:commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf
|
||||
:git: https://github.com/facebook/SocketRocket.git
|
||||
|
@ -164,6 +161,6 @@ SPEC CHECKSUMS:
|
|||
UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d
|
||||
YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266
|
||||
|
||||
PODFILE CHECKSUM: 48e80d7f1e049bbf544a689fdfdf33e8196c640a
|
||||
PODFILE CHECKSUM: 6f9ef5d9fa17469569e127a9f5719dafa11631b9
|
||||
|
||||
COCOAPODS: 1.2.1
|
||||
|
|
|
@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
_attachment = attachment;
|
||||
_attachmentId = attachment.uniqueId;
|
||||
_incoming = incoming;
|
||||
_imageSize = attachment.mediaURL ? [self sizeOfImageAtURL:attachment.mediaURL] : CGSizeZero;
|
||||
_imageSize = [attachment cachedImageSizeWithoutTransaction];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
|
|
@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
_attachment = attachment;
|
||||
_attachmentId = attachment.uniqueId;
|
||||
_incoming = incoming;
|
||||
_imageSize = attachment.mediaURL ? [self sizeOfImageAtURL:attachment.mediaURL] : CGSizeZero;
|
||||
_imageSize = [attachment cachedImageSizeWithoutTransaction];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@interface TSVideoAttachmentAdapter ()
|
||||
|
||||
@property (nonatomic) UIImage *image;
|
||||
@property (nonatomic, nullable) UIView *cachedMediaView;
|
||||
@property (nonatomic) TSAttachmentStream *attachment;
|
||||
@property (nonatomic, nullable) UIButton *audioPlayPauseButton;
|
||||
|
@ -36,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@property (nonatomic) CGFloat audioProgressSeconds;
|
||||
@property (nonatomic) CGFloat audioDurationSeconds;
|
||||
@property (nonatomic) BOOL isPaused;
|
||||
@property (nonatomic) CGSize imageSize;
|
||||
|
||||
// See comments on OWSMessageMediaAdapter.
|
||||
@property (nonatomic, nullable, weak) id lastPresentingCell;
|
||||
|
@ -50,12 +50,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
self = [super initWithFileURL:[attachment mediaURL] isReadyToPlay:YES];
|
||||
|
||||
if (self) {
|
||||
_image = attachment.image;
|
||||
_cachedMediaView = nil;
|
||||
_attachmentId = attachment.uniqueId;
|
||||
_contentType = attachment.contentType;
|
||||
_attachment = attachment;
|
||||
_incoming = incoming;
|
||||
_imageSize = [attachment cachedImageSizeWithoutTransaction];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -224,7 +224,11 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
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.frame = CGRectMake(0.0f, 0.0f, size.width, size.height);
|
||||
imageView.clipsToBounds = YES;
|
||||
|
@ -261,7 +265,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
{
|
||||
OWSAssert([self isAudio]);
|
||||
|
||||
[self ensureAudioDurationSeconds];
|
||||
self.audioDurationSeconds = [self.attachment cachedAudioDurationSecondsWithoutTransaction];
|
||||
|
||||
CGSize viewSize = [self mediaViewDisplaySize];
|
||||
UIColor *textColor = [self audioTextColor];
|
||||
|
@ -351,30 +355,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
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 size = [super mediaViewDisplaySize];
|
||||
if ([self isAudio]) {
|
||||
size.width = [self ows_maxMediaBubbleWidth:size];
|
||||
size.height = (CGFloat)ceil(self.audioBubbleHeight);
|
||||
} else if ([self isVideo]) {
|
||||
return [self ows_adjustBubbleSize:size forImage:self.image];
|
||||
return [self ows_adjustBubbleSize:size forImageSize:self.imageSize];
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue