Tweak attachment download view.

pull/1/head
Matthew Chen 7 years ago
parent 296c7c286c
commit 3d5cff1ed0

@ -889,26 +889,13 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssert(self.attachmentPointer); OWSAssert(self.attachmentPointer);
UIView *customView = [UIView new]; AttachmentPointerView *downloadView =
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 alloc] initWithAttachmentPointer:self.attachmentPointer isIncoming:self.isIncoming]; [[AttachmentPointerView alloc] initWithAttachmentPointer:self.attachmentPointer isIncoming:self.isIncoming];
[customView addSubview:attachmentPointerView];
[attachmentPointerView autoPinWidthToSuperviewWithMargin:20.f]; UIView *wrapper = [UIView new];
[attachmentPointerView autoVCenterInSuperview]; [wrapper addSubview:downloadView];
[downloadView autoPinWidthToSuperview];
[downloadView autoVCenterInSuperview];
self.loadCellContentBlock = ^{ self.loadCellContentBlock = ^{
// Do nothing. // Do nothing.
@ -917,7 +904,7 @@ NS_ASSUME_NONNULL_BEGIN
// Do nothing. // Do nothing.
}; };
return customView; return wrapper;
} }
- (UIView *)loadViewForContactShare - (UIView *)loadViewForContactShare
@ -1058,7 +1045,7 @@ NS_ASSUME_NONNULL_BEGIN
result = CGSizeMake(maxMessageWidth, [OWSGenericAttachmentView bubbleHeight]); result = CGSizeMake(maxMessageWidth, [OWSGenericAttachmentView bubbleHeight]);
break; break;
case OWSMessageCellType_DownloadingAttachment: case OWSMessageCellType_DownloadingAttachment:
result = CGSizeMake(200, 90); result = CGSizeMake(200, [AttachmentPointerView measureHeight]);
break; break;
case OWSMessageCellType_ContactShare: case OWSMessageCellType_ContactShare:
OWSAssert(self.viewItem.contactShare); OWSAssert(self.viewItem.contactShare);

@ -6,7 +6,7 @@ import Foundation
import SignalServiceKit import SignalServiceKit
import SignalMessaging import SignalMessaging
class AttachmentPointerView: UIView { class AttachmentPointerView: UIStackView {
let TAG = "[AttachmentPointerView]" let TAG = "[AttachmentPointerView]"
@ -72,77 +72,37 @@ class AttachmentPointerView: UIView {
self.progress = CGFloat(progress.floatValue) self.progress = CGFloat(progress.floatValue)
} }
@available(*, unavailable) @available(*, unavailable, message: "use init(call:) constructor instead.")
override init(frame: CGRect) { required init(coder aDecoder: NSCoder) {
owsFail("invalid constructor") fatalError("Unimplemented")
// 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) private static var vSpacing: CGFloat = 5
required init?(coder aDecoder: NSCoder) { private static var nameFont = UIFont.ows_dynamicTypeBody
owsFail("Invalid constructor") private static var statusFont = UIFont.ows_dynamicTypeCaption1
// 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()
}
func createSubviews() { func createSubviews() {
self.addSubview(nameLabel)
// truncate middle to be sure we include file extension // truncate middle to be sure we include file extension
nameLabel.lineBreakMode = .byTruncatingMiddle nameLabel.lineBreakMode = .byTruncatingMiddle
nameLabel.textAlignment = .center nameLabel.textAlignment = .center
nameLabel.textColor = self.textColor nameLabel.textColor = self.textColor
nameLabel.font = UIFont.ows_dynamicTypeBody nameLabel.font = AttachmentPointerView.nameFont
nameLabel.autoPinWidthToSuperview()
nameLabel.autoPinEdge(toSuperviewEdge: .top)
self.addSubview(progressView)
progressView.autoPinWidthToSuperview()
progressView.autoPinEdge(.top, to: .bottom, of: nameLabel, withOffset: 6)
self.addSubview(statusLabel)
statusLabel.textAlignment = .center statusLabel.textAlignment = .center
statusLabel.adjustsFontSizeToFitWidth = true statusLabel.adjustsFontSizeToFitWidth = true
statusLabel.numberOfLines = 2 statusLabel.numberOfLines = 2
statusLabel.textColor = self.textColor statusLabel.textColor = self.textColor
statusLabel.font = UIFont.ows_regularFont(withSize: 11.0) statusLabel.font = AttachmentPointerView.statusFont
statusLabel.autoPinWidthToSuperview() self.axis = .vertical
statusLabel.autoPinEdge(.top, to: .bottom, of: progressView, withOffset: 4) self.spacing = AttachmentPointerView.vSpacing
statusLabel.autoPinEdge(toSuperviewEdge: .bottom) addArrangedSubview(nameLabel)
} addArrangedSubview(progressView)
addArrangedSubview(statusLabel)
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 "📁"
}
} }
func updateViews() { func updateViews() {
let emoji = self.emojiForContentType(self.attachmentPointer.contentType) let emoji = TSAttachment.emoji(forMimeType: self.attachmentPointer.contentType)
nameLabel.text = "\(emoji) \(self.filename)" nameLabel.text = "\(emoji) \(self.filename)"
statusLabel.text = { statusLabel.text = {
@ -168,4 +128,12 @@ class AttachmentPointerView: UIView {
var textColor: UIColor { var textColor: UIColor {
return self.isIncoming ? UIColor.darkText : UIColor.white return self.isIncoming ? UIColor.darkText : UIColor.white
} }
@objc
public class func measureHeight() -> CGFloat {
return ceil(nameFont.lineHeight +
statusFont.lineHeight +
OWSProgressView.defaultSize().height +
vSpacing * 2)
}
} }

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@ -11,6 +11,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) UIColor *color; @property (nonatomic) UIColor *color;
@property (nonatomic) CGFloat progress; @property (nonatomic) CGFloat progress;
+ (CGSize)defaultSize;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -121,11 +121,16 @@ NS_ASSUME_NONNULL_BEGIN
[CATransaction commit]; [CATransaction commit];
} }
- (CGSize)sizeThatFits:(CGSize)size + (CGSize)defaultSize
{ {
return CGSizeMake(150, 16); return CGSizeMake(150, 16);
} }
- (CGSize)sizeThatFits:(CGSize)size
{
return OWSProgressView.defaultSize;
}
- (CGSize)intrinsicContentSize - (CGSize)intrinsicContentSize
{ {
return CGSizeMake(UIViewNoIntrinsicMetric, 16); return CGSizeMake(UIViewNoIntrinsicMetric, 16);

Loading…
Cancel
Save