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)
}
protocol ContactShareField: class {
func localizedLabel() -> String
func isIncluded() -> Bool
func setIsIncluded(_ isIncluded: Bool)
func applyToContact(contact: OWSContact)
}
// MARK: -
class ContactShareField: NSObject {
class ContactShareFieldBase<ContactFieldType: OWSContactField>: 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<OWSContactPhoneNumber> {
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<OWSContactEmail> {
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<OWSContactAddress> {
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.")

@ -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

@ -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 <NSObject>
- (BOOL)ows_isValid;
@ -42,6 +36,18 @@ NSString *NSStringForContactPhoneType(OWSContactPhoneType value);
#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) {
OWSContactEmailType_Home = 1,
OWSContactEmailType_Mobile,
@ -51,7 +57,7 @@ typedef NS_ENUM(NSUInteger, OWSContactEmailType) {
NSString *NSStringForContactEmailType(OWSContactEmailType value);
@interface OWSContactEmail : MTLModel
@interface OWSContactEmail : MTLModel <OWSContactField>
@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 <OWSContactField>
@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 -

Loading…
Cancel
Save