From dc79d302c6b87ccc5e1e387f7d885e5d65c583ac Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 27 Jun 2018 15:13:15 -0400 Subject: [PATCH] Tweak audio messages. --- .../Cells/OWSAudioMessageView.h | 2 +- .../Cells/OWSAudioMessageView.m | 95 +++++++++---------- .../Cells/OWSGenericAttachmentView.m | 32 +++++-- .../Cells/OWSMessageBubbleView.m | 23 +---- 4 files changed, 75 insertions(+), 77 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.h b/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.h index d96257833..065e69c90 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.h +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.h @@ -9,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN @class ConversationViewItem; @class TSAttachmentStream; -@interface OWSAudioMessageView : UIView +@interface OWSAudioMessageView : UIStackView - (instancetype)initWithAttachment:(TSAttachmentStream *)attachmentStream isIncoming:(BOOL)isIncoming diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m index 98a9403af..bcb003e5e 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m @@ -93,13 +93,14 @@ NS_ASSUME_NONNULL_BEGIN - (void)setAudioIcon:(UIImage *)icon iconColor:(UIColor *)iconColor { + OWSAssert(icon.size.height == self.iconSize); + icon = [icon imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [_audioPlayPauseButton setImage:icon forState:UIControlStateNormal]; [_audioPlayPauseButton setImage:icon forState:UIControlStateDisabled]; _audioPlayPauseButton.imageView.tintColor = self.bubbleBackgroundColor; _audioPlayPauseButton.backgroundColor = iconColor; - _audioPlayPauseButton.layer.cornerRadius - = MIN(_audioPlayPauseButton.bounds.size.width, _audioPlayPauseButton.bounds.size.height) * 0.5f; + _audioPlayPauseButton.layer.cornerRadius = self.iconSize * 0.5f; } - (void)setAudioIconToPlay @@ -127,29 +128,33 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - -- (CGFloat)audioIconHMargin +- (CGFloat)hMargin { - return 12.f; + return 0.f; } -- (CGFloat)audioIconHSpacing +- (CGFloat)hSpacing { return 8.f; } -+ (CGFloat)audioIconVMargin ++ (CGFloat)vMargin { - return 12.f; + return 0.f; } -- (CGFloat)audioIconVMargin +- (CGFloat)vMargin { - return [OWSAudioMessageView audioIconVMargin]; + return [OWSAudioMessageView vMargin]; } + (CGFloat)bubbleHeight { - return self.iconSize + self.audioIconVMargin * 2; + CGFloat iconHeight = self.iconSize; + CGFloat labelsHeight = ([OWSAudioMessageView labelFont].lineHeight * 2 + + [OWSAudioMessageView audioProgressViewHeight] + [OWSAudioMessageView labelVSpacing] * 2); + CGFloat contentHeight = MAX(iconHeight, labelsHeight); + return contentHeight + self.vMargin * 2; } - (CGFloat)bubbleHeight @@ -195,36 +200,21 @@ NS_ASSUME_NONNULL_BEGIN { UIColor *textColor = [self audioTextColor]; - self.backgroundColor = self.bubbleBackgroundColor; - self.layoutMargins = UIEdgeInsetsZero; - - // TODO: Verify that this layout works in RTL. - const CGFloat kBubbleTailWidth = 6.f; - - UIView *contentView = [UIView containerView]; - [self addSubview:contentView]; - [contentView autoPinLeadingToSuperviewMarginWithInset:self.isIncoming ? kBubbleTailWidth : 0.f]; - [contentView autoPinTrailingToSuperviewMarginWithInset:self.isIncoming ? 0.f : kBubbleTailWidth]; - [contentView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.audioIconVMargin]; - [contentView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:self.audioIconVMargin]; + self.axis = UILayoutConstraintAxisHorizontal; + self.alignment = UIStackViewAlignmentCenter; + self.spacing = self.hSpacing; _audioPlayPauseButton = [UIButton buttonWithType:UIButtonTypeCustom]; self.audioPlayPauseButton.enabled = NO; - [contentView addSubview:self.audioPlayPauseButton]; - [self.audioPlayPauseButton autoPinLeadingToSuperviewMarginWithInset:self.audioIconHMargin]; - [self.audioPlayPauseButton autoVCenterInSuperview]; - [self.audioPlayPauseButton autoSetDimension:ALDimensionWidth toSize:self.iconSize]; - [self.audioPlayPauseButton autoSetDimension:ALDimensionHeight toSize:self.iconSize]; - - const CGFloat kLabelHSpacing = self.audioIconHSpacing; + [self addArrangedSubview:self.audioPlayPauseButton]; + [self.audioPlayPauseButton setContentHuggingHigh]; - UIView *labelsView = [UIView containerView]; - [contentView addSubview:labelsView]; - [labelsView autoPinLeadingToTrailingEdgeOfView:self.audioPlayPauseButton offset:kLabelHSpacing]; - [labelsView autoPinTrailingToSuperviewMarginWithInset:self.audioIconHMargin]; - [labelsView autoVCenterInSuperview]; + UIStackView *labelsView = [UIStackView new]; + labelsView.axis = UILayoutConstraintAxisVertical; + labelsView.spacing = [OWSAudioMessageView labelVSpacing]; + labelsView.alignment = UIStackViewAlignmentFill; + [self addArrangedSubview:labelsView]; - const CGFloat kLabelVSpacing = 2; NSString *filename = self.attachmentStream.sourceFilename; if (!filename) { filename = [[self.attachmentStream filePath] lastPathComponent]; @@ -243,34 +233,41 @@ NS_ASSUME_NONNULL_BEGIN topLabel.text = topText; topLabel.textColor = [textColor colorWithAlphaComponent:0.85f]; topLabel.lineBreakMode = NSLineBreakByTruncatingMiddle; - topLabel.font = [UIFont ows_regularFontWithSize:ScaleFromIPhone5To7Plus(11.f, 13.f)]; - [labelsView addSubview:topLabel]; - [topLabel autoPinEdgeToSuperviewEdge:ALEdgeTop]; - [topLabel autoPinWidthToSuperview]; + topLabel.font = [OWSAudioMessageView labelFont]; + [labelsView addArrangedSubview:topLabel]; - const CGFloat kAudioProgressViewHeight = 12.f; AudioProgressView *audioProgressView = [AudioProgressView new]; self.audioProgressView = audioProgressView; [self updateAudioProgressView]; - [labelsView addSubview:audioProgressView]; - [audioProgressView autoPinWidthToSuperview]; - [audioProgressView autoSetDimension:ALDimensionHeight toSize:kAudioProgressViewHeight]; - [audioProgressView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topLabel withOffset:kLabelVSpacing]; + [labelsView addArrangedSubview:audioProgressView]; + [audioProgressView autoSetDimension:ALDimensionHeight toSize:[OWSAudioMessageView audioProgressViewHeight]]; UILabel *bottomLabel = [UILabel new]; self.audioBottomLabel = bottomLabel; [self updateAudioBottomLabel]; bottomLabel.textColor = [textColor colorWithAlphaComponent:0.85f]; bottomLabel.lineBreakMode = NSLineBreakByTruncatingMiddle; - bottomLabel.font = [UIFont ows_regularFontWithSize:ScaleFromIPhone5To7Plus(11.f, 13.f)]; - [labelsView addSubview:bottomLabel]; - [bottomLabel autoPinWidthToSuperview]; - [bottomLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:audioProgressView withOffset:kLabelVSpacing]; - [bottomLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom]; + bottomLabel.font = [OWSAudioMessageView labelFont]; + [labelsView addArrangedSubview:bottomLabel]; [self updateContents]; } ++ (CGFloat)audioProgressViewHeight +{ + return 12.f; +} + ++ (UIFont *)labelFont +{ + return [UIFont ows_regularFontWithSize:ScaleFromIPhone5To7Plus(11.f, 13.f)]; +} + ++ (CGFloat)labelVSpacing +{ + return 2.f; +} + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m index 78599afb4..0e44ce564 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m @@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN return 0.f; } -- (CGFloat)iconHSpacing +- (CGFloat)hSpacing { return 8.f; } @@ -63,7 +63,11 @@ NS_ASSUME_NONNULL_BEGIN + (CGFloat)bubbleHeight { - return self.iconHeight + self.vMargin * 2; + CGFloat iconHeight = self.iconHeight; + CGFloat labelsHeight = ([OWSGenericAttachmentView topLabelFont].lineHeight + + [OWSGenericAttachmentView bottomLabelFont].lineHeight + [OWSGenericAttachmentView labelVSpacing]); + CGFloat contentHeight = MAX(iconHeight, labelsHeight); + return contentHeight + self.vMargin * 2; } - (CGFloat)bubbleHeight @@ -100,10 +104,9 @@ NS_ASSUME_NONNULL_BEGIN { UIColor *textColor = (self.isIncoming ? [UIColor colorWithWhite:0.2 alpha:1.f] : [UIColor whiteColor]); - self.layoutMargins = UIEdgeInsetsZero; self.axis = UILayoutConstraintAxisHorizontal; self.alignment = UIStackViewAlignmentCenter; - self.spacing = self.iconHSpacing; + self.spacing = self.hSpacing; // attachment_file UIImage *image = [UIImage imageNamed:@"generic-attachment"]; @@ -117,7 +120,7 @@ NS_ASSUME_NONNULL_BEGIN UIStackView *labelsView = [UIStackView new]; labelsView.axis = UILayoutConstraintAxisVertical; - labelsView.spacing = 2; + labelsView.spacing = [OWSGenericAttachmentView labelVSpacing]; labelsView.alignment = UIStackViewAlignmentLeading; [self addArrangedSubview:labelsView]; @@ -132,7 +135,7 @@ NS_ASSUME_NONNULL_BEGIN topLabel.text = topText; topLabel.textColor = textColor; topLabel.lineBreakMode = NSLineBreakByTruncatingMiddle; - topLabel.font = [UIFont ows_regularFontWithSize:ScaleFromIPhone5To7Plus(13.f, 15.f)]; + topLabel.font = [OWSGenericAttachmentView bottomLabelFont]; [labelsView addArrangedSubview:topLabel]; NSError *error; @@ -144,10 +147,25 @@ NS_ASSUME_NONNULL_BEGIN bottomLabel.text = bottomText; bottomLabel.textColor = [textColor colorWithAlphaComponent:0.85f]; bottomLabel.lineBreakMode = NSLineBreakByTruncatingMiddle; - bottomLabel.font = [UIFont ows_regularFontWithSize:ScaleFromIPhone5To7Plus(11.f, 13.f)]; + bottomLabel.font = [OWSGenericAttachmentView bottomLabelFont]; [labelsView addArrangedSubview:bottomLabel]; } ++ (UIFont *)topLabelFont +{ + return [UIFont ows_regularFontWithSize:ScaleFromIPhone5To7Plus(13.f, 15.f)]; +} + ++ (UIFont *)bottomLabelFont +{ + return [UIFont ows_regularFontWithSize:ScaleFromIPhone5To7Plus(11.f, 13.f)]; +} + ++ (CGFloat)labelVSpacing +{ + return 2.f; +} + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m index 31c0d62d9..9116fd033 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m @@ -425,31 +425,14 @@ NS_ASSUME_NONNULL_BEGIN ]]; }]; - [self updateBubbleColorWithBodyMediaView:bodyMediaView]; + [self updateBubbleColor]; [self logFrameLaterWithLabel:@"----- message bubble"]; } -- (void)updateBubbleColorWithBodyMediaView:(nullable UIView *)bodyMediaView +- (void)updateBubbleColor { - OWSAssert([self.viewItem.interaction isKindOfClass:[TSMessage class]]); - - BOOL hasOnlyBodyMediaView = NO; - switch (self.cellType) { - case OWSMessageCellType_Unknown: - case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: - case OWSMessageCellType_GenericAttachment: - case OWSMessageCellType_DownloadingAttachment: - case OWSMessageCellType_ContactShare: - break; - case OWSMessageCellType_StillImage: - case OWSMessageCellType_AnimatedImage: - case OWSMessageCellType_Audio: - case OWSMessageCellType_Video: - hasOnlyBodyMediaView = (bodyMediaView && self.stackView.subviews.count == 1); - break; - } + BOOL hasOnlyBodyMediaView = ([self hasBodyMediaWithThumbnail] && self.stackView.subviews.count == 1); if (!hasOnlyBodyMediaView) { self.bubbleView.bubbleColor = self.bubbleColor; } else {