From 520819b248c813cc34874d176faf18931d2a3cf5 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 29 Jun 2018 10:25:36 -0400 Subject: [PATCH] Show generic attachment extension. --- .../Cells/OWSGenericAttachmentView.m | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m index 80144480d..2944fce70 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m @@ -119,6 +119,31 @@ NS_ASSUME_NONNULL_BEGIN [self addArrangedSubview:imageView]; [imageView setContentHuggingHigh]; + NSString *filename = self.attachmentStream.sourceFilename; + if (!filename) { + filename = [[self.attachmentStream filePath] lastPathComponent]; + } + NSString *fileExtension = filename.pathExtension; + if (fileExtension.length < 1) { + [MIMETypeUtil fileExtensionForMIMEType:self.attachmentStream.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 = UIColor.ows_light90Color; + fileTypeLabel.lineBreakMode = NSLineBreakByTruncatingTail; + fileTypeLabel.font = [UIFont ows_dynamicTypeCaption1Font].ows_mediumWeight; + fileTypeLabel.adjustsFontSizeToFitWidth = YES; + fileTypeLabel.textAlignment = NSTextAlignmentCenter; + // Center on icon. + [imageView addSubview:fileTypeLabel]; + [fileTypeLabel autoCenterInSuperview]; + [fileTypeLabel autoSetDimension:ALDimensionWidth toSize:self.iconWidth - 20.f]; + UIStackView *labelsView = [UIStackView new]; labelsView.axis = UILayoutConstraintAxisVertical; labelsView.spacing = [OWSGenericAttachmentView labelVSpacing];