Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent ba74e3857a
commit 7c3991ebd8

@ -11,14 +11,33 @@ public protocol ApproveContactShareViewControllerDelegate: class {
func approveContactShare(_ approveContactShare: ApproveContactShareViewController, didCancelContactShare contactShare: OWSContact) 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: - // MARK: -
class ContactShareField: NSObject { class ContactShareFieldBase<ContactFieldType: OWSContactField>: NSObject, ContactShareField {
let value: ContactFieldType
private var isIncludedFlag = true private var isIncludedFlag = true
required init(_ value: ContactFieldType) {
self.value = value
super.init()
}
func localizedLabel() -> String { func localizedLabel() -> String {
preconditionFailure("This method must be overridden") return value.localizedLabel()
} }
func isIncluded() -> Bool { func isIncluded() -> Bool {
@ -36,19 +55,7 @@ class ContactShareField: NSObject {
// MARK: - // MARK: -
class ContactSharePhoneNumber: ContactShareField { class ContactSharePhoneNumber: ContactShareFieldBase<OWSContactPhoneNumber> {
let value: OWSContactPhoneNumber
required init(_ value: OWSContactPhoneNumber) {
self.value = value
super.init()
}
override func localizedLabel() -> String {
return value.localizedLabel()
}
override func applyToContact(contact: OWSContact) { override func applyToContact(contact: OWSContact) {
assert(isIncluded()) assert(isIncluded())
@ -62,19 +69,7 @@ class ContactSharePhoneNumber: ContactShareField {
// MARK: - // MARK: -
class ContactShareEmail: ContactShareField { class ContactShareEmail: ContactShareFieldBase<OWSContactEmail> {
let value: OWSContactEmail
required init(_ value: OWSContactEmail) {
self.value = value
super.init()
}
override func localizedLabel() -> String {
return value.localizedLabel()
}
override func applyToContact(contact: OWSContact) { override func applyToContact(contact: OWSContact) {
assert(isIncluded()) assert(isIncluded())
@ -88,19 +83,7 @@ class ContactShareEmail: ContactShareField {
// MARK: - // MARK: -
class ContactShareAddress: ContactShareField { class ContactShareAddress: ContactShareFieldBase<OWSContactAddress> {
let value: OWSContactAddress
required init(_ value: OWSContactAddress) {
self.value = value
super.init()
}
override func localizedLabel() -> String {
return value.localizedLabel()
}
override func applyToContact(contact: OWSContact) { override func applyToContact(contact: OWSContact) {
assert(isIncluded()) assert(isIncluded())
@ -259,10 +242,6 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh
self.fieldViews = fieldViews self.fieldViews = fieldViews
} }
override public var canBecomeFirstResponder: Bool {
return true
}
// MARK: - View Lifecycle // MARK: - View Lifecycle
override public func viewWillAppear(_ animated: Bool) { override public func viewWillAppear(_ animated: Bool) {
@ -289,7 +268,6 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh
self.navigationItem.title = NSLocalizedString("CONTACT_SHARE_APPROVAL_VIEW_TITLE", self.navigationItem.title = NSLocalizedString("CONTACT_SHARE_APPROVAL_VIEW_TITLE",
comment: "Title for the 'Approve contact share' view.") comment: "Title for the 'Approve contact share' view.")
self.view.preservesSuperviewLayoutMargins = false
self.view.backgroundColor = UIColor.white self.view.backgroundColor = UIColor.white
updateContent() updateContent()
@ -340,10 +318,13 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh
let fieldsView = createFieldsView() let fieldsView = createFieldsView()
scrollView.addSubview(fieldsView) scrollView.addSubview(fieldsView)
// Use layoutMarginsGuide for views inside UIScrollView
// that should have same width as scroll view.
fieldsView.autoPinLeadingToSuperviewMargin() fieldsView.autoPinLeadingToSuperviewMargin()
fieldsView.autoPinTrailingToSuperviewMargin() fieldsView.autoPinTrailingToSuperviewMargin()
fieldsView.autoPinEdge(toSuperviewEdge: .top) fieldsView.autoPinEdge(toSuperviewEdge: .top)
fieldsView.autoPinEdge(toSuperviewEdge: .bottom) fieldsView.autoPinEdge(toSuperviewEdge: .bottom)
fieldsView.setContentHuggingHorizontalLow()
} }
private func createFieldsView() -> UIView { private func createFieldsView() -> UIView {
@ -374,10 +355,7 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh
stackView.layoutMargins = .zero stackView.layoutMargins = .zero
stackView.spacing = 10 stackView.spacing = 10
row.addSubview(stackView) row.addSubview(stackView)
stackView.autoPinLeadingToSuperviewMargin() stackView.autoPinEdgesToSuperviewMargins()
stackView.autoPinTrailingToSuperviewMargin()
stackView.autoPinTopToSuperviewMargin()
stackView.autoPinBottomToSuperviewMargin()
let nameLabel = UILabel() let nameLabel = UILabel()
self.nameLabel = nameLabel self.nameLabel = nameLabel
@ -386,7 +364,6 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh
nameLabel.textColor = UIColor.ows_materialBlue nameLabel.textColor = UIColor.ows_materialBlue
nameLabel.lineBreakMode = .byTruncatingTail nameLabel.lineBreakMode = .byTruncatingTail
stackView.addArrangedSubview(nameLabel) stackView.addArrangedSubview(nameLabel)
nameLabel.setContentHuggingHigh()
let editNameLabel = UILabel() let editNameLabel = UILabel()
editNameLabel.text = NSLocalizedString("CONTACT_EDIT_NAME_BUTTON", comment: "Label for the 'edit name' button in the contact share approval view.") editNameLabel.text = NSLocalizedString("CONTACT_EDIT_NAME_BUTTON", comment: "Label for the 'edit name' button in the contact share approval view.")

@ -52,10 +52,7 @@ class ContactNameFieldView: UIView {
stackView.layoutMargins = .zero stackView.layoutMargins = .zero
stackView.spacing = 10 stackView.spacing = 10
self.addSubview(stackView) self.addSubview(stackView)
stackView.autoPinTopToSuperviewMargin() stackView.autoPinEdgesToSuperviewMargins()
stackView.autoPinBottomToSuperviewMargin()
stackView.autoPinLeadingToSuperviewMargin()
stackView.autoPinTrailingToSuperviewMargin()
let nameLabel = UILabel() let nameLabel = UILabel()
nameLabel.text = name nameLabel.text = name
@ -291,13 +288,21 @@ public class EditContactShareNameViewController: OWSViewController, ContactNameF
delegate.editContactShareNameView(self, didEditContactShare: modifiedContactShare) 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() { func didPressCancel() {
Logger.info("\(logTag) \(#function)") 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 // MARK: - ContactNameFieldViewDelegate

@ -24,13 +24,7 @@ typedef NS_ENUM(NSUInteger, OWSContactPhoneType) {
NSString *NSStringForContactPhoneType(OWSContactPhoneType value); NSString *NSStringForContactPhoneType(OWSContactPhoneType value);
@interface OWSContactPhoneNumber : MTLModel @protocol OWSContactField <NSObject>
@property (nonatomic, readonly) OWSContactPhoneType phoneType;
// Applies in the OWSContactPhoneType_Custom case.
@property (nonatomic, readonly, nullable) NSString *label;
@property (nonatomic, readonly) NSString *phoneNumber;
- (BOOL)ows_isValid; - (BOOL)ows_isValid;
@ -42,6 +36,18 @@ NSString *NSStringForContactPhoneType(OWSContactPhoneType value);
#pragma mark - #pragma mark -
@interface OWSContactPhoneNumber : MTLModel <OWSContactField>
@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) { typedef NS_ENUM(NSUInteger, OWSContactEmailType) {
OWSContactEmailType_Home = 1, OWSContactEmailType_Home = 1,
OWSContactEmailType_Mobile, OWSContactEmailType_Mobile,
@ -51,7 +57,7 @@ typedef NS_ENUM(NSUInteger, OWSContactEmailType) {
NSString *NSStringForContactEmailType(OWSContactEmailType value); NSString *NSStringForContactEmailType(OWSContactEmailType value);
@interface OWSContactEmail : MTLModel @interface OWSContactEmail : MTLModel <OWSContactField>
@property (nonatomic, readonly) OWSContactEmailType emailType; @property (nonatomic, readonly) OWSContactEmailType emailType;
// Applies in the OWSContactEmailType_Custom case. // Applies in the OWSContactEmailType_Custom case.
@ -59,12 +65,6 @@ NSString *NSStringForContactEmailType(OWSContactEmailType value);
@property (nonatomic, readonly) NSString *email; @property (nonatomic, readonly) NSString *email;
- (BOOL)ows_isValid;
- (NSString *)localizedLabel;
- (NSString *)debugDescription;
@end @end
#pragma mark - #pragma mark -
@ -77,7 +77,7 @@ typedef NS_ENUM(NSUInteger, OWSContactAddressType) {
NSString *NSStringForContactAddressType(OWSContactAddressType value); NSString *NSStringForContactAddressType(OWSContactAddressType value);
@interface OWSContactAddress : MTLModel @interface OWSContactAddress : MTLModel <OWSContactField>
@property (nonatomic, readonly) OWSContactAddressType addressType; @property (nonatomic, readonly) OWSContactAddressType addressType;
// Applies in the OWSContactAddressType_Custom case. // 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 *postcode;
@property (nonatomic, readonly, nullable) NSString *country; @property (nonatomic, readonly, nullable) NSString *country;
- (BOOL)ows_isValid;
- (NSString *)localizedLabel;
- (NSString *)debugDescription;
@end @end
#pragma mark - #pragma mark -

Loading…
Cancel
Save