Ensure constant bubble sizes for generic attachments.

pull/2/head
Matthew Chen 6 years ago
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 NS_ASSUME_NONNULL_BEGIN
@class ConversationStyle; @class ConversationStyle;
@class TSAttachmentStream; @class TSAttachment;
@interface OWSGenericAttachmentView : UIStackView @interface OWSGenericAttachmentView : UIStackView
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachmentStream isIncoming:(BOOL)isIncoming; - (instancetype)initWithAttachment:(TSAttachment *)attachment isIncoming:(BOOL)isIncoming;
- (void)createContentsWithConversationStyle:(ConversationStyle *)conversationStyle; - (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" #import "OWSGenericAttachmentView.h"
@ -18,7 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSGenericAttachmentView () @interface OWSGenericAttachmentView ()
@property (nonatomic) TSAttachmentStream *attachmentStream; @property (nonatomic) TSAttachment *attachment;
@property (nonatomic, nullable) TSAttachmentStream *attachmentStream;
@property (nonatomic) BOOL isIncoming; @property (nonatomic) BOOL isIncoming;
@property (nonatomic) UILabel *topLabel; @property (nonatomic) UILabel *topLabel;
@property (nonatomic) UILabel *bottomLabel; @property (nonatomic) UILabel *bottomLabel;
@ -29,12 +30,15 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSGenericAttachmentView @implementation OWSGenericAttachmentView
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachmentStream isIncoming:(BOOL)isIncoming - (instancetype)initWithAttachment:(TSAttachment *)attachment isIncoming:(BOOL)isIncoming
{ {
self = [super init]; self = [super init];
if (self) { if (self) {
_attachmentStream = attachmentStream; _attachment = attachment;
if ([attachment isKindOfClass:[TSAttachmentStream class]]) {
_attachmentStream = (TSAttachmentStream *)attachment;
}
_isIncoming = isIncoming; _isIncoming = isIncoming;
} }
@ -105,13 +109,13 @@ NS_ASSUME_NONNULL_BEGIN
[self addArrangedSubview:imageView]; [self addArrangedSubview:imageView];
[imageView setContentHuggingHigh]; [imageView setContentHuggingHigh];
NSString *filename = self.attachmentStream.sourceFilename; NSString *_Nullable filename = self.attachment.sourceFilename;
if (!filename) { if (!filename) {
filename = [[self.attachmentStream originalFilePath] lastPathComponent]; filename = [[self.attachmentStream originalFilePath] lastPathComponent];
} }
NSString *fileExtension = filename.pathExtension; NSString *fileExtension = filename.pathExtension;
if (fileExtension.length < 1) { if (fileExtension.length < 1) {
fileExtension = [MIMETypeUtil fileExtensionForMIMEType:self.attachmentStream.contentType]; fileExtension = [MIMETypeUtil fileExtensionForMIMEType:self.attachment.contentType];
} }
UILabel *fileTypeLabel = [UILabel new]; UILabel *fileTypeLabel = [UILabel new];
@ -132,9 +136,9 @@ NS_ASSUME_NONNULL_BEGIN
labelsView.alignment = UIStackViewAlignmentLeading; labelsView.alignment = UIStackViewAlignmentLeading;
[self addArrangedSubview:labelsView]; [self addArrangedSubview:labelsView];
NSString *topText = [self.attachmentStream.sourceFilename ows_stripped]; NSString *topText = [self.attachment.sourceFilename ows_stripped];
if (topText.length < 1) { if (topText.length < 1) {
topText = [MIMETypeUtil fileExtensionForMIMEType:self.attachmentStream.contentType].localizedUppercaseString; topText = [MIMETypeUtil fileExtensionForMIMEType:self.attachment.contentType].localizedUppercaseString;
} }
if (topText.length < 1) { if (topText.length < 1) {
topText = NSLocalizedString(@"GENERIC_ATTACHMENT_LABEL", @"A label for generic attachments."); topText = NSLocalizedString(@"GENERIC_ATTACHMENT_LABEL", @"A label for generic attachments.");
@ -147,12 +151,18 @@ NS_ASSUME_NONNULL_BEGIN
topLabel.font = [OWSGenericAttachmentView topLabelFont]; topLabel.font = [OWSGenericAttachmentView topLabelFont];
[labelsView addArrangedSubview:topLabel]; [labelsView addArrangedSubview:topLabel];
NSError *error; unsigned long long fileSize = 0;
unsigned long long fileSize = if (self.attachmentStream) {
[[NSFileManager defaultManager] attributesOfItemAtPath:[self.attachmentStream originalFilePath] error:&error] NSError *error;
.fileSize; fileSize = [[NSFileManager defaultManager] attributesOfItemAtPath:[self.attachmentStream originalFilePath]
OWSAssertDebug(!error); error:&error]
NSString *bottomText = [OWSFormat formatFileSize:fileSize]; .fileSize;
OWSAssertDebug(!error);
}
NSString *bottomText = @" ";
if (fileSize > 0) {
bottomText = [OWSFormat formatFileSize:fileSize];
}
UILabel *bottomLabel = [UILabel new]; UILabel *bottomLabel = [UILabel new];
self.bottomLabel = bottomLabel; self.bottomLabel = bottomLabel;
bottomLabel.text = bottomText; bottomLabel.text = bottomText;

@ -853,11 +853,10 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
- (UIView *)loadViewForGenericAttachment - (UIView *)loadViewForGenericAttachment
{ {
OWSAssertDebug(self.viewItem.attachmentStream); TSAttachment *attachment = (self.viewItem.attachmentStream ?: self.viewItem.attachmentPointer);
OWSAssertDebug(attachment);
// TODO:
OWSGenericAttachmentView *attachmentView = OWSGenericAttachmentView *attachmentView =
[[OWSGenericAttachmentView alloc] initWithAttachment:self.viewItem.attachmentStream isIncoming:self.isIncoming]; [[OWSGenericAttachmentView alloc] initWithAttachment:attachment isIncoming:self.isIncoming];
[attachmentView createContentsWithConversationStyle:self.conversationStyle]; [attachmentView createContentsWithConversationStyle:self.conversationStyle];
[self addProgressViewsIfNecessary:attachmentView]; [self addProgressViewsIfNecessary:attachmentView];
@ -1068,10 +1067,10 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
result = CGSizeMake(maxMessageWidth, OWSAudioMessageView.bubbleHeight); result = CGSizeMake(maxMessageWidth, OWSAudioMessageView.bubbleHeight);
break; break;
case OWSMessageCellType_GenericAttachment: { case OWSMessageCellType_GenericAttachment: {
OWSAssertDebug(self.viewItem.attachmentStream); TSAttachment *attachment = (self.viewItem.attachmentStream ?: self.viewItem.attachmentPointer);
OWSAssertDebug(attachment);
OWSGenericAttachmentView *attachmentView = OWSGenericAttachmentView *attachmentView =
[[OWSGenericAttachmentView alloc] initWithAttachment:self.viewItem.attachmentStream [[OWSGenericAttachmentView alloc] initWithAttachment:attachment isIncoming:self.isIncoming];
isIncoming:self.isIncoming];
[attachmentView createContentsWithConversationStyle:self.conversationStyle]; [attachmentView createContentsWithConversationStyle:self.conversationStyle];
result = [attachmentView measureSizeWithMaxMessageWidth:maxMessageWidth]; result = [attachmentView measureSizeWithMaxMessageWidth:maxMessageWidth];
break; break;

@ -643,7 +643,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
self.audioDurationSeconds = 0; self.audioDurationSeconds = 0;
self.messageCellType = OWSMessageCellType_Audio; self.messageCellType = OWSMessageCellType_Audio;
} else { } else {
self.messageCellType = OWSMessageCellType_DownloadingAttachment; self.messageCellType = OWSMessageCellType_GenericAttachment;
} }
self.attachmentPointer = (TSAttachmentPointer *)mediaAttachment; self.attachmentPointer = (TSAttachmentPointer *)mediaAttachment;
} else { } else {

Loading…
Cancel
Save