Merge branch 'mkirk/quote-authoring-redesign'

pull/1/head
Michael Kirk 7 years ago
commit 149d89224f

@ -29,6 +29,7 @@
#import "OWSMessageCell.h" #import "OWSMessageCell.h"
#import "OWSNavigationController.h" #import "OWSNavigationController.h"
#import "OWSProgressView.h" #import "OWSProgressView.h"
#import "OWSQuotedMessageView.h"
#import "OWSWebRTCDataProtos.pb.h" #import "OWSWebRTCDataProtos.pb.h"
#import "PinEntryView.h" #import "PinEntryView.h"
#import "PrivacySettingsTableViewController.h" #import "PrivacySettingsTableViewController.h"

@ -23,6 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable, readonly) DisplayableText *displayableQuotedText; @property (nonatomic, nullable, readonly) DisplayableText *displayableQuotedText;
@property (nonatomic, nullable) OWSBubbleStrokeView *boundsStrokeView; @property (nonatomic, nullable) OWSBubbleStrokeView *boundsStrokeView;
@property (nonatomic, readonly) BOOL isForPreview;
@end @end
@ -35,8 +36,9 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssert(quotedMessage); OWSAssert(quotedMessage);
return return [[OWSQuotedMessageView alloc] initWithQuotedMessage:quotedMessage
[[OWSQuotedMessageView alloc] initWithQuotedMessage:quotedMessage displayableQuotedText:displayableQuotedText]; displayableQuotedText:displayableQuotedText
isForPreview:NO];
} }
+ (OWSQuotedMessageView *)quotedMessageViewForPreview:(OWSQuotedReplyModel *)quotedMessage + (OWSQuotedMessageView *)quotedMessageViewForPreview:(OWSQuotedReplyModel *)quotedMessage
@ -48,12 +50,14 @@ NS_ASSUME_NONNULL_BEGIN
displayableQuotedText = [DisplayableText displayableText:quotedMessage.body]; displayableQuotedText = [DisplayableText displayableText:quotedMessage.body];
} }
return return [[OWSQuotedMessageView alloc] initWithQuotedMessage:quotedMessage
[[OWSQuotedMessageView alloc] initWithQuotedMessage:quotedMessage displayableQuotedText:displayableQuotedText]; displayableQuotedText:displayableQuotedText
isForPreview:YES];
} }
- (instancetype)initWithQuotedMessage:(OWSQuotedReplyModel *)quotedMessage - (instancetype)initWithQuotedMessage:(OWSQuotedReplyModel *)quotedMessage
displayableQuotedText:(nullable DisplayableText *)displayableQuotedText displayableQuotedText:(nullable DisplayableText *)displayableQuotedText
isForPreview:(BOOL)isForPreview
{ {
self = [super init]; self = [super init];
@ -65,6 +69,9 @@ NS_ASSUME_NONNULL_BEGIN
_quotedMessage = quotedMessage; _quotedMessage = quotedMessage;
_displayableQuotedText = displayableQuotedText; _displayableQuotedText = displayableQuotedText;
_isForPreview = isForPreview;
[self createContents];
return self; return self;
} }
@ -258,7 +265,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
UILabel *quotedTextLabel = [UILabel new]; UILabel *quotedTextLabel = [UILabel new];
quotedTextLabel.numberOfLines = 3; quotedTextLabel.numberOfLines = self.isForPreview ? 1 : 3;
quotedTextLabel.lineBreakMode = NSLineBreakByWordWrapping; quotedTextLabel.lineBreakMode = NSLineBreakByWordWrapping;
quotedTextLabel.text = text; quotedTextLabel.text = text;
quotedTextLabel.textColor = textColor; quotedTextLabel.textColor = textColor;

