2018-05-01 19:39:48 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import SignalServiceKit
|
|
|
|
import SignalMessaging
|
|
|
|
import Reachability
|
2018-05-01 21:53:51 +02:00
|
|
|
import ContactsUI
|
2018-05-02 16:08:47 +02:00
|
|
|
import MessageUI
|
2018-05-01 19:39:48 +02:00
|
|
|
|
2018-05-01 21:53:51 +02:00
|
|
|
class TappableView: UIView {
|
|
|
|
let actionBlock : (() -> Void)
|
|
|
|
|
|
|
|
// MARK: - Initializers
|
|
|
|
|
2018-05-03 20:07:49 +02:00
|
|
|
@available(*, unavailable, message: "use other constructor instead.")
|
2018-05-01 21:53:51 +02:00
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
|
|
fatalError("Unimplemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
required init(actionBlock : @escaping () -> Void) {
|
|
|
|
self.actionBlock = actionBlock
|
|
|
|
super.init(frame: CGRect.zero)
|
|
|
|
|
|
|
|
self.isUserInteractionEnabled = true
|
|
|
|
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(wasTapped)))
|
|
|
|
}
|
|
|
|
|
|
|
|
func wasTapped(sender: UIGestureRecognizer) {
|
2018-05-03 20:31:11 +02:00
|
|
|
Logger.info("\(logTag) \(#function)")
|
2018-05-01 21:53:51 +02:00
|
|
|
|
|
|
|
guard sender.state == .recognized else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
actionBlock()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
2018-05-02 16:08:47 +02:00
|
|
|
class ContactViewController: OWSViewController, CNContactViewControllerDelegate {
|
2018-05-01 19:39:48 +02:00
|
|
|
|
|
|
|
enum ContactViewMode {
|
|
|
|
case systemContactWithSignal,
|
|
|
|
systemContactWithoutSignal,
|
2018-05-01 21:53:51 +02:00
|
|
|
nonSystemContact,
|
2018-05-01 19:39:48 +02:00
|
|
|
noPhoneNumber,
|
|
|
|
unknown
|
|
|
|
}
|
|
|
|
|
|
|
|
private var hasLoadedView = false
|
|
|
|
|
|
|
|
private var viewMode = ContactViewMode.unknown {
|
|
|
|
didSet {
|
|
|
|
SwiftAssertIsOnMainThread(#function)
|
|
|
|
|
|
|
|
if oldValue != viewMode && hasLoadedView {
|
|
|
|
updateContent()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let contactsManager: OWSContactsManager
|
|
|
|
|
|
|
|
var reachability: Reachability?
|
|
|
|
|
2018-05-05 04:32:29 +02:00
|
|
|
private let contactShare: ContactShareViewModel
|
2018-05-01 19:39:48 +02:00
|
|
|
|
|
|
|
// MARK: - Initializers
|
|
|
|
|
|
|
|
@available(*, unavailable, message: "use init(call:) constructor instead.")
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
|
|
fatalError("Unimplemented")
|
|
|
|
}
|
|
|
|
|
2018-05-05 02:46:00 +02:00
|
|
|
required init(contactShare: ContactShareViewModel) {
|
2018-05-01 19:39:48 +02:00
|
|
|
contactsManager = Environment.current().contactsManager
|
2018-05-05 04:32:29 +02:00
|
|
|
self.contactShare = contactShare
|
2018-05-01 19:39:48 +02:00
|
|
|
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
|
|
|
2018-05-03 20:31:11 +02:00
|
|
|
updateMode()
|
2018-05-01 19:39:48 +02:00
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(forName: .OWSContactsManagerSignalAccountsDidChange, object: nil, queue: nil) { [weak self] _ in
|
|
|
|
guard let strongSelf = self else { return }
|
2018-05-03 20:31:11 +02:00
|
|
|
strongSelf.updateMode()
|
2018-05-01 19:39:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
reachability = Reachability.forInternetConnection()
|
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(forName: .reachabilityChanged, object: nil, queue: nil) { [weak self] _ in
|
|
|
|
guard let strongSelf = self else { return }
|
2018-05-03 20:31:11 +02:00
|
|
|
strongSelf.updateMode()
|
2018-05-01 19:39:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - View Lifecycle
|
|
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
super.viewWillAppear(animated)
|
|
|
|
|
2018-05-01 21:53:51 +02:00
|
|
|
UIUtil.applySignalAppearence()
|
|
|
|
|
2018-05-04 22:20:33 +02:00
|
|
|
navigationController?.isNavigationBarHidden = true
|
2018-05-02 21:43:53 +02:00
|
|
|
|
2018-05-01 19:39:48 +02:00
|
|
|
contactsManager.requestSystemContactsOnce(completion: { [weak self] _ in
|
|
|
|
guard let strongSelf = self else { return }
|
2018-05-03 20:31:11 +02:00
|
|
|
strongSelf.updateMode()
|
2018-05-01 19:39:48 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
|
2018-05-01 21:53:51 +02:00
|
|
|
UIUtil.applySignalAppearence()
|
2018-05-01 19:39:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-02 21:43:53 +02:00
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
|
|
super.viewWillDisappear(animated)
|
|
|
|
|
2018-05-04 22:20:33 +02:00
|
|
|
navigationController?.isNavigationBarHidden = false
|
2018-05-02 21:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidDisappear(_ animated: Bool) {
|
|
|
|
super.viewDidDisappear(animated)
|
|
|
|
}
|
2018-05-01 21:53:51 +02:00
|
|
|
|
2018-05-01 19:39:48 +02:00
|
|
|
override func loadView() {
|
|
|
|
super.loadView()
|
2018-05-01 21:53:51 +02:00
|
|
|
|
2018-05-02 21:43:53 +02:00
|
|
|
self.view.preservesSuperviewLayoutMargins = false
|
2018-05-04 16:30:49 +02:00
|
|
|
self.view.backgroundColor = heroBackgroundColor()
|
2018-05-01 19:39:48 +02:00
|
|
|
|
|
|
|
updateContent()
|
|
|
|
|
|
|
|
hasLoadedView = true
|
|
|
|
}
|
|
|
|
|
2018-05-03 20:31:11 +02:00
|
|
|
private func updateMode() {
|
2018-05-01 19:39:48 +02:00
|
|
|
SwiftAssertIsOnMainThread(#function)
|
|
|
|
|
2018-05-05 04:32:29 +02:00
|
|
|
guard contactShare.phoneNumberStrings.count > 0 else {
|
2018-05-01 19:39:48 +02:00
|
|
|
viewMode = .noPhoneNumber
|
|
|
|
return
|
|
|
|
}
|
2018-05-02 16:08:47 +02:00
|
|
|
if systemContactsWithSignalAccountsForContact().count > 0 {
|
2018-05-01 19:39:48 +02:00
|
|
|
viewMode = .systemContactWithSignal
|
|
|
|
return
|
|
|
|
}
|
2018-05-02 16:08:47 +02:00
|
|
|
if systemContactsForContact().count > 0 {
|
2018-05-01 19:39:48 +02:00
|
|
|
viewMode = .systemContactWithoutSignal
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-01 21:53:51 +02:00
|
|
|
viewMode = .nonSystemContact
|
2018-05-01 19:39:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-02 16:08:47 +02:00
|
|
|
private func systemContactsWithSignalAccountsForContact() -> [String] {
|
|
|
|
SwiftAssertIsOnMainThread(#function)
|
|
|
|
|
2018-05-05 04:32:29 +02:00
|
|
|
return contactShare.phoneNumberStrings.filter({ (phoneNumber) -> Bool in
|
2018-05-02 16:08:47 +02:00
|
|
|
return contactsManager.hasSignalAccount(forRecipientId: phoneNumber)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
private func systemContactsForContact() -> [String] {
|
|
|
|
SwiftAssertIsOnMainThread(#function)
|
|
|
|
|
2018-05-05 04:32:29 +02:00
|
|
|
return contactShare.phoneNumberStrings.filter({ (phoneNumber) -> Bool in
|
2018-05-02 16:08:47 +02:00
|
|
|
return contactsManager.allContactsMap[phoneNumber] != nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-01 19:39:48 +02:00
|
|
|
private func updateContent() {
|
|
|
|
SwiftAssertIsOnMainThread(#function)
|
|
|
|
|
2018-05-02 21:43:53 +02:00
|
|
|
guard let rootView = self.view else {
|
|
|
|
owsFail("\(logTag) missing root view.")
|
|
|
|
return
|
|
|
|
}
|
2018-05-01 21:53:51 +02:00
|
|
|
|
|
|
|
for subview in rootView.subviews {
|
2018-05-01 19:39:48 +02:00
|
|
|
subview.removeFromSuperview()
|
|
|
|
}
|
|
|
|
|
2018-05-02 21:43:53 +02:00
|
|
|
let topView = createTopView()
|
|
|
|
rootView.addSubview(topView)
|
|
|
|
topView.autoPin(toTopLayoutGuideOf: self, withInset: 0)
|
|
|
|
topView.autoPinWidthToSuperview()
|
|
|
|
|
|
|
|
// This view provides a background "below the fold".
|
|
|
|
let bottomView = UIView.container()
|
|
|
|
bottomView.backgroundColor = UIColor.white
|
|
|
|
self.view.addSubview(bottomView)
|
|
|
|
bottomView.layoutMargins = .zero
|
|
|
|
bottomView.autoPinWidthToSuperview()
|
|
|
|
bottomView.autoPinEdge(.top, to: .bottom, of: topView)
|
|
|
|
bottomView.autoPinEdge(toSuperviewEdge: .bottom)
|
|
|
|
|
|
|
|
let scrollView = UIScrollView()
|
|
|
|
scrollView.preservesSuperviewLayoutMargins = false
|
|
|
|
self.view.addSubview(scrollView)
|
|
|
|
scrollView.layoutMargins = .zero
|
|
|
|
scrollView.autoPinWidthToSuperview()
|
|
|
|
scrollView.autoPinEdge(.top, to: .bottom, of: topView)
|
|
|
|
scrollView.autoPinEdge(toSuperviewEdge: .bottom)
|
|
|
|
|
|
|
|
let fieldsView = createFieldsView()
|
|
|
|
|
|
|
|
scrollView.addSubview(fieldsView)
|
|
|
|
fieldsView.autoPinLeadingToSuperviewMargin()
|
|
|
|
fieldsView.autoPinTrailingToSuperviewMargin()
|
|
|
|
fieldsView.autoPinEdge(toSuperviewEdge: .top)
|
|
|
|
fieldsView.autoPinEdge(toSuperviewEdge: .bottom)
|
|
|
|
}
|
|
|
|
|
2018-05-04 16:30:49 +02:00
|
|
|
private func heroBackgroundColor() -> UIColor {
|
|
|
|
return UIColor(rgbHex: 0xefeff4)
|
|
|
|
}
|
|
|
|
|
2018-05-02 21:43:53 +02:00
|
|
|
private func createTopView() -> UIView {
|
|
|
|
SwiftAssertIsOnMainThread(#function)
|
|
|
|
|
2018-05-01 19:39:48 +02:00
|
|
|
let topView = UIView.container()
|
2018-05-04 16:30:49 +02:00
|
|
|
topView.backgroundColor = heroBackgroundColor()
|
2018-05-02 21:43:53 +02:00
|
|
|
topView.preservesSuperviewLayoutMargins = false
|
|
|
|
|
|
|
|
// Back Button
|
|
|
|
let backButtonSize = CGFloat(50)
|
|
|
|
let backButton = TappableView(actionBlock: { [weak self] _ in
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
strongSelf.didPressDismiss()
|
|
|
|
})
|
|
|
|
backButton.autoSetDimension(.width, toSize: backButtonSize)
|
|
|
|
backButton.autoSetDimension(.height, toSize: backButtonSize)
|
|
|
|
topView.addSubview(backButton)
|
|
|
|
backButton.autoPin(toTopLayoutGuideOf: self, withInset: 0)
|
|
|
|
backButton.autoPinLeadingToSuperviewMargin()
|
|
|
|
|
|
|
|
let backIconName = (self.view.isRTL() ? "system_disclosure_indicator" : "system_disclosure_indicator_rtl")
|
2018-05-04 19:34:11 +02:00
|
|
|
guard let backIconImage = UIImage(named: backIconName) else {
|
|
|
|
owsFail("\(logTag) missing icon.")
|
|
|
|
return topView
|
|
|
|
}
|
|
|
|
let backIconView = UIImageView(image: backIconImage.withRenderingMode(.alwaysTemplate))
|
2018-05-02 21:43:53 +02:00
|
|
|
backIconView.contentMode = .scaleAspectFit
|
|
|
|
backIconView.tintColor = UIColor.black.withAlphaComponent(0.6)
|
|
|
|
backButton.addSubview(backIconView)
|
|
|
|
backIconView.autoCenterInSuperview()
|
2018-05-01 19:39:48 +02:00
|
|
|
|
2018-05-05 04:52:43 +02:00
|
|
|
let avatarSize: CGFloat = 100
|
2018-05-02 19:25:38 +02:00
|
|
|
let avatarView = AvatarImageView()
|
2018-05-05 04:52:43 +02:00
|
|
|
avatarView.image = contactShare.getAvatarImage(diameter: avatarSize, contactsManager: contactsManager)
|
2018-05-01 19:39:48 +02:00
|
|
|
topView.addSubview(avatarView)
|
2018-05-02 16:08:47 +02:00
|
|
|
avatarView.autoPin(toTopLayoutGuideOf: self, withInset: 20)
|
2018-05-01 19:39:48 +02:00
|
|
|
avatarView.autoHCenterInSuperview()
|
|
|
|
avatarView.autoSetDimension(.width, toSize: avatarSize)
|
|
|
|
avatarView.autoSetDimension(.height, toSize: avatarSize)
|
|
|
|
|
|
|
|
let nameLabel = UILabel()
|
2018-05-05 04:32:29 +02:00
|
|
|
nameLabel.text = contactShare.displayName
|
2018-05-04 19:06:26 +02:00
|
|
|
nameLabel.font = UIFont.ows_dynamicTypeTitle1
|
2018-05-01 19:39:48 +02:00
|
|
|
nameLabel.textColor = UIColor.black
|
|
|
|
nameLabel.lineBreakMode = .byTruncatingTail
|
|
|
|
nameLabel.textAlignment = .center
|
|
|
|
topView.addSubview(nameLabel)
|
|
|
|
nameLabel.autoPinEdge(.top, to: .bottom, of: avatarView, withOffset: 10)
|
2018-05-02 16:08:47 +02:00
|
|
|
nameLabel.autoPinLeadingToSuperviewMargin(withInset: hMargin)
|
|
|
|
nameLabel.autoPinTrailingToSuperviewMargin(withInset: hMargin)
|
2018-05-01 19:39:48 +02:00
|
|
|
|
|
|
|
var lastView: UIView = nameLabel
|
|
|
|
|
2018-05-04 19:06:26 +02:00
|
|
|
for phoneNumber in systemContactsWithSignalAccountsForContact() {
|
2018-05-01 19:39:48 +02:00
|
|
|
let phoneNumberLabel = UILabel()
|
2018-05-04 19:06:26 +02:00
|
|
|
phoneNumberLabel.text = PhoneNumber.bestEffortLocalizedPhoneNumber(withE164: phoneNumber)
|
|
|
|
phoneNumberLabel.font = UIFont.ows_dynamicTypeFootnote
|
2018-05-01 19:39:48 +02:00
|
|
|
phoneNumberLabel.textColor = UIColor.black
|
|
|
|
phoneNumberLabel.lineBreakMode = .byTruncatingTail
|
|
|
|
phoneNumberLabel.textAlignment = .center
|
|
|
|
topView.addSubview(phoneNumberLabel)
|
2018-05-01 21:53:51 +02:00
|
|
|
phoneNumberLabel.autoPinEdge(.top, to: .bottom, of: lastView, withOffset: 5)
|
2018-05-02 16:08:47 +02:00
|
|
|
phoneNumberLabel.autoPinLeadingToSuperviewMargin(withInset: hMargin)
|
|
|
|
phoneNumberLabel.autoPinTrailingToSuperviewMargin(withInset: hMargin)
|
2018-05-01 19:39:48 +02:00
|
|
|
lastView = phoneNumberLabel
|
|
|
|
}
|
|
|
|
|
|
|
|
switch viewMode {
|
|
|
|
case .systemContactWithSignal:
|
2018-05-01 21:53:51 +02:00
|
|
|
// Show actions buttons for system contacts with a Signal account.
|
2018-05-02 16:08:47 +02:00
|
|
|
let stackView = UIStackView()
|
|
|
|
stackView.axis = .horizontal
|
|
|
|
stackView.distribution = .fillEqually
|
|
|
|
stackView.addArrangedSubview(createCircleActionButton(text: NSLocalizedString("ACTION_SEND_MESSAGE",
|
|
|
|
comment: "Label for 'sent message' button in contact view."),
|
|
|
|
actionBlock: { [weak self] _ in
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
strongSelf.didPressSendMessage()
|
|
|
|
}))
|
|
|
|
stackView.addArrangedSubview(createCircleActionButton(text: NSLocalizedString("ACTION_AUDIO_CALL",
|
|
|
|
comment: "Label for 'audio call' button in contact view."),
|
|
|
|
actionBlock: { [weak self] _ in
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
strongSelf.didPressAudioCall()
|
|
|
|
}))
|
|
|
|
stackView.addArrangedSubview(createCircleActionButton(text: NSLocalizedString("ACTION_VIDEO_CALL",
|
|
|
|
comment: "Label for 'video call' button in contact view."),
|
|
|
|
actionBlock: { [weak self] _ in
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
strongSelf.didPressVideoCall()
|
|
|
|
}))
|
|
|
|
topView.addSubview(stackView)
|
|
|
|
stackView.autoPinEdge(.top, to: .bottom, of: lastView, withOffset: 20)
|
|
|
|
stackView.autoPinLeadingToSuperviewMargin(withInset: hMargin)
|
|
|
|
stackView.autoPinTrailingToSuperviewMargin(withInset: hMargin)
|
|
|
|
lastView = stackView
|
2018-05-01 19:39:48 +02:00
|
|
|
case .systemContactWithoutSignal:
|
2018-05-01 21:53:51 +02:00
|
|
|
// Show invite button for system contacts without a Signal account.
|
2018-05-02 16:08:47 +02:00
|
|
|
let inviteButton = createLargePillButton(text: NSLocalizedString("ACTION_INVITE",
|
2018-05-04 19:06:26 +02:00
|
|
|
comment: "Label for 'invite' button in contact view."),
|
2018-05-02 16:08:47 +02:00
|
|
|
actionBlock: { [weak self] _ in
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
strongSelf.didPressInvite()
|
|
|
|
})
|
|
|
|
topView.addSubview(inviteButton)
|
|
|
|
inviteButton.autoPinEdge(.top, to: .bottom, of: lastView, withOffset: 20)
|
|
|
|
inviteButton.autoPinLeadingToSuperviewMargin(withInset: 55)
|
|
|
|
inviteButton.autoPinTrailingToSuperviewMargin(withInset: 55)
|
|
|
|
lastView = inviteButton
|
2018-05-01 21:53:51 +02:00
|
|
|
case .nonSystemContact:
|
2018-05-04 19:06:26 +02:00
|
|
|
// Show "add to contacts" button for non-system contacts.
|
|
|
|
let addToContactsButton = createLargePillButton(text: NSLocalizedString("CONVERSATION_VIEW_ADD_TO_CONTACTS_OFFER",
|
|
|
|
comment: "Message shown in conversation view that offers to add an unknown user to your phone's contacts."),
|
|
|
|
actionBlock: { [weak self] _ in
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
strongSelf.didPressAddToContacts()
|
|
|
|
})
|
|
|
|
topView.addSubview(addToContactsButton)
|
|
|
|
addToContactsButton.autoPinEdge(.top, to: .bottom, of: lastView, withOffset: 20)
|
|
|
|
addToContactsButton.autoPinLeadingToSuperviewMargin(withInset: 55)
|
|
|
|
addToContactsButton.autoPinTrailingToSuperviewMargin(withInset: 55)
|
|
|
|
lastView = addToContactsButton
|
2018-05-01 19:39:48 +02:00
|
|
|
break
|
|
|
|
case .noPhoneNumber:
|
2018-05-01 21:53:51 +02:00
|
|
|
// Show no action buttons for contacts without a phone number.
|
2018-05-01 19:39:48 +02:00
|
|
|
break
|
|
|
|
case .unknown:
|
|
|
|
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge)
|
|
|
|
topView.addSubview(activityIndicator)
|
|
|
|
activityIndicator.autoPinEdge(.top, to: .bottom, of: lastView, withOffset: 10)
|
|
|
|
activityIndicator.autoHCenterInSuperview()
|
|
|
|
lastView = activityIndicator
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2018-05-01 21:53:51 +02:00
|
|
|
lastView.autoPinEdge(toSuperviewEdge: .bottom, withInset: 15)
|
|
|
|
|
2018-05-02 21:43:53 +02:00
|
|
|
return topView
|
|
|
|
}
|
|
|
|
|
|
|
|
private func createFieldsView() -> UIView {
|
|
|
|
SwiftAssertIsOnMainThread(#function)
|
|
|
|
|
2018-05-04 19:57:29 +02:00
|
|
|
var rows = [UIView]()
|
2018-05-01 21:53:51 +02:00
|
|
|
|
|
|
|
// TODO: Not designed yet.
|
|
|
|
// if viewMode == .systemContactWithSignal ||
|
|
|
|
// viewMode == .systemContactWithoutSignal {
|
|
|
|
// addRow(createActionRow(labelText:NSLocalizedString("ACTION_SHARE_CONTACT",
|
|
|
|
// comment:"Label for 'share contact' button."),
|
|
|
|
// action:#selector(didPressShareContact)))
|
|
|
|
// }
|
|
|
|
|
2018-05-05 04:32:29 +02:00
|
|
|
for phoneNumber in contactShare.phoneNumbers {
|
2018-05-04 19:34:11 +02:00
|
|
|
let formattedPhoneNumber = PhoneNumber.bestEffortLocalizedPhoneNumber(withE164: phoneNumber.phoneNumber)
|
2018-05-02 20:13:55 +02:00
|
|
|
|
2018-05-04 19:06:26 +02:00
|
|
|
rows.append(createSimpleFieldRow(name: phoneNumber.localizedLabel(),
|
|
|
|
value: formattedPhoneNumber,
|
|
|
|
actionBlock: {
|
|
|
|
guard let url = NSURL(string: "tel:\(phoneNumber.phoneNumber)") else {
|
|
|
|
owsFail("\(ContactViewController.logTag) could not open phone number.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
UIApplication.shared.openURL(url as URL)
|
2018-05-03 20:31:11 +02:00
|
|
|
}))
|
2018-05-01 21:53:51 +02:00
|
|
|
}
|
|
|
|
|
2018-05-05 04:32:29 +02:00
|
|
|
for email in contactShare.emails {
|
2018-05-04 19:06:26 +02:00
|
|
|
rows.append(createSimpleFieldRow(name: email.localizedLabel(),
|
|
|
|
value: email.email,
|
|
|
|
actionBlock: {
|
|
|
|
guard let url = NSURL(string: "mailto:\(email.email)") else {
|
|
|
|
owsFail("\(ContactViewController.logTag) could not open email.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
UIApplication.shared.openURL(url as URL)
|
2018-05-03 20:31:11 +02:00
|
|
|
}))
|
2018-05-01 21:53:51 +02:00
|
|
|
}
|
|
|
|
|
2018-05-04 19:06:26 +02:00
|
|
|
for address in contactShare.addresses {
|
|
|
|
rows.append(createAddressFieldRow(name: address.localizedLabel(),
|
|
|
|
address: address,
|
|
|
|
actionBlock: { [weak self] _ in
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
strongSelf.didPressAddress(address: address)
|
|
|
|
}))
|
|
|
|
}
|
2018-05-01 21:53:51 +02:00
|
|
|
|
2018-05-04 19:57:29 +02:00
|
|
|
return ContactFieldView(rows: rows, hMargin: hMargin)
|
2018-05-01 21:53:51 +02:00
|
|
|
}
|
|
|
|
|
2018-05-02 16:08:47 +02:00
|
|
|
private let hMargin = CGFloat(16)
|
2018-05-01 21:53:51 +02:00
|
|
|
|
|
|
|
private func createActionRow(labelText: String, action: Selector) -> UIView {
|
|
|
|
let row = UIView()
|
2018-05-02 16:08:47 +02:00
|
|
|
row.layoutMargins.left = 0
|
|
|
|
row.layoutMargins.right = 0
|
2018-05-01 21:53:51 +02:00
|
|
|
row.isUserInteractionEnabled = true
|
|
|
|
row.addGestureRecognizer(UITapGestureRecognizer(target: self, action: action))
|
2018-05-02 16:08:47 +02:00
|
|
|
|
2018-05-01 21:53:51 +02:00
|
|
|
let label = UILabel()
|
|
|
|
label.text = labelText
|
|
|
|
label.font = UIFont.ows_dynamicTypeBody
|
|
|
|
label.textColor = UIColor.ows_materialBlue
|
|
|
|
label.lineBreakMode = .byTruncatingTail
|
|
|
|
row.addSubview(label)
|
|
|
|
label.autoPinTopToSuperviewMargin()
|
|
|
|
label.autoPinBottomToSuperviewMargin()
|
|
|
|
label.autoPinLeadingToSuperviewMargin(withInset: hMargin)
|
|
|
|
label.autoPinTrailingToSuperviewMargin(withInset: hMargin)
|
2018-05-02 16:08:47 +02:00
|
|
|
|
2018-05-01 21:53:51 +02:00
|
|
|
return row
|
|
|
|
}
|
|
|
|
|
2018-05-04 19:06:26 +02:00
|
|
|
private func createSimpleFieldRow(name: String, value: String?, actionBlock : @escaping () -> Void) -> UIView {
|
2018-05-01 21:53:51 +02:00
|
|
|
let row = TappableView(actionBlock: actionBlock)
|
2018-05-02 16:08:47 +02:00
|
|
|
row.layoutMargins.left = 0
|
|
|
|
row.layoutMargins.right = 0
|
2018-05-01 21:53:51 +02:00
|
|
|
|
2018-05-04 19:06:26 +02:00
|
|
|
let stackView = UIStackView()
|
|
|
|
stackView.axis = .vertical
|
|
|
|
stackView.alignment = .leading
|
|
|
|
stackView.spacing = 3
|
|
|
|
row.addSubview(stackView)
|
|
|
|
stackView.autoPinTopToSuperviewMargin()
|
|
|
|
stackView.autoPinBottomToSuperviewMargin()
|
|
|
|
stackView.autoPinLeadingToSuperviewMargin(withInset: hMargin)
|
|
|
|
stackView.autoPinTrailingToSuperviewMargin(withInset: hMargin)
|
|
|
|
|
2018-05-01 21:53:51 +02:00
|
|
|
let nameLabel = UILabel()
|
|
|
|
nameLabel.text = name
|
2018-05-04 19:06:26 +02:00
|
|
|
nameLabel.font = UIFont.ows_dynamicTypeSubheadline
|
2018-05-01 21:53:51 +02:00
|
|
|
nameLabel.textColor = UIColor.black
|
|
|
|
nameLabel.lineBreakMode = .byTruncatingTail
|
2018-05-04 19:06:26 +02:00
|
|
|
stackView.addArrangedSubview(nameLabel)
|
2018-05-01 21:53:51 +02:00
|
|
|
|
|
|
|
let valueLabel = UILabel()
|
2018-05-04 19:34:11 +02:00
|
|
|
valueLabel.text = value
|
2018-05-04 19:06:26 +02:00
|
|
|
valueLabel.font = UIFont.ows_dynamicTypeBody
|
2018-05-01 21:53:51 +02:00
|
|
|
valueLabel.textColor = UIColor.ows_materialBlue
|
|
|
|
valueLabel.lineBreakMode = .byTruncatingTail
|
2018-05-04 19:06:26 +02:00
|
|
|
stackView.addArrangedSubview(valueLabel)
|
|
|
|
|
|
|
|
return row
|
|
|
|
}
|
|
|
|
|
|
|
|
private func createAddressFieldRow(name: String, address: OWSContactAddress, actionBlock : @escaping () -> Void) -> UIView {
|
|
|
|
let row = TappableView(actionBlock: actionBlock)
|
|
|
|
row.layoutMargins.left = 0
|
|
|
|
row.layoutMargins.right = 0
|
|
|
|
|
|
|
|
let stackView = UIStackView()
|
|
|
|
stackView.axis = .vertical
|
|
|
|
stackView.alignment = .leading
|
|
|
|
stackView.spacing = 3
|
|
|
|
stackView.layoutMargins = .zero
|
|
|
|
row.addSubview(stackView)
|
|
|
|
stackView.autoPinTopToSuperviewMargin()
|
|
|
|
stackView.autoPinBottomToSuperviewMargin()
|
|
|
|
stackView.autoPinLeadingToSuperviewMargin(withInset: hMargin)
|
|
|
|
stackView.autoPinTrailingToSuperviewMargin(withInset: hMargin)
|
2018-05-01 21:53:51 +02:00
|
|
|
|
2018-05-04 19:06:26 +02:00
|
|
|
let nameLabel = UILabel()
|
|
|
|
nameLabel.text = name
|
|
|
|
nameLabel.font = UIFont.ows_dynamicTypeSubheadline
|
|
|
|
nameLabel.textColor = UIColor.black
|
|
|
|
nameLabel.lineBreakMode = .byTruncatingTail
|
|
|
|
stackView.addArrangedSubview(nameLabel)
|
|
|
|
|
|
|
|
let tryToAddNameValue: ((String, String?) -> Void) = { (propertyName, propertyValue) in
|
|
|
|
guard let propertyValue = propertyValue else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
guard propertyValue.count > 0 else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let row = UIStackView()
|
|
|
|
row.axis = .horizontal
|
|
|
|
row.alignment = .leading
|
|
|
|
row.spacing = 10
|
|
|
|
row.layoutMargins = .zero
|
|
|
|
|
|
|
|
let nameLabel = UILabel()
|
|
|
|
nameLabel.text = propertyName
|
|
|
|
nameLabel.font = UIFont.ows_dynamicTypeBody
|
|
|
|
nameLabel.textColor = UIColor.black
|
|
|
|
nameLabel.lineBreakMode = .byTruncatingTail
|
|
|
|
row.addArrangedSubview(nameLabel)
|
|
|
|
nameLabel.setContentHuggingHigh()
|
|
|
|
nameLabel.setCompressionResistanceHigh()
|
|
|
|
|
|
|
|
let valueLabel = UILabel()
|
|
|
|
valueLabel.text = propertyValue
|
|
|
|
valueLabel.font = UIFont.ows_dynamicTypeBody
|
|
|
|
valueLabel.textColor = UIColor.ows_materialBlue
|
|
|
|
valueLabel.lineBreakMode = .byTruncatingTail
|
|
|
|
row.addArrangedSubview(valueLabel)
|
|
|
|
|
|
|
|
stackView.addArrangedSubview(row)
|
|
|
|
}
|
|
|
|
|
|
|
|
tryToAddNameValue(NSLocalizedString("CONTACT_FIELD_ADDRESS_STREET", comment: "Label for the 'street' field of a contact's address."),
|
|
|
|
address.street)
|
|
|
|
tryToAddNameValue(NSLocalizedString("CONTACT_FIELD_ADDRESS_POBOX", comment: "Label for the 'pobox' field of a contact's address."),
|
|
|
|
address.pobox)
|
|
|
|
tryToAddNameValue(NSLocalizedString("CONTACT_FIELD_ADDRESS_NEIGHBORHOOD", comment: "Label for the 'neighborhood' field of a contact's address."),
|
|
|
|
address.neighborhood)
|
|
|
|
tryToAddNameValue(NSLocalizedString("CONTACT_FIELD_ADDRESS_CITY", comment: "Label for the 'city' field of a contact's address."),
|
|
|
|
address.city)
|
|
|
|
tryToAddNameValue(NSLocalizedString("CONTACT_FIELD_ADDRESS_REGION", comment: "Label for the 'region' field of a contact's address."),
|
|
|
|
address.region)
|
|
|
|
tryToAddNameValue(NSLocalizedString("CONTACT_FIELD_ADDRESS_POSTCODE", comment: "Label for the 'postcode' field of a contact's address."),
|
|
|
|
address.postcode)
|
|
|
|
tryToAddNameValue(NSLocalizedString("CONTACT_FIELD_ADDRESS_COUNTRY", comment: "Label for the 'country' field of a contact's address."),
|
|
|
|
address.country)
|
2018-05-01 21:53:51 +02:00
|
|
|
|
|
|
|
return row
|
2018-05-01 19:39:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-02 16:08:47 +02:00
|
|
|
// TODO: Use real assets.
|
|
|
|
private func createCircleActionButton(text: String, actionBlock : @escaping () -> Void) -> UIView {
|
|
|
|
let buttonSize = CGFloat(50)
|
2018-05-01 19:39:48 +02:00
|
|
|
|
2018-05-02 16:08:47 +02:00
|
|
|
let button = TappableView(actionBlock: actionBlock)
|
|
|
|
button.layoutMargins = .zero
|
|
|
|
button.autoSetDimension(.width, toSize: buttonSize, relation: .greaterThanOrEqual)
|
|
|
|
|
|
|
|
let circleView = UIView()
|
|
|
|
circleView.backgroundColor = UIColor.white
|
|
|
|
circleView.autoSetDimension(.width, toSize: buttonSize)
|
|
|
|
circleView.autoSetDimension(.height, toSize: buttonSize)
|
|
|
|
circleView.layer.cornerRadius = buttonSize * 0.5
|
|
|
|
button.addSubview(circleView)
|
|
|
|
circleView.autoPinEdge(toSuperviewEdge: .top)
|
|
|
|
circleView.autoHCenterInSuperview()
|
|
|
|
|
|
|
|
let label = UILabel()
|
|
|
|
label.text = text
|
|
|
|
label.font = UIFont.ows_dynamicTypeCaption2
|
|
|
|
label.textColor = UIColor.black
|
|
|
|
label.lineBreakMode = .byTruncatingTail
|
|
|
|
label.textAlignment = .center
|
|
|
|
button.addSubview(label)
|
|
|
|
label.autoPinEdge(.top, to: .bottom, of: circleView, withOffset: 3)
|
|
|
|
label.autoPinEdge(toSuperviewEdge: .bottom)
|
|
|
|
label.autoPinLeadingToSuperviewMargin()
|
|
|
|
label.autoPinTrailingToSuperviewMargin()
|
|
|
|
|
|
|
|
return button
|
|
|
|
}
|
|
|
|
|
|
|
|
private func createLargePillButton(text: String, actionBlock : @escaping () -> Void) -> UIView {
|
|
|
|
let button = TappableView(actionBlock: actionBlock)
|
|
|
|
button.backgroundColor = UIColor.white
|
|
|
|
button.layoutMargins = .zero
|
|
|
|
button.autoSetDimension(.height, toSize: 45)
|
|
|
|
button.layer.cornerRadius = 5
|
|
|
|
|
|
|
|
let label = UILabel()
|
|
|
|
label.text = text
|
2018-05-04 19:06:26 +02:00
|
|
|
label.font = UIFont.ows_dynamicTypeBody
|
2018-05-02 16:08:47 +02:00
|
|
|
label.textColor = UIColor.ows_materialBlue
|
|
|
|
label.lineBreakMode = .byTruncatingTail
|
|
|
|
label.textAlignment = .center
|
|
|
|
button.addSubview(label)
|
|
|
|
label.autoPinLeadingToSuperviewMargin(withInset: 20)
|
|
|
|
label.autoPinTrailingToSuperviewMargin(withInset: 20)
|
|
|
|
label.autoVCenterInSuperview()
|
|
|
|
label.autoPinEdge(toSuperviewEdge: .top, withInset: 0, relation: .greaterThanOrEqual)
|
|
|
|
label.autoPinEdge(toSuperviewEdge: .bottom, withInset: 0, relation: .greaterThanOrEqual)
|
|
|
|
|
|
|
|
return button
|
|
|
|
}
|
2018-05-01 21:53:51 +02:00
|
|
|
|
2018-05-04 19:06:26 +02:00
|
|
|
func didPressCreateNewContact() {
|
2018-05-03 20:31:11 +02:00
|
|
|
Logger.info("\(logTag) \(#function)")
|
2018-05-01 21:53:51 +02:00
|
|
|
|
|
|
|
presentNewContactView()
|
|
|
|
}
|
|
|
|
|
2018-05-04 19:06:26 +02:00
|
|
|
func didPressAddToExistingContact() {
|
2018-05-03 20:31:11 +02:00
|
|
|
Logger.info("\(logTag) \(#function)")
|
2018-05-01 21:53:51 +02:00
|
|
|
|
|
|
|
presentSelectAddToExistingContactView()
|
|
|
|
}
|
|
|
|
|
|
|
|
func didPressShareContact(sender: UIGestureRecognizer) {
|
2018-05-03 20:31:11 +02:00
|
|
|
Logger.info("\(logTag) \(#function)")
|
2018-05-01 21:53:51 +02:00
|
|
|
|
|
|
|
guard sender.state == .recognized else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// TODO:
|
|
|
|
}
|
|
|
|
|
2018-05-02 16:08:47 +02:00
|
|
|
func didPressSendMessage() {
|
2018-05-03 20:31:11 +02:00
|
|
|
Logger.info("\(logTag) \(#function)")
|
2018-05-01 21:53:51 +02:00
|
|
|
|
2018-05-02 20:50:05 +02:00
|
|
|
presentThreadAndPeform(action: .compose)
|
2018-05-02 16:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func didPressAudioCall() {
|
2018-05-03 20:31:11 +02:00
|
|
|
Logger.info("\(logTag) \(#function)")
|
2018-05-02 16:08:47 +02:00
|
|
|
|
2018-05-02 20:50:05 +02:00
|
|
|
presentThreadAndPeform(action: .audioCall)
|
2018-05-02 16:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func didPressVideoCall() {
|
2018-05-03 20:31:11 +02:00
|
|
|
Logger.info("\(logTag) \(#function)")
|
2018-05-02 16:08:47 +02:00
|
|
|
|
2018-05-02 20:50:05 +02:00
|
|
|
presentThreadAndPeform(action: .videoCall)
|
|
|
|
}
|
|
|
|
|
|
|
|
func presentThreadAndPeform(action: ConversationViewAction) {
|
2018-05-02 16:08:47 +02:00
|
|
|
// TODO: We're taking the first Signal account id. We might
|
|
|
|
// want to let the user select if there's more than one.
|
2018-05-02 20:50:05 +02:00
|
|
|
let phoneNumbers = systemContactsWithSignalAccountsForContact()
|
|
|
|
guard phoneNumbers.count > 0 else {
|
2018-05-02 16:08:47 +02:00
|
|
|
owsFail("\(logTag) missing Signal recipient id.")
|
|
|
|
return
|
|
|
|
}
|
2018-05-02 20:50:05 +02:00
|
|
|
guard phoneNumbers.count > 1 else {
|
|
|
|
let recipientId = systemContactsWithSignalAccountsForContact().first!
|
|
|
|
SignalApp.shared().presentConversation(forRecipientId: recipientId, action: action)
|
|
|
|
return
|
|
|
|
}
|
2018-05-02 16:08:47 +02:00
|
|
|
|
2018-05-02 20:50:05 +02:00
|
|
|
showPhoneNumberPicker(phoneNumbers: phoneNumbers, completion: { (recipientId) in
|
|
|
|
SignalApp.shared().presentConversation(forRecipientId: recipientId, action: action)
|
|
|
|
})
|
2018-05-02 16:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func didPressInvite() {
|
2018-05-03 20:31:11 +02:00
|
|
|
Logger.info("\(logTag) \(#function)")
|
2018-05-02 16:08:47 +02:00
|
|
|
|
|
|
|
guard MFMessageComposeViewController.canSendText() else {
|
2018-05-03 20:31:11 +02:00
|
|
|
Logger.info("\(logTag) Device cannot send text")
|
2018-05-02 16:08:47 +02:00
|
|
|
OWSAlerts.showErrorAlert(message: NSLocalizedString("UNSUPPORTED_FEATURE_ERROR", comment: ""))
|
|
|
|
return
|
|
|
|
}
|
2018-05-05 04:32:29 +02:00
|
|
|
let phoneNumbers = contactShare.phoneNumberStrings
|
2018-05-02 16:08:47 +02:00
|
|
|
guard phoneNumbers.count > 0 else {
|
|
|
|
owsFail("\(logTag) no phone numbers.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let inviteFlow =
|
|
|
|
InviteFlow(presentingViewController: self, contactsManager: contactsManager)
|
|
|
|
inviteFlow.sendSMSTo(phoneNumbers: phoneNumbers)
|
|
|
|
}
|
2018-05-01 21:53:51 +02:00
|
|
|
|
2018-05-04 19:06:26 +02:00
|
|
|
func didPressAddToContacts() {
|
|
|
|
Logger.info("\(logTag) \(#function)")
|
|
|
|
|
|
|
|
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
|
|
|
|
|
|
|
actionSheet.addAction(UIAlertAction(title: NSLocalizedString("CONVERSATION_SETTINGS_NEW_CONTACT",
|
|
|
|
comment: "Label for 'new contact' button in conversation settings view."),
|
|
|
|
style: .default) { _ in
|
|
|
|
self.didPressCreateNewContact()
|
|
|
|
})
|
|
|
|
actionSheet.addAction(UIAlertAction(title: NSLocalizedString("CONVERSATION_SETTINGS_ADD_TO_EXISTING_CONTACT",
|
|
|
|
comment: "Label for 'new contact' button in conversation settings view."),
|
|
|
|
style: .default) { _ in
|
|
|
|
self.didPressAddToExistingContact()
|
|
|
|
})
|
|
|
|
actionSheet.addAction(OWSAlerts.cancelAction)
|
|
|
|
|
|
|
|
self.present(actionSheet, animated: true)
|
|
|
|
}
|
|
|
|
|
2018-05-02 20:50:05 +02:00
|
|
|
private func showPhoneNumberPicker(phoneNumbers: [String], completion :@escaping ((String) -> Void)) {
|
|
|
|
|
|
|
|
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
|
|
|
|
|
|
|
for phoneNumber in phoneNumbers {
|
2018-05-04 19:34:11 +02:00
|
|
|
actionSheet.addAction(UIAlertAction(title: PhoneNumber.bestEffortLocalizedPhoneNumber(withE164: phoneNumber),
|
2018-05-02 20:50:05 +02:00
|
|
|
style: .default) { _ in
|
|
|
|
completion(phoneNumber)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
actionSheet.addAction(OWSAlerts.cancelAction)
|
|
|
|
|
|
|
|
self.present(actionSheet, animated: true)
|
|
|
|
}
|
|
|
|
|
2018-05-02 21:43:53 +02:00
|
|
|
func didPressDismiss() {
|
|
|
|
Logger.info("\(self.logTag) \(#function)")
|
|
|
|
|
|
|
|
self.navigationController?.popViewController(animated: true)
|
|
|
|
}
|
|
|
|
|
2018-05-04 19:06:26 +02:00
|
|
|
func didPressAddress(address: OWSContactAddress) {
|
|
|
|
Logger.info("\(self.logTag) \(#function)")
|
|
|
|
|
|
|
|
// Open address in Apple Maps app.
|
|
|
|
var addressParts = [String]()
|
|
|
|
let addAddressPart: ((String?) -> Void) = { (part) in
|
|
|
|
guard let part = part else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
guard part.count > 0 else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
addressParts.append(part)
|
|
|
|
}
|
|
|
|
addAddressPart(address.street)
|
|
|
|
addAddressPart(address.neighborhood)
|
|
|
|
addAddressPart(address.city)
|
|
|
|
addAddressPart(address.region)
|
|
|
|
addAddressPart(address.postcode)
|
|
|
|
addAddressPart(address.country)
|
|
|
|
let mapAddress = addressParts.joined(separator: ", ")
|
|
|
|
guard let escapedMapAddress = mapAddress.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
|
2018-05-04 19:09:26 +02:00
|
|
|
owsFail("\(ContactViewController.logTag) could not open address.")
|
2018-05-04 19:06:26 +02:00
|
|
|
return
|
|
|
|
}
|
2018-05-04 19:19:40 +02:00
|
|
|
// Note that we use "q" (i.e. query) rather than "address" since we can't assume
|
|
|
|
// this is a well-formed address.
|
|
|
|
guard let url = NSURL(string: "http://maps.apple.com/?q=\(escapedMapAddress)") else {
|
2018-05-04 19:09:26 +02:00
|
|
|
owsFail("\(ContactViewController.logTag) could not open address.")
|
2018-05-04 19:06:26 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
UIApplication.shared.openURL(url as URL)
|
|
|
|
}
|
|
|
|
|
2018-05-01 21:53:51 +02:00
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
private func presentNewContactView() {
|
|
|
|
guard contactsManager.supportsContactEditing else {
|
2018-05-03 20:31:11 +02:00
|
|
|
owsFail("\(logTag) Contact editing not supported")
|
2018-05-01 21:53:51 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-05 04:32:29 +02:00
|
|
|
guard let systemContact = OWSContacts.systemContact(for: contactShare.dbRecord) else {
|
|
|
|
owsFail("\(logTag) Could not derive system contactShare.")
|
2018-05-01 21:53:51 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
guard contactsManager.isSystemContactsAuthorized else {
|
|
|
|
ContactsViewHelper.presentMissingContactAccessAlertController(from: self)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let contactViewController = CNContactViewController(forNewContact: systemContact)
|
|
|
|
contactViewController.delegate = self
|
|
|
|
contactViewController.allowsActions = false
|
|
|
|
contactViewController.allowsEditing = true
|
|
|
|
contactViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: CommonStrings.cancelButton, style: .plain, target: self, action: #selector(didFinishEditingContact))
|
2018-05-03 17:33:01 +02:00
|
|
|
contactViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: CommonStrings.cancelButton,
|
|
|
|
style: .plain,
|
|
|
|
target: self,
|
|
|
|
action: #selector(didFinishEditingContact))
|
2018-05-01 21:53:51 +02:00
|
|
|
|
|
|
|
self.navigationController?.pushViewController(contactViewController, animated: true)
|
|
|
|
|
|
|
|
// HACK otherwise CNContactViewController Navbar is shown as black.
|
|
|
|
// RADAR rdar://28433898 http://www.openradar.me/28433898
|
|
|
|
// CNContactViewController incompatible with opaque navigation bar
|
|
|
|
UIUtil.applyDefaultSystemAppearence()
|
|
|
|
}
|
|
|
|
|
|
|
|
private func presentSelectAddToExistingContactView() {
|
|
|
|
guard contactsManager.supportsContactEditing else {
|
2018-05-03 20:31:11 +02:00
|
|
|
owsFail("\(logTag) Contact editing not supported")
|
2018-05-01 21:53:51 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
guard contactsManager.isSystemContactsAuthorized else {
|
|
|
|
ContactsViewHelper.presentMissingContactAccessAlertController(from: self)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-05 04:32:29 +02:00
|
|
|
guard let firstPhoneNumber = contactShare.phoneNumbers.first else {
|
2018-05-03 20:31:11 +02:00
|
|
|
owsFail("\(logTag) Missing phone number.")
|
2018-05-01 21:53:51 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-02 16:08:47 +02:00
|
|
|
// TODO: We need to modify OWSAddToContactViewController to take a OWSContact
|
|
|
|
// and merge it with an existing CNContact.
|
2018-05-01 21:53:51 +02:00
|
|
|
let viewController = OWSAddToContactViewController()
|
|
|
|
viewController.configure(withRecipientId: firstPhoneNumber.phoneNumber)
|
|
|
|
self.navigationController?.pushViewController(viewController, animated: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - CNContactViewControllerDelegate
|
|
|
|
|
|
|
|
@objc public func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) {
|
2018-05-03 20:31:11 +02:00
|
|
|
Logger.info("\(logTag) \(#function)")
|
2018-05-01 21:53:51 +02:00
|
|
|
|
|
|
|
self.navigationController?.popToViewController(self, animated: true)
|
|
|
|
|
|
|
|
updateContent()
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc public func didFinishEditingContact() {
|
2018-05-03 20:31:11 +02:00
|
|
|
Logger.info("\(logTag) \(#function)")
|
2018-05-01 21:53:51 +02:00
|
|
|
|
|
|
|
self.navigationController?.popToViewController(self, animated: true)
|
|
|
|
|
|
|
|
updateContent()
|
|
|
|
}
|
2018-05-01 19:39:48 +02:00
|
|
|
}
|