Merge branch 'charlesmchen/constantBubbleSizes2'

pull/2/head
Matthew Chen 7 years ago
commit ca6f3b52a1

@ -128,6 +128,45 @@ NS_ASSUME_NONNULL_BEGIN
self.audioProgressView.progressColor = progressColor; self.audioProgressView.progressColor = progressColor;
} }
- (void)replaceIconWithDownloadProgressIfNecessary:(UIView *)iconView
{
if (!self.viewItem.attachmentPointer) {
return;
}
switch (self.viewItem.attachmentPointer.state) {
case TSAttachmentPointerStateFailed:
// We don't need to handle the "tap to retry" state here,
// only download progress.
return;
case TSAttachmentPointerStateEnqueued:
case TSAttachmentPointerStateDownloading:
break;
}
switch (self.viewItem.attachmentPointer.pointerType) {
case TSAttachmentPointerTypeRestoring:
// TODO: Show "restoring" indicator and possibly progress.
return;
case TSAttachmentPointerTypeUnknown:
case TSAttachmentPointerTypeIncoming:
break;
}
NSString *_Nullable uniqueId = self.viewItem.attachmentPointer.uniqueId;
if (uniqueId.length < 1) {
OWSFailDebug(@"Missing uniqueId.");
return;
}
CGFloat downloadViewSize = self.iconSize;
MediaDownloadView *downloadView =
[[MediaDownloadView alloc] initWithAttachmentId:uniqueId radius:downloadViewSize * 0.5f];
iconView.layer.opacity = 0.01f;
[self addSubview:downloadView];
[downloadView autoSetDimensionsToSize:CGSizeMake(downloadViewSize, downloadViewSize)];
[downloadView autoAlignAxis:ALAxisHorizontal toSameAxisOfView:iconView];
[downloadView autoAlignAxis:ALAxisVertical toSameAxisOfView:iconView];
}
#pragma mark - #pragma mark -
- (CGFloat)hMargin - (CGFloat)hMargin
@ -192,6 +231,8 @@ NS_ASSUME_NONNULL_BEGIN
[self addArrangedSubview:self.audioPlayPauseButton]; [self addArrangedSubview:self.audioPlayPauseButton];
[self.audioPlayPauseButton setContentHuggingHigh]; [self.audioPlayPauseButton setContentHuggingHigh];
[self replaceIconWithDownloadProgressIfNecessary:self.audioPlayPauseButton];
NSString *_Nullable filename = self.attachment.sourceFilename; NSString *_Nullable filename = self.attachment.sourceFilename;
if (filename.length < 1) { if (filename.length < 1) {
filename = [self.attachmentStream.originalFilePath lastPathComponent]; filename = [self.attachmentStream.originalFilePath lastPathComponent];

@ -7,9 +7,13 @@ NS_ASSUME_NONNULL_BEGIN
@class ConversationStyle; @class ConversationStyle;
@class TSAttachment; @class TSAttachment;
@protocol ConversationViewItem;
@interface OWSGenericAttachmentView : UIStackView @interface OWSGenericAttachmentView : UIStackView
- (instancetype)initWithAttachment:(TSAttachment *)attachment isIncoming:(BOOL)isIncoming; - (instancetype)initWithAttachment:(TSAttachment *)attachment
isIncoming:(BOOL)isIncoming
viewItem:(id<ConversationViewItem>)viewItem;
- (void)createContentsWithConversationStyle:(ConversationStyle *)conversationStyle; - (void)createContentsWithConversationStyle:(ConversationStyle *)conversationStyle;

@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) TSAttachment *attachment; @property (nonatomic) TSAttachment *attachment;
@property (nonatomic, nullable) TSAttachmentStream *attachmentStream; @property (nonatomic, nullable) TSAttachmentStream *attachmentStream;
@property (nonatomic, weak) id<ConversationViewItem> viewItem;
@property (nonatomic) BOOL isIncoming; @property (nonatomic) BOOL isIncoming;
@property (nonatomic) UILabel *topLabel; @property (nonatomic) UILabel *topLabel;
@property (nonatomic) UILabel *bottomLabel; @property (nonatomic) UILabel *bottomLabel;
@ -30,7 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSGenericAttachmentView @implementation OWSGenericAttachmentView
- (instancetype)initWithAttachment:(TSAttachment *)attachment isIncoming:(BOOL)isIncoming - (instancetype)initWithAttachment:(TSAttachment *)attachment
isIncoming:(BOOL)isIncoming
viewItem:(id<ConversationViewItem>)viewItem
{ {
self = [super init]; self = [super init];
@ -40,6 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
_attachmentStream = (TSAttachmentStream *)attachment; _attachmentStream = (TSAttachmentStream *)attachment;
} }
_isIncoming = isIncoming; _isIncoming = isIncoming;
_viewItem = viewItem;
} }
return self; return self;
@ -130,6 +134,8 @@ NS_ASSUME_NONNULL_BEGIN
[fileTypeLabel autoCenterInSuperview]; [fileTypeLabel autoCenterInSuperview];
[fileTypeLabel autoSetDimension:ALDimensionWidth toSize:self.iconWidth - 20.f]; [fileTypeLabel autoSetDimension:ALDimensionWidth toSize:self.iconWidth - 20.f];
[self replaceIconWithDownloadProgressIfNecessary:imageView];
UIStackView *labelsView = [UIStackView new]; UIStackView *labelsView = [UIStackView new];
labelsView.axis = UILayoutConstraintAxisVertical; labelsView.axis = UILayoutConstraintAxisVertical;
labelsView.spacing = [OWSGenericAttachmentView labelVSpacing]; labelsView.spacing = [OWSGenericAttachmentView labelVSpacing];
@ -175,6 +181,46 @@ NS_ASSUME_NONNULL_BEGIN
[labelsView addArrangedSubview:bottomLabel]; [labelsView addArrangedSubview:bottomLabel];
} }
- (void)replaceIconWithDownloadProgressIfNecessary:(UIView *)iconView
{
if (!self.viewItem.attachmentPointer) {
return;
}
switch (self.viewItem.attachmentPointer.state) {
case TSAttachmentPointerStateFailed:
// We don't need to handle the "tap to retry" state here,
// only download progress.
return;
case TSAttachmentPointerStateEnqueued:
case TSAttachmentPointerStateDownloading:
break;
}
switch (self.viewItem.attachmentPointer.pointerType) {
case TSAttachmentPointerTypeRestoring:
// TODO: Show "restoring" indicator and possibly progress.
return;
case TSAttachmentPointerTypeUnknown:
case TSAttachmentPointerTypeIncoming:
break;
}
NSString *_Nullable uniqueId = self.viewItem.attachmentPointer.uniqueId;
if (uniqueId.length < 1) {
OWSFailDebug(@"Missing uniqueId.");
return;
}
CGSize iconViewSize = [iconView sizeThatFits:CGSizeZero];
CGFloat downloadViewSize = MIN(iconViewSize.width, iconViewSize.height);
MediaDownloadView *downloadView =
[[MediaDownloadView alloc] initWithAttachmentId:uniqueId radius:downloadViewSize * 0.5f];
iconView.layer.opacity = 0.01f;
[self addSubview:downloadView];
[downloadView autoSetDimensionsToSize:CGSizeMake(downloadViewSize, downloadViewSize)];
[downloadView autoAlignAxis:ALAxisHorizontal toSameAxisOfView:iconView];
[downloadView autoAlignAxis:ALAxisVertical toSameAxisOfView:iconView];
}
+ (UIFont *)topLabelFont + (UIFont *)topLabelFont
{ {
return [UIFont ows_dynamicTypeBodyFont]; return [UIFont ows_dynamicTypeBodyFont];

@ -838,7 +838,7 @@ NS_ASSUME_NONNULL_BEGIN
conversationStyle:self.conversationStyle]; conversationStyle:self.conversationStyle];
self.viewItem.lastAudioMessageView = audioMessageView; self.viewItem.lastAudioMessageView = audioMessageView;
[audioMessageView createContents]; [audioMessageView createContents];
[self addProgressViewsIfNecessary:audioMessageView]; [self addProgressViewsIfNecessary:audioMessageView shouldShowDownloadProgress:NO];
self.loadCellContentBlock = ^{ self.loadCellContentBlock = ^{
// Do nothing. // Do nothing.
@ -854,10 +854,11 @@ NS_ASSUME_NONNULL_BEGIN
{ {
TSAttachment *attachment = (self.viewItem.attachmentStream ?: self.viewItem.attachmentPointer); TSAttachment *attachment = (self.viewItem.attachmentStream ?: self.viewItem.attachmentPointer);
OWSAssertDebug(attachment); OWSAssertDebug(attachment);
OWSGenericAttachmentView *attachmentView = OWSGenericAttachmentView *attachmentView = [[OWSGenericAttachmentView alloc] initWithAttachment:attachment
[[OWSGenericAttachmentView alloc] initWithAttachment:attachment isIncoming:self.isIncoming]; isIncoming:self.isIncoming
viewItem:self.viewItem];
[attachmentView createContentsWithConversationStyle:self.conversationStyle]; [attachmentView createContentsWithConversationStyle:self.conversationStyle];
[self addProgressViewsIfNecessary:attachmentView]; [self addProgressViewsIfNecessary:attachmentView shouldShowDownloadProgress:NO];
self.loadCellContentBlock = ^{ self.loadCellContentBlock = ^{
// Do nothing. // Do nothing.
@ -895,7 +896,7 @@ NS_ASSUME_NONNULL_BEGIN
// progress or tap-to-retry UI. // progress or tap-to-retry UI.
UIView *attachmentView = [UIView new]; UIView *attachmentView = [UIView new];
[self addProgressViewsIfNecessary:attachmentView]; [self addProgressViewsIfNecessary:attachmentView shouldShowDownloadProgress:YES];
self.loadCellContentBlock = ^{ self.loadCellContentBlock = ^{
// Do nothing. // Do nothing.
@ -907,12 +908,12 @@ NS_ASSUME_NONNULL_BEGIN
return attachmentView; return attachmentView;
} }
- (void)addProgressViewsIfNecessary:(UIView *)bodyMediaView - (void)addProgressViewsIfNecessary:(UIView *)bodyMediaView shouldShowDownloadProgress:(BOOL)shouldShowDownloadProgress
{ {
if (self.viewItem.attachmentStream) { if (self.viewItem.attachmentStream) {
[self addUploadViewIfNecessary:bodyMediaView]; [self addUploadViewIfNecessary:bodyMediaView];
} else if (self.viewItem.attachmentPointer) { } else if (self.viewItem.attachmentPointer) {
[self addDownloadViewIfNecessary:bodyMediaView]; [self addDownloadViewIfNecessary:bodyMediaView shouldShowDownloadProgress:(BOOL)shouldShowDownloadProgress];
} }
} }
@ -934,7 +935,7 @@ NS_ASSUME_NONNULL_BEGIN
[uploadView setCompressionResistanceLow]; [uploadView setCompressionResistanceLow];
} }
- (void)addDownloadViewIfNecessary:(UIView *)bodyMediaView - (void)addDownloadViewIfNecessary:(UIView *)bodyMediaView shouldShowDownloadProgress:(BOOL)shouldShowDownloadProgress
{ {
OWSAssertDebug(self.viewItem.attachmentPointer); OWSAssertDebug(self.viewItem.attachmentPointer);
@ -954,6 +955,9 @@ NS_ASSUME_NONNULL_BEGIN
case TSAttachmentPointerTypeIncoming: case TSAttachmentPointerTypeIncoming:
break; break;
} }
if (!shouldShowDownloadProgress) {
return;
}
NSString *_Nullable uniqueId = self.viewItem.attachmentPointer.uniqueId; NSString *_Nullable uniqueId = self.viewItem.attachmentPointer.uniqueId;
if (uniqueId.length < 1) { if (uniqueId.length < 1) {
OWSFailDebug(@"Missing uniqueId."); OWSFailDebug(@"Missing uniqueId.");
@ -1062,7 +1066,9 @@ NS_ASSUME_NONNULL_BEGIN
TSAttachment *attachment = (self.viewItem.attachmentStream ?: self.viewItem.attachmentPointer); TSAttachment *attachment = (self.viewItem.attachmentStream ?: self.viewItem.attachmentPointer);
OWSAssertDebug(attachment); OWSAssertDebug(attachment);
OWSGenericAttachmentView *attachmentView = OWSGenericAttachmentView *attachmentView =
[[OWSGenericAttachmentView alloc] initWithAttachment:attachment isIncoming:self.isIncoming]; [[OWSGenericAttachmentView alloc] initWithAttachment:attachment
isIncoming:self.isIncoming
viewItem:self.viewItem];
[attachmentView createContentsWithConversationStyle:self.conversationStyle]; [attachmentView createContentsWithConversationStyle:self.conversationStyle];
result = [attachmentView measureSizeWithMaxMessageWidth:maxMessageWidth]; result = [attachmentView measureSizeWithMaxMessageWidth:maxMessageWidth];
break; break;

Loading…
Cancel
Save