diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m index b106c30be..53e56335b 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m @@ -77,7 +77,7 @@ static const CGFloat ConversationInputToolbarBorderViewHeight = 0.5; { self.layoutMargins = UIEdgeInsetsZero; - self.backgroundColor = [UIColor ows_inputToolbarBackgroundColor]; + self.backgroundColor = [UIColor ows_toolbarBackgroundColor]; self.autoresizingMask = UIViewAutoresizingFlexibleHeight; UIView *borderView = [UIView new]; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index cac13441f..4ffc5f843 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -499,7 +499,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { { [super loadView]; - self.view.backgroundColor = [UIColor ows_inputToolbarBackgroundColor]; + self.view.backgroundColor = [UIColor ows_toolbarBackgroundColor]; } - (void)createContents diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 66896619e..ec955a8c9 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -916,6 +916,12 @@ /* media picker option to choose from library */ "MEDIA_FROM_LIBRARY_BUTTON" = "Photo Library"; +/* Title for the 'message approval' dialog. */ +"MESSAGE_APPROVAL_DIALOG_TITLE" = "Message"; + +/* Label for the recipient name in the 'message approval' dialog. */ +"MESSAGE_APPROVAL_RECIPIENT_LABEL" = "To:"; + /* No comment provided by engineer. */ "MESSAGE_COMPOSEVIEW_TITLE" = "New Message"; diff --git a/SignalMessaging/attachments/MessageApprovalViewController.swift b/SignalMessaging/attachments/MessageApprovalViewController.swift index 083196064..2ea1e9321 100644 --- a/SignalMessaging/attachments/MessageApprovalViewController.swift +++ b/SignalMessaging/attachments/MessageApprovalViewController.swift @@ -18,7 +18,9 @@ public class MessageApprovalViewController: OWSViewController, UITextViewDelegat // MARK: Properties + let thread: TSThread let initialMessageText: String + let contactsManager: OWSContactsManager private(set) var textView: UITextView! private(set) var topToolbar: UIToolbar! @@ -31,8 +33,10 @@ public class MessageApprovalViewController: OWSViewController, UITextViewDelegat } @objc - required public init(messageText: String, delegate: MessageApprovalViewControllerDelegate) { + required public init(messageText: String, thread: TSThread, contactsManager: OWSContactsManager, delegate: MessageApprovalViewControllerDelegate) { self.initialMessageText = messageText + self.thread = thread + self.contactsManager = contactsManager self.delegate = delegate super.init(nibName: nil, bundle: nil) @@ -70,18 +74,24 @@ public class MessageApprovalViewController: OWSViewController, UITextViewDelegat public override func loadView() { - self.view = UIView() + self.view = UIView.container() self.view.backgroundColor = UIColor.white // Top Toolbar topToolbar = UIToolbar() - topToolbar.backgroundColor = UIColor.ows_inputToolbarBackground + topToolbar.backgroundColor = UIColor.ows_toolbarBackground self.view.addSubview(topToolbar) topToolbar.autoPinWidthToSuperview() topToolbar.autoPin(toTopLayoutGuideOf: self, withInset: 0) topToolbar.setContentHuggingVerticalHigh() topToolbar.setCompressionResistanceVerticalHigh() + // Recipient Row + let recipientRow = createRecipientRow() + view.addSubview(recipientRow) + recipientRow.autoPinWidthToSuperview() + recipientRow.autoPinEdge(.top, to: .bottom, of: topToolbar) + // Text View textView = UITextView() textView.delegate = self @@ -89,14 +99,158 @@ public class MessageApprovalViewController: OWSViewController, UITextViewDelegat textView.textColor = UIColor.black textView.font = UIFont.ows_dynamicTypeBody() textView.text = self.initialMessageText + textView.textContainerInset = UIEdgeInsets(top:0.0, left:0.0, bottom:0.0, right:0.0) + textView.contentInset = UIEdgeInsets(top:10.0, left:10.0, bottom:10.0, right:10.0) view.addSubview(textView) textView.autoPinWidthToSuperview() - textView.autoPinEdge(.top, to: .bottom, of: topToolbar) + textView.autoPinEdge(.top, to: .bottom, of: recipientRow) textView.autoPin(toBottomLayoutGuideOf: self, withInset: 0) updateToolbar() } + private func createRecipientRow() -> UIView { + let recipientRow = UIView.container() + recipientRow.backgroundColor = UIColor.ows_toolbarBackground + recipientRow.autoSetDimension(.height, toSize: 40.0) + + // Hairline borders should be 1 pixel, not 1 point. + let borderThickness = 1.0 / UIScreen.main.scale + let borderColor = UIColor(white:135 / 255.0, alpha:1.0) + + let topBorder = UIView.container() + topBorder.backgroundColor = borderColor + recipientRow.addSubview(topBorder) + topBorder.autoPinWidthToSuperview() + topBorder.autoPinTopToSuperview() + topBorder.autoSetDimension(.height, toSize: borderThickness) + + let bottomBorder = UIView.container() + bottomBorder.backgroundColor = borderColor + recipientRow.addSubview(bottomBorder) + bottomBorder.autoPinWidthToSuperview() + bottomBorder.autoPinBottomToSuperview() + bottomBorder.autoSetDimension(.height, toSize: borderThickness) + + guard let font = UIFont.ows_regularFont(withSize:ScaleFromIPhone5To7Plus(14.0, 18.0)) else { + owsFail("Can't load font") + return recipientRow + } + let hSpacing = CGFloat(10) + let hMargin = CGFloat(15) + + let toLabel = UILabel() + toLabel.text = NSLocalizedString("MESSAGE_APPROVAL_RECIPIENT_LABEL", + comment: "Label for the recipient name in the 'message approval' dialog.") + toLabel.textColor = UIColor.ows_darkGray + toLabel.font = font + recipientRow.addSubview(toLabel) + toLabel.autoVCenterInSuperview() + toLabel.autoPinLeadingToSuperview(withMargin: hMargin) + toLabel.setContentHuggingHorizontalHigh() + toLabel.setCompressionResistanceHorizontalHigh() + + if let groupThread = self.thread as? TSGroupThread { + let groupName = (groupThread.name().count > 0 + ? groupThread.name() + : MessageStrings.newGroupDefaultTitle) + + let nameLabel = UILabel() + nameLabel.text = groupName + nameLabel.textColor = UIColor.black + nameLabel.font = font + nameLabel.lineBreakMode = .byTruncatingTail + recipientRow.addSubview(nameLabel) + nameLabel.autoVCenterInSuperview() + nameLabel.autoPinLeading(toTrailingOf: toLabel, margin:hSpacing) + nameLabel.autoPinTrailingToSuperview(withMargin: hMargin) + nameLabel.setContentHuggingHorizontalLow() + nameLabel.setCompressionResistanceHorizontalLow() + + return recipientRow + } + guard let contactThread = self.thread as? TSContactThread else { + owsFail("Unexpected thread type") + return recipientRow + } + +// let recipientLabel = UILabel() +// recipientLabel.text = NSLocalizedString("MESSAGE_APPROVAL_RECIPIENT_LABEL", +// comment: "Label for the recipient name in the 'message approval' dialog.") +// recipientLabel.textColor = UIColor.black +// recipientLabel.font = UIFont.ows_regularFont(withSize:ScaleFromIPhone5To7Plus(14.0, 18.0)) +// recipientLabel.lineBreakMode = .byTruncatingTail +// recipientRow.addSubview(recipientLabel) +// recipientLabel.autoVCenterInSuperview() +// recipientLabel.autoPinLeading(toTrailingOf: toLabel) +// recipientLabel.autoPinTrailingToSuperview(withMargin: 20.0) +// +// +// topToolbar.autoSetDimension(.height, toSize: 30.0) +// +// let toLabel = UILabel() +// toLabel.text = NSLocalizedString("MESSAGE_APPROVAL_RECIPIENT_LABEL", +// comment: "Label for the recipient name in the 'message approval' dialog.") +// toLabel.textColor = UIColor.ows_darkGray +// toLabel.font = UIFont.ows_regularFont(withSize:ScaleFromIPhone5To7Plus(14.0, 18.0)) +// recipientRow.addSubview(toLabel) +// toLabel.autoVCenterInSuperview() +// toLabel.autoPinLeadingToSuperview(withMargin: 20.0) +// + let recipientLabel = UILabel() + recipientLabel.textColor = UIColor.black + recipientLabel.font = font + recipientLabel.attributedText = contactsManager.formattedFullName(forRecipientId:contactThread.contactIdentifier(), font:font) + // self.nameLabel.attributedText = + // [contactsManager formattedFullNameForRecipientId:recipientId font:self.nameLabel.font]; + recipientLabel.lineBreakMode = .byTruncatingTail + recipientRow.addSubview(recipientLabel) + recipientLabel.autoVCenterInSuperview() + recipientLabel.autoPinLeading(toTrailingOf: toLabel, margin:hSpacing) + recipientLabel.autoPinTrailingToSuperview(withMargin: hMargin) + recipientLabel.setContentHuggingHorizontalLow() + recipientLabel.setCompressionResistanceHorizontalLow() + +// recipientLabel + + // - (void)configureWithRecipientId:(NSString *)recipientId contactsManager:(OWSContactsManager *)contactsManager + // { + // self.recipientId = recipientId; + // self.contactsManager = contactsManager; + // + // self.nameLabel.attributedText = + // [contactsManager formattedFullNameForRecipientId:recipientId font:self.nameLabel.font]; + // + // - (void)updateProfileName + // { + // OWSContactsManager *contactsManager = self.contactsManager; + // if (contactsManager == nil) { + // OWSFail(@"%@ contactsManager should not be nil", self.logTag); + // self.profileNameLabel.text = nil; + // return; + // } + // + // NSString *recipientId = self.recipientId; + // if (recipientId.length == 0) { + // OWSFail(@"%@ recipientId should not be nil", self.logTag); + // self.profileNameLabel.text = nil; + // return; + // } + // + // if ([contactsManager hasNameInSystemContactsForRecipientId:recipientId]) { + // // Don't display profile name when we have a veritas name in system Contacts + // self.profileNameLabel.text = nil; + // } else { + // // Use profile name, if any is available + // self.profileNameLabel.text = [contactsManager formattedProfileNameForRecipientId:recipientId]; + // } + // + // [self.profileNameLabel setNeedsLayout]; + // } + + return recipientRow + } + // MARK: - Event Handlers func cancelPressed(sender: UIButton) { diff --git a/SignalMessaging/attachments/SharingThreadPickerViewController.m b/SignalMessaging/attachments/SharingThreadPickerViewController.m index 258b3d7f1..97502999e 100644 --- a/SignalMessaging/attachments/SharingThreadPickerViewController.m +++ b/SignalMessaging/attachments/SharingThreadPickerViewController.m @@ -147,7 +147,10 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion); if (messageText) { MessageApprovalViewController *approvalVC = - [[MessageApprovalViewController alloc] initWithMessageText:messageText delegate:self]; + [[MessageApprovalViewController alloc] initWithMessageText:messageText + thread:thread + contactsManager:self.contactsManager + delegate:self]; [self.navigationController pushViewController:approvalVC animated:YES]; } else { diff --git a/SignalMessaging/categories/UIColor+OWS.h b/SignalMessaging/categories/UIColor+OWS.h index 1daeb73b6..7e3038a9b 100644 --- a/SignalMessaging/categories/UIColor+OWS.h +++ b/SignalMessaging/categories/UIColor+OWS.h @@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN @property (class, readonly, nonatomic) UIColor *ows_darkIconColor; @property (class, readonly, nonatomic) UIColor *ows_errorMessageBorderColor; @property (class, readonly, nonatomic) UIColor *ows_infoMessageBorderColor; -@property (class, readonly, nonatomic) UIColor *ows_inputToolbarBackgroundColor; +@property (class, readonly, nonatomic) UIColor *ows_toolbarBackgroundColor; + (UIColor *)backgroundColorForContact:(NSString *)contactIdentifier; + (UIColor *)colorWithRGBHex:(unsigned long)value; diff --git a/SignalMessaging/categories/UIColor+OWS.m b/SignalMessaging/categories/UIColor+OWS.m index 1fa45ec6f..12dbe9087 100644 --- a/SignalMessaging/categories/UIColor+OWS.m +++ b/SignalMessaging/categories/UIColor+OWS.m @@ -91,7 +91,7 @@ NS_ASSUME_NONNULL_BEGIN return [UIColor colorWithRed:239.f / 255.f green:189.f / 255.f blue:88.f / 255.f alpha:1.0f]; } -+ (UIColor *)ows_inputToolbarBackgroundColor ++ (UIColor *)ows_toolbarBackgroundColor { return [self colorWithWhite:245 / 255.f alpha:1.f]; }