Ensure constant bubble sizes for generic attachments.
This commit is contained in:
parent
3702dfa198
commit
dc168270c2
|
@ -1,15 +1,15 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class ConversationStyle;
|
||||
@class TSAttachmentStream;
|
||||
@class TSAttachment;
|
||||
|
||||
@interface OWSGenericAttachmentView : UIStackView
|
||||
|
||||
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachmentStream isIncoming:(BOOL)isIncoming;
|
||||
- (instancetype)initWithAttachment:(TSAttachment *)attachment isIncoming:(BOOL)isIncoming;
|
||||
|
||||
- (void)createContentsWithConversationStyle:(ConversationStyle *)conversationStyle;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSGenericAttachmentView.h"
|
||||
|
@ -18,7 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@interface OWSGenericAttachmentView ()
|
||||
|
||||
@property (nonatomic) TSAttachmentStream *attachmentStream;
|
||||
@property (nonatomic) TSAttachment *attachment;
|
||||
@property (nonatomic, nullable) TSAttachmentStream *attachmentStream;
|
||||
@property (nonatomic) BOOL isIncoming;
|
||||
@property (nonatomic) UILabel *topLabel;
|
||||
@property (nonatomic) UILabel *bottomLabel;
|
||||
|
@ -29,12 +30,15 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@implementation OWSGenericAttachmentView
|
||||
|
||||
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachmentStream isIncoming:(BOOL)isIncoming
|
||||
- (instancetype)initWithAttachment:(TSAttachment *)attachment isIncoming:(BOOL)isIncoming
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
_attachmentStream = attachmentStream;
|
||||
_attachment = attachment;
|
||||
if ([attachment isKindOfClass:[TSAttachmentStream class]]) {
|
||||
_attachmentStream = (TSAttachmentStream *)attachment;
|
||||
}
|
||||
_isIncoming = isIncoming;
|
||||
}
|
||||
|
||||
|
@ -105,13 +109,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[self addArrangedSubview:imageView];
|
||||
[imageView setContentHuggingHigh];
|
||||
|
||||
NSString *filename = self.attachmentStream.sourceFilename;
|
||||
NSString *_Nullable filename = self.attachment.sourceFilename;
|
||||
if (!filename) {
|
||||
filename = [[self.attachmentStream originalFilePath] lastPathComponent];
|
||||
}
|
||||
NSString *fileExtension = filename.pathExtension;
|
||||
if (fileExtension.length < 1) {
|
||||
fileExtension = [MIMETypeUtil fileExtensionForMIMEType:self.attachmentStream.contentType];
|
||||
fileExtension = [MIMETypeUtil fileExtensionForMIMEType:self.attachment.contentType];
|
||||
}
|
||||
|
||||
UILabel *fileTypeLabel = [UILabel new];
|
||||
|
@ -132,9 +136,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
labelsView.alignment = UIStackViewAlignmentLeading;
|
||||
[self addArrangedSubview:labelsView];
|
||||
|
||||
NSString *topText = [self.attachmentStream.sourceFilename ows_stripped];
|
||||
NSString *topText = [self.attachment.sourceFilename ows_stripped];
|
||||
if (topText.length < 1) {
|
||||
topText = [MIMETypeUtil fileExtensionForMIMEType:self.attachmentStream.contentType].localizedUppercaseString;
|
||||
topText = [MIMETypeUtil fileExtensionForMIMEType:self.attachment.contentType].localizedUppercaseString;
|
||||
}
|
||||
if (topText.length < 1) {
|
||||
topText = NSLocalizedString(@"GENERIC_ATTACHMENT_LABEL", @"A label for generic attachments.");
|
||||
|
@ -147,12 +151,18 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
topLabel.font = [OWSGenericAttachmentView topLabelFont];
|
||||
[labelsView addArrangedSubview:topLabel];
|
||||
|
||||
NSError *error;
|
||||
unsigned long long fileSize =
|
||||
[[NSFileManager defaultManager] attributesOfItemAtPath:[self.attachmentStream originalFilePath] error:&error]
|
||||
.fileSize;
|
||||
OWSAssertDebug(!error);
|
||||
NSString *bottomText = [OWSFormat formatFileSize:fileSize];
|
||||
unsigned long long fileSize = 0;
|
||||
if (self.attachmentStream) {
|
||||
NSError *error;
|
||||
fileSize = [[NSFileManager defaultManager] attributesOfItemAtPath:[self.attachmentStream originalFilePath]
|
||||
error:&error]
|
||||
.fileSize;
|
||||
OWSAssertDebug(!error);
|
||||
}
|
||||
NSString *bottomText = @" ";
|
||||
if (fileSize > 0) {
|
||||
bottomText = [OWSFormat formatFileSize:fileSize];
|
||||
}
|
||||
UILabel *bottomLabel = [UILabel new];
|
||||
self.bottomLabel = bottomLabel;
|
||||
bottomLabel.text = bottomText;
|
||||
|
|
|
@ -853,11 +853,10 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
|
|||
|
||||
- (UIView *)loadViewForGenericAttachment
|
||||
{
|
||||
OWSAssertDebug(self.viewItem.attachmentStream);
|
||||
|
||||
// TODO:
|
||||
TSAttachment *attachment = (self.viewItem.attachmentStream ?: self.viewItem.attachmentPointer);
|
||||
OWSAssertDebug(attachment);
|
||||
OWSGenericAttachmentView *attachmentView =
|
||||
[[OWSGenericAttachmentView alloc] initWithAttachment:self.viewItem.attachmentStream isIncoming:self.isIncoming];
|
||||
[[OWSGenericAttachmentView alloc] initWithAttachment:attachment isIncoming:self.isIncoming];
|
||||
[attachmentView createContentsWithConversationStyle:self.conversationStyle];
|
||||
[self addProgressViewsIfNecessary:attachmentView];
|
||||
|
||||
|
@ -1068,10 +1067,10 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
|
|||
result = CGSizeMake(maxMessageWidth, OWSAudioMessageView.bubbleHeight);
|
||||
break;
|
||||
case OWSMessageCellType_GenericAttachment: {
|
||||
OWSAssertDebug(self.viewItem.attachmentStream);
|
||||
TSAttachment *attachment = (self.viewItem.attachmentStream ?: self.viewItem.attachmentPointer);
|
||||
OWSAssertDebug(attachment);
|
||||
OWSGenericAttachmentView *attachmentView =
|
||||
[[OWSGenericAttachmentView alloc] initWithAttachment:self.viewItem.attachmentStream
|
||||
isIncoming:self.isIncoming];
|
||||
[[OWSGenericAttachmentView alloc] initWithAttachment:attachment isIncoming:self.isIncoming];
|
||||
[attachmentView createContentsWithConversationStyle:self.conversationStyle];
|
||||
result = [attachmentView measureSizeWithMaxMessageWidth:maxMessageWidth];
|
||||
break;
|
||||
|
|
|
@ -643,7 +643,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|||
self.audioDurationSeconds = 0;
|
||||
self.messageCellType = OWSMessageCellType_Audio;
|
||||
} else {
|
||||
self.messageCellType = OWSMessageCellType_DownloadingAttachment;
|
||||
self.messageCellType = OWSMessageCellType_GenericAttachment;
|
||||
}
|
||||
self.attachmentPointer = (TSAttachmentPointer *)mediaAttachment;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue