From 00d972db4891678de1afeef57474c9f612f3d985 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 12 May 2017 16:04:56 -0400 Subject: [PATCH] Rework appearance of audio and generic attachment messages. // FREEBIE --- .../TSGenericAttachmentAdapter.m | 54 +++++++++++++++---- .../TSVideoAttachmentAdapter.m | 10 +++- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/Signal/src/Models/TSMessageAdapaters/TSGenericAttachmentAdapter.m b/Signal/src/Models/TSMessageAdapaters/TSGenericAttachmentAdapter.m index ceb93e3b1..b7a5a5450 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSGenericAttachmentAdapter.m +++ b/Signal/src/Models/TSMessageAdapaters/TSGenericAttachmentAdapter.m @@ -77,19 +77,24 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - JSQMessageMediaData protocol -- (CGFloat)audioIconHMargin +- (CGFloat)iconHMargin +{ + return 12.f; +} + +- (CGFloat)iconHSpacing { return 10.f; } -- (CGFloat)audioIconVMargin +- (CGFloat)iconVMargin { return 12.f; } - (CGFloat)bubbleHeight { - return self.iconSize + self.audioIconVMargin * 2; + return self.iconSize + self.iconVMargin * 2; } - (CGFloat)iconSize @@ -107,14 +112,14 @@ NS_ASSUME_NONNULL_BEGIN return self.incoming ? [UIColor jsq_messageBubbleLightGrayColor] : [UIColor ows_materialBlueColor]; } -- (UIColor *)audioTextColor +- (UIColor *)textColor { return (self.incoming ? [UIColor colorWithWhite:0.2f alpha:1.f] : [UIColor whiteColor]); } -- (UIColor *)audioColorWithOpacity:(CGFloat)alpha +- (UIColor *)foregroundColorWithOpacity:(CGFloat)alpha { - return [self.audioTextColor blendWithColor:self.bubbleBackgroundColor alpha:alpha]; + return [self.textColor blendWithColor:self.bubbleBackgroundColor alpha:alpha]; } - (UIView *)mediaView @@ -132,13 +137,13 @@ NS_ASSUME_NONNULL_BEGIN const CGFloat kBubbleTailWidth = 6.f; CGRect contentFrame = CGRectMake(self.incoming ? kBubbleTailWidth : 0.f, self.vMargin, - viewSize.width - kBubbleTailWidth - 15, + viewSize.width - kBubbleTailWidth - self.iconHMargin, viewSize.height - self.vMargin * 2); UIImage *image = [UIImage imageNamed:@"generic-attachment-small"]; OWSAssert(image); UIImageView *imageView = [UIImageView new]; - CGRect iconFrame = CGRectMake(round(contentFrame.origin.x + self.audioIconHMargin), + CGRect iconFrame = CGRectMake(round(contentFrame.origin.x + self.iconHMargin), round(contentFrame.origin.y + (contentFrame.size.height - self.iconSize) * 0.5f), self.iconSize, self.iconSize); @@ -146,12 +151,39 @@ NS_ASSUME_NONNULL_BEGIN imageView.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; imageView.tintColor = self.bubbleBackgroundColor; imageView.backgroundColor - = (self.incoming ? [UIColor colorWithRGBHex:0x9e9e9e] : [self audioColorWithOpacity:0.15f]); + = (self.incoming ? [UIColor colorWithRGBHex:0x9e9e9e] : [self foregroundColorWithOpacity:0.15f]); imageView.layer.cornerRadius = MIN(imageView.bounds.size.width, imageView.bounds.size.height) * 0.5f; - [_cachedMediaView addSubview:imageView]; - const CGFloat kLabelHSpacing = self.audioIconHMargin; + NSString *fileExtension = self.attachment.filePath.pathExtension; + if (fileExtension.length < 1) { + [MIMETypeUtil fileExtensionForMIMEType:self.attachment.contentType]; + } + if (fileExtension.length < 1) { + fileExtension = NSLocalizedString(@"GENERIC_ATTACHMENT_DEFAULT_TYPE", + @"A default label for attachment whose file extension cannot be determined."); + } + + UILabel *fileTypeLabel = [UILabel new]; + fileTypeLabel.text = fileExtension.uppercaseString; + fileTypeLabel.textColor = imageView.backgroundColor; + fileTypeLabel.lineBreakMode = NSLineBreakByTruncatingTail; + fileTypeLabel.font = [UIFont ows_mediumFontWithSize:20.f]; + fileTypeLabel.adjustsFontSizeToFitWidth = YES; + fileTypeLabel.textAlignment = NSTextAlignmentCenter; + CGRect fileTypeLabelFrame = CGRectZero; + fileTypeLabelFrame.size = [fileTypeLabel sizeThatFits:CGSizeZero]; + // This dimension depends on the space within the icon boundaries. + fileTypeLabelFrame.size.width = 15.f; + // Center on icon. + fileTypeLabelFrame.origin.x + = round(iconFrame.origin.x + (iconFrame.size.width - fileTypeLabelFrame.size.width) * 0.5f); + fileTypeLabelFrame.origin.y + = round(iconFrame.origin.y + (iconFrame.size.height - fileTypeLabelFrame.size.height) * 0.5f); + fileTypeLabel.frame = fileTypeLabelFrame; + [_cachedMediaView addSubview:fileTypeLabel]; + + const CGFloat kLabelHSpacing = self.iconHSpacing; const CGFloat kLabelVSpacing = 2; NSString *topText = [self.attachment.filename stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; diff --git a/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m b/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m index a1aa8b6fb..64bc837e7 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m +++ b/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m @@ -157,6 +157,11 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - JSQMessageMediaData protocol - (CGFloat)audioIconHMargin +{ + return 12.f; +} + +- (CGFloat)audioIconHSpacing { return 10.f; } @@ -269,7 +274,7 @@ NS_ASSUME_NONNULL_BEGIN const CGFloat kBubbleTailWidth = 6.f; CGRect contentFrame = CGRectMake(self.incoming ? kBubbleTailWidth : 0.f, self.audioIconVMargin, - viewSize.width - kBubbleTailWidth - 15, + viewSize.width - kBubbleTailWidth - self.audioIconHMargin, viewSize.height - self.audioIconVMargin * 2); CGRect iconFrame = CGRectMake((CGFloat)round(contentFrame.origin.x + self.audioIconHMargin), @@ -280,7 +285,7 @@ NS_ASSUME_NONNULL_BEGIN _audioPlayPauseButton.enabled = NO; [mediaView addSubview:_audioPlayPauseButton]; - const CGFloat kLabelHSpacing = self.audioIconHMargin; + const CGFloat kLabelHSpacing = self.audioIconHSpacing; const CGFloat kLabelVSpacing = 2; NSString *topText = [[self.attachment.filename stringByDeletingPathExtension] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; @@ -363,6 +368,7 @@ NS_ASSUME_NONNULL_BEGIN 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]; }