From 7c3991ebd8bf8ffd886292e5d75981a9e1320b81 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 7 May 2018 09:47:22 -0400 Subject: [PATCH] Respond to CR. --- .../ApproveContactShareViewController.swift | 79 +++++++------------ .../EditContactShareNameViewController.swift | 17 ++-- .../src/Messages/Interactions/OWSContact.h | 36 ++++----- 3 files changed, 54 insertions(+), 78 deletions(-) diff --git a/SignalMessaging/attachments/ApproveContactShareViewController.swift b/SignalMessaging/attachments/ApproveContactShareViewController.swift index b99c396d8..5bddec249 100644 --- a/SignalMessaging/attachments/ApproveContactShareViewController.swift +++ b/SignalMessaging/attachments/ApproveContactShareViewController.swift @@ -11,14 +11,33 @@ public protocol ApproveContactShareViewControllerDelegate: class { func approveContactShare(_ approveContactShare: ApproveContactShareViewController, didCancelContactShare contactShare: OWSContact) } +protocol ContactShareField: class { + + func localizedLabel() -> String + + func isIncluded() -> Bool + + func setIsIncluded(_ isIncluded: Bool) + + func applyToContact(contact: OWSContact) +} + // MARK: - -class ContactShareField: NSObject { +class ContactShareFieldBase: NSObject, ContactShareField { + + let value: ContactFieldType private var isIncludedFlag = true + required init(_ value: ContactFieldType) { + self.value = value + + super.init() + } + func localizedLabel() -> String { - preconditionFailure("This method must be overridden") + return value.localizedLabel() } func isIncluded() -> Bool { @@ -36,19 +55,7 @@ class ContactShareField: NSObject { // MARK: - -class ContactSharePhoneNumber: ContactShareField { - - let value: OWSContactPhoneNumber - - required init(_ value: OWSContactPhoneNumber) { - self.value = value - - super.init() - } - - override func localizedLabel() -> String { - return value.localizedLabel() - } +class ContactSharePhoneNumber: ContactShareFieldBase { override func applyToContact(contact: OWSContact) { assert(isIncluded()) @@ -62,19 +69,7 @@ class ContactSharePhoneNumber: ContactShareField { // MARK: - -class ContactShareEmail: ContactShareField { - - let value: OWSContactEmail - - required init(_ value: OWSContactEmail) { - self.value = value - - super.init() - } - - override func localizedLabel() -> String { - return value.localizedLabel() - } +class ContactShareEmail: ContactShareFieldBase { override func applyToContact(contact: OWSContact) { assert(isIncluded()) @@ -88,19 +83,7 @@ class ContactShareEmail: ContactShareField { // MARK: - -class ContactShareAddress: ContactShareField { - - let value: OWSContactAddress - - required init(_ value: OWSContactAddress) { - self.value = value - - super.init() - } - - override func localizedLabel() -> String { - return value.localizedLabel() - } +class ContactShareAddress: ContactShareFieldBase { override func applyToContact(contact: OWSContact) { assert(isIncluded()) @@ -259,10 +242,6 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh self.fieldViews = fieldViews } - override public var canBecomeFirstResponder: Bool { - return true - } - // MARK: - View Lifecycle override public func viewWillAppear(_ animated: Bool) { @@ -289,7 +268,6 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh self.navigationItem.title = NSLocalizedString("CONTACT_SHARE_APPROVAL_VIEW_TITLE", comment: "Title for the 'Approve contact share' view.") - self.view.preservesSuperviewLayoutMargins = false self.view.backgroundColor = UIColor.white updateContent() @@ -340,10 +318,13 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh let fieldsView = createFieldsView() scrollView.addSubview(fieldsView) + // Use layoutMarginsGuide for views inside UIScrollView + // that should have same width as scroll view. fieldsView.autoPinLeadingToSuperviewMargin() fieldsView.autoPinTrailingToSuperviewMargin() fieldsView.autoPinEdge(toSuperviewEdge: .top) fieldsView.autoPinEdge(toSuperviewEdge: .bottom) + fieldsView.setContentHuggingHorizontalLow() } private func createFieldsView() -> UIView { @@ -374,10 +355,7 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh stackView.layoutMargins = .zero stackView.spacing = 10 row.addSubview(stackView) - stackView.autoPinLeadingToSuperviewMargin() - stackView.autoPinTrailingToSuperviewMargin() - stackView.autoPinTopToSuperviewMargin() - stackView.autoPinBottomToSuperviewMargin() + stackView.autoPinEdgesToSuperviewMargins() let nameLabel = UILabel() self.nameLabel = nameLabel @@ -386,7 +364,6 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh nameLabel.textColor = UIColor.ows_materialBlue nameLabel.lineBreakMode = .byTruncatingTail stackView.addArrangedSubview(nameLabel) - nameLabel.setContentHuggingHigh() let editNameLabel = UILabel() editNameLabel.text = NSLocalizedString("CONTACT_EDIT_NAME_BUTTON", comment: "Label for the 'edit name' button in the contact share approval view.") diff --git a/SignalMessaging/attachments/EditContactShareNameViewController.swift b/SignalMessaging/attachments/EditContactShareNameViewController.swift index da6ff149e..b943b60c9 100644 --- a/SignalMessaging/attachments/EditContactShareNameViewController.swift +++ b/SignalMessaging/attachments/EditContactShareNameViewController.swift @@ -52,10 +52,7 @@ class ContactNameFieldView: UIView { stackView.layoutMargins = .zero stackView.spacing = 10 self.addSubview(stackView) - stackView.autoPinTopToSuperviewMargin() - stackView.autoPinBottomToSuperviewMargin() - stackView.autoPinLeadingToSuperviewMargin() - stackView.autoPinTrailingToSuperviewMargin() + stackView.autoPinEdgesToSuperviewMargins() let nameLabel = UILabel() nameLabel.text = name @@ -291,13 +288,21 @@ public class EditContactShareNameViewController: OWSViewController, ContactNameF delegate.editContactShareNameView(self, didEditContactShare: modifiedContactShare) - self.navigationController?.popViewController(animated: true) + guard let navigationController = self.navigationController else { + owsFail("\(logTag) Missing navigationController.") + return + } + navigationController.popViewController(animated: true) } func didPressCancel() { Logger.info("\(logTag) \(#function)") - self.navigationController?.popViewController(animated: true) + guard let navigationController = self.navigationController else { + owsFail("\(logTag) Missing navigationController.") + return + } + navigationController.popViewController(animated: true) } // MARK: - ContactNameFieldViewDelegate diff --git a/SignalServiceKit/src/Messages/Interactions/OWSContact.h b/SignalServiceKit/src/Messages/Interactions/OWSContact.h index ecd8fc5d0..91f417634 100644 --- a/SignalServiceKit/src/Messages/Interactions/OWSContact.h +++ b/SignalServiceKit/src/Messages/Interactions/OWSContact.h @@ -24,13 +24,7 @@ typedef NS_ENUM(NSUInteger, OWSContactPhoneType) { NSString *NSStringForContactPhoneType(OWSContactPhoneType value); -@interface OWSContactPhoneNumber : MTLModel - -@property (nonatomic, readonly) OWSContactPhoneType phoneType; -// Applies in the OWSContactPhoneType_Custom case. -@property (nonatomic, readonly, nullable) NSString *label; - -@property (nonatomic, readonly) NSString *phoneNumber; +@protocol OWSContactField - (BOOL)ows_isValid; @@ -42,6 +36,18 @@ NSString *NSStringForContactPhoneType(OWSContactPhoneType value); #pragma mark - +@interface OWSContactPhoneNumber : MTLModel + +@property (nonatomic, readonly) OWSContactPhoneType phoneType; +// Applies in the OWSContactPhoneType_Custom case. +@property (nonatomic, readonly, nullable) NSString *label; + +@property (nonatomic, readonly) NSString *phoneNumber; + +@end + +#pragma mark - + typedef NS_ENUM(NSUInteger, OWSContactEmailType) { OWSContactEmailType_Home = 1, OWSContactEmailType_Mobile, @@ -51,7 +57,7 @@ typedef NS_ENUM(NSUInteger, OWSContactEmailType) { NSString *NSStringForContactEmailType(OWSContactEmailType value); -@interface OWSContactEmail : MTLModel +@interface OWSContactEmail : MTLModel @property (nonatomic, readonly) OWSContactEmailType emailType; // Applies in the OWSContactEmailType_Custom case. @@ -59,12 +65,6 @@ NSString *NSStringForContactEmailType(OWSContactEmailType value); @property (nonatomic, readonly) NSString *email; -- (BOOL)ows_isValid; - -- (NSString *)localizedLabel; - -- (NSString *)debugDescription; - @end #pragma mark - @@ -77,7 +77,7 @@ typedef NS_ENUM(NSUInteger, OWSContactAddressType) { NSString *NSStringForContactAddressType(OWSContactAddressType value); -@interface OWSContactAddress : MTLModel +@interface OWSContactAddress : MTLModel @property (nonatomic, readonly) OWSContactAddressType addressType; // Applies in the OWSContactAddressType_Custom case. @@ -91,12 +91,6 @@ NSString *NSStringForContactAddressType(OWSContactAddressType value); @property (nonatomic, readonly, nullable) NSString *postcode; @property (nonatomic, readonly, nullable) NSString *country; -- (BOOL)ows_isValid; - -- (NSString *)localizedLabel; - -- (NSString *)debugDescription; - @end #pragma mark -