@ -13,108 +13,71 @@ protocol QuotedReplyPreviewDelegate: class {
class QuotedReplyPreview: UIView { class QuotedReplyPreview: UIView {
public weak var delegate: QuotedReplyPreviewDelegate? public weak var delegate: QuotedReplyPreviewDelegate?
private let quotedReply: OWSQuotedReplyModel
private var quotedMessageView: OWSQuotedMessageView
private var heightConstraint: NSLayoutConstraint!
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
init(quotedReply: OWSQuotedReplyModel) { init(quotedReply: OWSQuotedReplyModel) {
super.init(frame: .zero) self.quotedReply = quotedReply
self.quotedMessageView = OWSQuotedMessageView(forPreview: quotedReply)
let isQuotingSelf = quotedReply.authorId == TSAccountManager.localNumber() super.init(frame: .zero)
// used for stripe and author self.heightConstraint = self.autoSetDimension(.height, toSize: 0)
// FIXME actual colors TBD
let authorColor: UIColor = isQuotingSelf ? .ows_materialBlue : .black
// used for text and cancel updateContents()
let foregroundColor: UIColor = .darkGray
let authorLabel: UILabel = UILabel() NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: .UIContentSizeCategoryDidChange, object: nil)
authorLabel.textColor = authorColor
if isQuotingSelf {
authorLabel.text = NSLocalizedString("MEDIA_GALLERY_SENDER_NAME_YOU", comment: "")
} else {
authorLabel.text = Environment.current().contactsManager.displayName(forPhoneIdentifier: quotedReply.authorId)
} }
authorLabel.font = .ows_dynamicTypeHeadline
let bodyLabel: UILabel = UILabel()
bodyLabel.textColor = foregroundColor
bodyLabel.font = .ows_dynamicTypeFootnote
bodyLabel.text = {
if let contentType = quotedReply.contentType {
let emoji = TSAttachmentStream.emoji(forMimeType: contentType)
return "\(emoji) \(quotedReply.body ?? "")"
} else {
return quotedReply.body
}
}()
let thumbnailView: UIView? = { func updateContents() {
if let image = quotedReply.thumbnailImage { subviews.forEach { $0.removeFromSuperview() }
let imageView = UIImageView(image: image) self.quotedMessageView = OWSQuotedMessageView(forPreview: quotedReply)
imageView.contentMode = .scaleAspectFill
imageView.autoPinToSquareAspectRatio()
imageView.layer.cornerRadius = 3.0
imageView.clipsToBounds = true
return imageView quotedMessageView.backgroundColor = .clear
}
return nil
}()
let cancelButton: UIButton = UIButton(type: .custom) let cancelButton: UIButton = UIButton(type: .custom)
// FIXME proper image asset/size
let buttonImage: UIImage = #imageLiteral(resourceName: "quoted-message-cancel").withRenderingMode(.alwaysTemplate) let buttonImage: UIImage = #imageLiteral(resourceName: "quoted-message-cancel").withRenderingMode(.alwaysTemplate)
cancelButton.setImage(buttonImage, for: .normal) cancelButton.setImage(buttonImage, for: .normal)
cancelButton.imageView?.tintColor = foregroundColor cancelButton.imageView?.tintColor = .darkGray
cancelButton.addTarget(self, action: #selector(didTapCancel), for: .touchUpInside) cancelButton.addTarget(self, action: #selector(didTapCancel), for: .touchUpInside)
let quoteStripe: UIView = UIView() self.layoutMargins = .zero
quoteStripe.backgroundColor = authorColor
let textColumn = UIView.container()
textColumn.addSubview(authorLabel)
textColumn.addSubview(bodyLabel)
authorLabel.autoPinEdges(toSuperviewMarginsExcludingEdge: .bottom)
authorLabel.autoPinEdge(.bottom, to: .top, of: bodyLabel)
bodyLabel.autoPinEdges(toSuperviewMarginsExcludingEdge: .top)
let contentViews: [UIView] = [textColumn, thumbnailView, cancelButton].flatMap { return $0 }
let contentRow = UIStackView(arrangedSubviews: contentViews)
contentRow.axis = .horizontal
self.addSubview(contentRow)
self.addSubview(quoteStripe)
// Layout
let kQuoteStripeWidth: CGFloat = 4 self.addSubview(quotedMessageView)
self.layoutMargins = UIEdgeInsets(top: 6, self.addSubview(cancelButton)
left: kQuoteStripeWidth + 8,
bottom: 2,
right: 4)
quoteStripe.autoPinEdge(toSuperviewEdge: .leading) quotedMessageView.autoPinEdges(toSuperviewMarginsExcludingEdge: .trailing)
quoteStripe.autoPinHeightToSuperview() cancelButton.autoPinEdges(toSuperviewMarginsExcludingEdge: .leading)
quoteStripe.autoSetDimension(.width, toSize: kQuoteStripeWidth) cancelButton.autoPinEdge(.leading, to: .trailing, of: quotedMessageView)
contentRow.autoPinEdgesToSuperviewMargins()
cancelButton.autoSetDimensions(to: CGSize(width: 40, height: 40)) cancelButton.autoSetDimensions(to: CGSize(width: 40, height: 40))
}
// MARK: UIViewOverrides
// Used by stack view to determin size. updateHeight()
override var intrinsicContentSize: CGSize {
return CGSize(width: 0, height: 30)
} }
// MARK: Actions // MARK: Actions
@objc @objc
func didTapCancel(_ sender: Any) { func didTapCancel(_ sender: Any) {
self.delegate?.quotedReplyPreviewDidPressCancel(self) self.delegate?.quotedReplyPreviewDidPressCancel(self)
} }
// MARK: Sizing
func updateHeight() {
let size = self.quotedMessageView.size(forMaxWidth: CGFloat.infinity)
self.heightConstraint.constant = size.height
}
func contentSizeCategoryDidChange(_ notification: Notification) {
Logger.debug("\(self.logTag) in \(#function)")
updateContents()
}
} }

Loading…
Cancel
Save