diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m index e9d74a2f3..59f8f1f33 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m @@ -889,26 +889,13 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssert(self.attachmentPointer); - UIView *customView = [UIView new]; - switch (self.attachmentPointer.state) { - case TSAttachmentPointerStateEnqueued: - customView.backgroundColor - = (self.isIncoming ? [UIColor ows_messageBubbleLightGrayColor] : [UIColor ows_fadedBlueColor]); - break; - case TSAttachmentPointerStateDownloading: - customView.backgroundColor - = (self.isIncoming ? [UIColor ows_messageBubbleLightGrayColor] : [UIColor ows_fadedBlueColor]); - break; - case TSAttachmentPointerStateFailed: - customView.backgroundColor = [UIColor grayColor]; - break; - } - - AttachmentPointerView *attachmentPointerView = + AttachmentPointerView *downloadView = [[AttachmentPointerView alloc] initWithAttachmentPointer:self.attachmentPointer isIncoming:self.isIncoming]; - [customView addSubview:attachmentPointerView]; - [attachmentPointerView autoPinWidthToSuperviewWithMargin:20.f]; - [attachmentPointerView autoVCenterInSuperview]; + + UIView *wrapper = [UIView new]; + [wrapper addSubview:downloadView]; + [downloadView autoPinWidthToSuperview]; + [downloadView autoVCenterInSuperview]; self.loadCellContentBlock = ^{ // Do nothing. @@ -917,7 +904,7 @@ NS_ASSUME_NONNULL_BEGIN // Do nothing. }; - return customView; + return wrapper; } - (UIView *)loadViewForContactShare @@ -1058,7 +1045,7 @@ NS_ASSUME_NONNULL_BEGIN result = CGSizeMake(maxMessageWidth, [OWSGenericAttachmentView bubbleHeight]); break; case OWSMessageCellType_DownloadingAttachment: - result = CGSizeMake(200, 90); + result = CGSizeMake(200, [AttachmentPointerView measureHeight]); break; case OWSMessageCellType_ContactShare: OWSAssert(self.viewItem.contactShare); diff --git a/Signal/src/views/AttachmentPointerView.swift b/Signal/src/views/AttachmentPointerView.swift index 03b369356..75e3abc97 100644 --- a/Signal/src/views/AttachmentPointerView.swift +++ b/Signal/src/views/AttachmentPointerView.swift @@ -6,7 +6,7 @@ import Foundation import SignalServiceKit import SignalMessaging -class AttachmentPointerView: UIView { +class AttachmentPointerView: UIStackView { let TAG = "[AttachmentPointerView]" @@ -72,77 +72,37 @@ class AttachmentPointerView: UIView { self.progress = CGFloat(progress.floatValue) } - @available(*, unavailable) - override init(frame: CGRect) { - owsFail("invalid constructor") - // This initializer should never be called, but we assign some bogus values to keep the compiler happy. - self.filename = genericFilename - self.isIncoming = false - self.attachmentPointer = TSAttachmentPointer() - super.init(frame: frame) - self.createSubviews() - self.updateViews() + @available(*, unavailable, message: "use init(call:) constructor instead.") + required init(coder aDecoder: NSCoder) { + fatalError("Unimplemented") } - @available(*, unavailable) - required init?(coder aDecoder: NSCoder) { - owsFail("Invalid constructor") - - // This initializer should never be called, but we assign some bogus values to keep the compiler happy. - self.filename = genericFilename - self.isIncoming = false - self.attachmentPointer = TSAttachmentPointer() - super.init(coder: aDecoder) - self.createSubviews() - self.updateViews() - } + private static var vSpacing: CGFloat = 5 + private static var nameFont = UIFont.ows_dynamicTypeBody + private static var statusFont = UIFont.ows_dynamicTypeCaption1 func createSubviews() { - self.addSubview(nameLabel) // truncate middle to be sure we include file extension nameLabel.lineBreakMode = .byTruncatingMiddle nameLabel.textAlignment = .center - nameLabel.textColor = self.textColor - nameLabel.font = UIFont.ows_dynamicTypeBody - - nameLabel.autoPinWidthToSuperview() - nameLabel.autoPinEdge(toSuperviewEdge: .top) + nameLabel.font = AttachmentPointerView.nameFont - self.addSubview(progressView) - progressView.autoPinWidthToSuperview() - progressView.autoPinEdge(.top, to: .bottom, of: nameLabel, withOffset: 6) - - self.addSubview(statusLabel) statusLabel.textAlignment = .center statusLabel.adjustsFontSizeToFitWidth = true statusLabel.numberOfLines = 2 - statusLabel.textColor = self.textColor - statusLabel.font = UIFont.ows_regularFont(withSize: 11.0) - - statusLabel.autoPinWidthToSuperview() - statusLabel.autoPinEdge(.top, to: .bottom, of: progressView, withOffset: 4) - statusLabel.autoPinEdge(toSuperviewEdge: .bottom) - } + statusLabel.font = AttachmentPointerView.statusFont - func emojiForContentType(_ contentType: String) -> String { - if MIMETypeUtil.isImage(contentType) { - return "📷" - } else if MIMETypeUtil.isVideo(contentType) { - return "📽" - } else if MIMETypeUtil.isAudio(contentType) { - return "📻" - } else if MIMETypeUtil.isAnimated(contentType) { - return "🎡" - } else { - // generic file - return "📁" - } + self.axis = .vertical + self.spacing = AttachmentPointerView.vSpacing + addArrangedSubview(nameLabel) + addArrangedSubview(progressView) + addArrangedSubview(statusLabel) } func updateViews() { - let emoji = self.emojiForContentType(self.attachmentPointer.contentType) + let emoji = TSAttachment.emoji(forMimeType: self.attachmentPointer.contentType) nameLabel.text = "\(emoji) \(self.filename)" statusLabel.text = { @@ -168,4 +128,12 @@ class AttachmentPointerView: UIView { var textColor: UIColor { return self.isIncoming ? UIColor.darkText : UIColor.white } + + @objc + public class func measureHeight() -> CGFloat { + return ceil(nameFont.lineHeight + + statusFont.lineHeight + + OWSProgressView.defaultSize().height + + vSpacing * 2) + } } diff --git a/Signal/src/views/OWSProgressView.h b/Signal/src/views/OWSProgressView.h index 768a8a942..3206f13bf 100644 --- a/Signal/src/views/OWSProgressView.h +++ b/Signal/src/views/OWSProgressView.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import @@ -11,6 +11,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) UIColor *color; @property (nonatomic) CGFloat progress; ++ (CGSize)defaultSize; + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/views/OWSProgressView.m b/Signal/src/views/OWSProgressView.m index f64385607..91bafe456 100644 --- a/Signal/src/views/OWSProgressView.m +++ b/Signal/src/views/OWSProgressView.m @@ -121,11 +121,16 @@ NS_ASSUME_NONNULL_BEGIN [CATransaction commit]; } -- (CGSize)sizeThatFits:(CGSize)size ++ (CGSize)defaultSize { return CGSizeMake(150, 16); } +- (CGSize)sizeThatFits:(CGSize)size +{ + return OWSProgressView.defaultSize; +} + - (CGSize)intrinsicContentSize { return CGSizeMake(UIViewNoIntrinsicMetric, 16);