Finish new conversation screen redesign

pull/68/head
Niels Andriesse 5 years ago
parent 8e06fd3e9a
commit 8429b9d680

@ -581,7 +581,6 @@
B893063F2383961A005EAA8E /* ScanQRCodeWrapperVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B893063E2383961A005EAA8E /* ScanQRCodeWrapperVC.swift */; };
B894D0712339D6F300B4D94D /* DeviceLinkingModalDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B894D0702339D6F300B4D94D /* DeviceLinkingModalDelegate.swift */; };
B894D0752339EDCF00B4D94D /* NukeDataModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B894D0742339EDCF00B4D94D /* NukeDataModal.swift */; };
B89841E322B7579F00B1BDC6 /* NewConversationVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B89841E222B7579F00B1BDC6 /* NewConversationVC.swift */; };
B8B26C8F234D629C004ED98C /* MentionCandidateSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B26C8E234D629C004ED98C /* MentionCandidateSelectionView.swift */; };
B8B26C91234D8CBD004ED98C /* MentionCandidateSelectionViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B26C90234D8CBD004ED98C /* MentionCandidateSelectionViewDelegate.swift */; };
B8B5BCEC2394D869003823C9 /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B5BCEB2394D869003823C9 /* Button.swift */; };
@ -592,7 +591,7 @@
B8BB82AB238F669C00BA5194 /* ConversationCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8BB82AA238F669C00BA5194 /* ConversationCell.swift */; };
B8BB82AD238F734800BA5194 /* ProfilePictureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8BB82AC238F734800BA5194 /* ProfilePictureView.swift */; };
B8BB82B12390C37000BA5194 /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8BB82B02390C37000BA5194 /* SearchBar.swift */; };
B8BB82B323947E6B00BA5194 /* NewConversationVCV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8BB82B223947E6B00BA5194 /* NewConversationVCV2.swift */; };
B8BB82B323947E6B00BA5194 /* NewConversationVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8BB82B223947E6B00BA5194 /* NewConversationVC.swift */; };
B8BB82B523947F2D00BA5194 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8BB82B423947F2D00BA5194 /* TextField.swift */; };
B8BB82B92394911B00BA5194 /* Separator.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8BB82B82394911B00BA5194 /* Separator.swift */; };
B8BB82BE2394D4CE00BA5194 /* Fonts.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8BB82BD2394D4CE00BA5194 /* Fonts.swift */; };
@ -1406,7 +1405,6 @@
B893063E2383961A005EAA8E /* ScanQRCodeWrapperVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanQRCodeWrapperVC.swift; sourceTree = "<group>"; };
B894D0702339D6F300B4D94D /* DeviceLinkingModalDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceLinkingModalDelegate.swift; sourceTree = "<group>"; };
B894D0742339EDCF00B4D94D /* NukeDataModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NukeDataModal.swift; sourceTree = "<group>"; };
B89841E222B7579F00B1BDC6 /* NewConversationVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewConversationVC.swift; sourceTree = "<group>"; };
B8B26C8E234D629C004ED98C /* MentionCandidateSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentionCandidateSelectionView.swift; sourceTree = "<group>"; };
B8B26C90234D8CBD004ED98C /* MentionCandidateSelectionViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentionCandidateSelectionViewDelegate.swift; sourceTree = "<group>"; };
B8B5BCEB2394D869003823C9 /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = "<group>"; };
@ -1417,7 +1415,7 @@
B8BB82AA238F669C00BA5194 /* ConversationCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationCell.swift; sourceTree = "<group>"; };
B8BB82AC238F734800BA5194 /* ProfilePictureView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePictureView.swift; sourceTree = "<group>"; };
B8BB82B02390C37000BA5194 /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = "<group>"; };
B8BB82B223947E6B00BA5194 /* NewConversationVCV2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewConversationVCV2.swift; sourceTree = "<group>"; };
B8BB82B223947E6B00BA5194 /* NewConversationVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewConversationVC.swift; sourceTree = "<group>"; };
B8BB82B423947F2D00BA5194 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; };
B8BB82B82394911B00BA5194 /* Separator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Separator.swift; sourceTree = "<group>"; };
B8BB82BD2394D4CE00BA5194 /* Fonts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fonts.swift; sourceTree = "<group>"; };
@ -2768,8 +2766,7 @@
B825849F2315024B001B41CB /* LokiRSSFeedPoller.swift */,
B8B26C8E234D629C004ED98C /* MentionCandidateSelectionView.swift */,
B8B26C90234D8CBD004ED98C /* MentionCandidateSelectionViewDelegate.swift */,
B89841E222B7579F00B1BDC6 /* NewConversationVC.swift */,
B8BB82B223947E6B00BA5194 /* NewConversationVCV2.swift */,
B8BB82B223947E6B00BA5194 /* NewConversationVC.swift */,
24BD2608234DA2050008EB0A /* JoinPublicChatVC.swift */,
B893063E2383961A005EAA8E /* ScanQRCodeWrapperVC.swift */,
);
@ -3780,7 +3777,7 @@
files = (
4CC0B59C20EC5F2E00CF6EE0 /* ConversationConfigurationSyncOperation.swift in Sources */,
3461293E1FD1D72B00532771 /* ExperienceUpgradeFinder.swift in Sources */,
B8BB82B323947E6B00BA5194 /* NewConversationVCV2.swift in Sources */,
B8BB82B323947E6B00BA5194 /* NewConversationVC.swift in Sources */,
34C4E2582118957600BEA353 /* WebRTCProto.swift in Sources */,
34D1F0BD1F8D108C0066283D /* AttachmentUploadView.m in Sources */,
452EC6DF205E9E30000E787C /* MediaGalleryViewController.swift in Sources */,
@ -3944,7 +3941,6 @@
45AE48511E0732D6004D96C2 /* TurnServerInfo.swift in Sources */,
34B3F8771E8DF1700035BE1A /* ContactsPicker.swift in Sources */,
45C0DC1B1E68FE9000E04C47 /* UIApplication+OWS.swift in Sources */,
B89841E322B7579F00B1BDC6 /* NewConversationVC.swift in Sources */,
45FBC5C81DF8575700E9B410 /* CallKitCallManager.swift in Sources */,
4539B5861F79348F007141FF /* PushRegistrationManager.swift in Sources */,
45FBC5D11DF8592E00E9B410 /* SignalCall.swift in Sources */,

@ -36,8 +36,13 @@ final class Button : UIButton {
case .unimportant: textColor = Colors.text
case .prominent: textColor = Colors.accent
}
set(.height, to: Values.buttonHeight)
layer.cornerRadius = Values.buttonHeight / 2
let height: CGFloat
switch style {
case .unimportant: height = Values.mediumButtonHeight
case .prominent: height = Values.largeButtonHeight
}
set(.height, to: height)
layer.cornerRadius = height / 2
backgroundColor = fillColor
layer.borderColor = borderColor.cgColor
layer.borderWidth = Values.borderThickness

@ -1,5 +1,5 @@
final class HomeVC : UIViewController, UITableViewDataSource, UITableViewDelegate, UIViewControllerPreviewingDelegate {
final class HomeVC : UIViewController, UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate, UIViewControllerPreviewingDelegate {
private var threadViewModelCache: [String:ThreadViewModel] = [:]
private var isObservingDatabase = true
private var isViewVisible = false { didSet { updateIsObservingDatabase() } }
@ -54,6 +54,7 @@ final class HomeVC : UIViewController, UITableViewDataSource, UITableViewDelegat
// MARK: Lifecycle
override func viewDidLoad() {
SignalApp.shared().homeViewController = self
// Set gradient background
view.backgroundColor = .clear
let gradient = Gradients.defaultLokiBackground
@ -65,7 +66,7 @@ final class HomeVC : UIViewController, UITableViewDataSource, UITableViewDelegat
navigationBar.isTranslucent = false
navigationBar.barTintColor = Colors.navigationBarBackground
}
// Set up the navigation bar buttons
// Set up navigation bar buttons
updateNavigationBarButtons()
// Customize title
let titleLabel = UILabel()
@ -218,6 +219,10 @@ final class HomeVC : UIViewController, UITableViewDataSource, UITableViewDelegat
}
// MARK: Interaction
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
searchBar.resignFirstResponder()
}
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
guard let indexPath = tableView.indexPathForRow(at: location), let thread = self.thread(at: indexPath.row) else { return nil }
previewingContext.sourceRect = tableView.rectForRow(at: indexPath)
@ -302,7 +307,7 @@ final class HomeVC : UIViewController, UITableViewDataSource, UITableViewDelegat
}
@objc func createPrivateChat() {
let newConversationVC = NewConversationVCV2()
let newConversationVC = NewConversationVC()
let navigationController = OWSNavigationController(rootViewController: newConversationVC)
present(navigationController, animated: true, completion: nil)
}

@ -1,71 +1,101 @@
@objc(LKNewConversationVC)
final class NewConversationVC : OWSViewController, OWSQRScannerDelegate {
private lazy var userHexEncodedPublicKey: String = {
let userDefaults = UserDefaults.standard
if let masterHexEncodedPublicKey = userDefaults.string(forKey: "masterDeviceHexEncodedPublicKey") {
return masterHexEncodedPublicKey
} else {
return OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
}
}()
// MARK: Components
private lazy var publicKeyTextField: UITextField = {
let result = UITextField()
result.textColor = Theme.primaryColor
result.font = .ows_dynamicTypeBodyClamped
let placeholder = NSMutableAttributedString(string: NSLocalizedString("Enter a Public Key", comment: ""))
placeholder.addAttribute(.foregroundColor, value: Theme.placeholderColor, range: NSRange(location: 0, length: placeholder.length))
result.attributedPlaceholder = placeholder
result.tintColor = .lokiGreen()
result.keyboardAppearance = .dark
private lazy var publicKeyTextField = TextField(placeholder: NSLocalizedString("Enter public key of recipient", comment: ""))
private lazy var userPublicKeyLabel: UILabel = {
let result = UILabel()
result.textColor = Colors.text
result.font = Fonts.spaceMono(ofSize: Values.mediumFontSize)
result.numberOfLines = 0
result.textAlignment = .center
result.lineBreakMode = .byCharWrapping
return result
}()
private lazy var copyButton: Button = {
let result = Button(style: .unimportant)
result.setTitle(NSLocalizedString("Copy", comment: ""), for: UIControl.State.normal)
result.addTarget(self, action: #selector(copyPublicKey), for: UIControl.Event.touchUpInside)
return result
}()
// MARK: Lifecycle
override func viewDidLoad() {
// Background color & margins
view.backgroundColor = Theme.backgroundColor
view.layoutMargins = .zero
// Navigation bar
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(close))
title = NSLocalizedString("New Conversation", comment: "")
// Separator
let separator = UIView()
separator.autoSetDimension(.height, toSize: 1 / UIScreen.main.scale)
separator.backgroundColor = Theme.hairlineColor
// Explanation label
// Set gradient background
view.backgroundColor = .clear
let gradient = Gradients.defaultLokiBackground
view.setGradient(gradient)
// Set navigation bar background color
if let navigationBar = navigationController?.navigationBar {
navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
navigationBar.shadowImage = UIImage()
navigationBar.isTranslucent = false
navigationBar.barTintColor = Colors.navigationBarBackground
}
// Set up navigation bar buttons
let closeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "X"), style: .plain, target: self, action: #selector(close))
closeButton.tintColor = Colors.text
navigationItem.leftBarButtonItem = closeButton
// Customize title
let titleLabel = UILabel()
titleLabel.text = NSLocalizedString("New Conversation", comment: "")
titleLabel.textColor = Colors.text
titleLabel.font = UIFont.boldSystemFont(ofSize: Values.veryLargeFontSize)
navigationItem.titleView = titleLabel
// Set up explanation label
let explanationLabel = UILabel()
explanationLabel.textColor = Theme.primaryColor
explanationLabel.font = UIFont.ows_dynamicTypeSubheadlineClamped
explanationLabel.text = NSLocalizedString("Enter the public key of the person you'd like to securely message. They can share their public key with you by going into Loki Messenger's in-app settings and clicking \"Share Public Key\".", comment: "")
explanationLabel.textColor = Colors.text.withAlphaComponent(Values.unimportantElementOpacity)
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize)
explanationLabel.text = NSLocalizedString("Users can share their public key by going into their account settings and tapping \"Share Public Key\", or by sharing their QR code.", comment: "")
explanationLabel.numberOfLines = 0
explanationLabel.textAlignment = .center
explanationLabel.lineBreakMode = .byWordWrapping
// QR code button
let qrCodeButtonFont = UIFont.ows_dynamicTypeBodyClamped.ows_mediumWeight()
let qrCodeButtonHeight = qrCodeButtonFont.pointSize * 48 / 17
let qrCodeButton = OWSFlatButton.button(title: NSLocalizedString("Scan a QR Code Instead", comment: ""), font: qrCodeButtonFont, titleColor: .lokiGreen(), backgroundColor: .clear, target: self, selector: #selector(scanQRCode))
qrCodeButton.setBackgroundColors(upColor: .clear, downColor: .clear)
qrCodeButton.autoSetDimension(.height, toSize: qrCodeButtonHeight)
qrCodeButton.button.contentHorizontalAlignment = .left
// Set up separator
let separator = Separator(title: NSLocalizedString("Your Public Key", comment: ""))
// Set up user public key label
userPublicKeyLabel.text = userHexEncodedPublicKey
// Set up share button
let shareButton = Button(style: .unimportant)
shareButton.setTitle(NSLocalizedString("Share", comment: ""), for: UIControl.State.normal)
shareButton.addTarget(self, action: #selector(sharePublicKey), for: UIControl.Event.touchUpInside)
// Set up button container
let buttonContainer = UIStackView(arrangedSubviews: [ copyButton, shareButton ])
buttonContainer.axis = .horizontal
buttonContainer.spacing = Values.mediumSpacing
buttonContainer.distribution = .fillEqually
// Next button
let nextButtonFont = UIFont.ows_dynamicTypeBodyClamped.ows_mediumWeight()
let nextButtonHeight = nextButtonFont.pointSize * 48 / 17
let nextButton = OWSFlatButton.button(title: NSLocalizedString("Next", comment: ""), font: nextButtonFont, titleColor: .white, backgroundColor: .lokiGreen(), target: self, selector: #selector(handleNextButtonTapped))
nextButton.autoSetDimension(.height, toSize: nextButtonHeight)
let nextButton = Button(style: .prominent)
nextButton.setTitle(NSLocalizedString("Next", comment: ""), for: UIControl.State.normal)
nextButton.addTarget(self, action: #selector(handleNextButtonTapped), for: UIControl.Event.touchUpInside)
let nextButtonContainer = UIView()
nextButtonContainer.addSubview(nextButton)
nextButton.pin(.leading, to: .leading, of: nextButtonContainer, withInset: 80)
nextButton.pin(.top, to: .top, of: nextButtonContainer)
nextButtonContainer.pin(.trailing, to: .trailing, of: nextButton, withInset: 80)
nextButtonContainer.pin(.bottom, to: .bottom, of: nextButton)
// Stack view
let stackView = UIStackView(arrangedSubviews: [
publicKeyTextField,
UIView.spacer(withHeight: 8),
separator,
UIView.spacer(withHeight: 24),
explanationLabel,
UIView.spacer(withHeight: 8),
qrCodeButton,
UIView.vStretchingSpacer(),
nextButton
])
let stackView = UIStackView(arrangedSubviews: [ publicKeyTextField, UIView.spacer(withHeight: Values.smallSpacing), explanationLabel, UIView.spacer(withHeight: Values.veryLargeSpacing), separator, UIView.spacer(withHeight: Values.veryLargeSpacing), userPublicKeyLabel, UIView.spacer(withHeight: Values.veryLargeSpacing), buttonContainer, UIView.spacer(withHeight: Values.veryLargeSpacing), nextButtonContainer, UIView.vStretchingSpacer() ])
stackView.axis = .vertical
stackView.alignment = .fill
stackView.layoutMargins = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
stackView.layoutMargins = UIEdgeInsets(top: Values.mediumSpacing, left: Values.largeSpacing, bottom: Values.mediumSpacing, right: Values.largeSpacing)
stackView.isLayoutMarginsRelativeArrangement = true
view.addSubview(stackView)
stackView.autoPinWidthToSuperview()
stackView.autoPin(toTopLayoutGuideOf: self, withInset: 0)
autoPinView(toBottomOfViewControllerOrKeyboard: stackView, avoidNotch: true)
stackView.pin(to: view)
// Dismiss keyboard on tap
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
view.addGestureRecognizer(tapGestureRecognizer)
}
override func viewDidAppear(_ animated: Bool) {
@ -73,30 +103,56 @@ final class NewConversationVC : OWSViewController, OWSQRScannerDelegate {
publicKeyTextField.becomeFirstResponder()
}
// MARK: General
@objc private func dismissKeyboard() {
publicKeyTextField.resignFirstResponder()
}
@objc private func enableCopyButton() {
copyButton.isUserInteractionEnabled = true
UIView.transition(with: copyButton, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.copyButton.setTitle(NSLocalizedString("Copy", comment: ""), for: UIControl.State.normal)
}, completion: nil)
}
// MARK: Interaction
@objc private func close() {
dismiss(animated: true, completion: nil)
}
@objc private func scanQRCode() {
ows_ask(forCameraPermissions: { [weak self] hasCameraAccess in
if hasCameraAccess {
let message = NSLocalizedString("Scan the QR code of the person you'd like to securely message. They can find their QR code by going into Loki Messenger's in-app settings and clicking \"Show QR Code\".", comment: "")
let scanQRCodeWrapperVC = ScanQRCodeWrapperVC(message: message)
scanQRCodeWrapperVC.delegate = self
self?.navigationController!.pushViewController(scanQRCodeWrapperVC, animated: true)
} else {
// Do nothing
}
})
@objc private func copyPublicKey() {
UIPasteboard.general.string = userHexEncodedPublicKey
copyButton.isUserInteractionEnabled = false
UIView.transition(with: copyButton, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.copyButton.setTitle(NSLocalizedString("Copied", comment: ""), for: UIControl.State.normal)
}, completion: nil)
Timer.scheduledTimer(timeInterval: 4, target: self, selector: #selector(enableCopyButton), userInfo: nil, repeats: false)
}
func controller(_ controller: OWSQRCodeScanningViewController, didDetectQRCodeWith string: String) {
Analytics.shared.track("QR Code Scanned")
let hexEncodedPublicKey = string
startNewConversationIfPossible(with: hexEncodedPublicKey)
@objc private func sharePublicKey() {
let shareVC = UIActivityViewController(activityItems: [ userHexEncodedPublicKey ], applicationActivities: nil)
navigationController?.present(shareVC, animated: true, completion: nil)
}
// @objc private func scanQRCode() {
// ows_ask(forCameraPermissions: { [weak self] hasCameraAccess in
// if hasCameraAccess {
// let message = NSLocalizedString("Scan the QR code of the person you'd like to securely message. They can find their QR code by going into Loki Messenger's in-app settings and clicking \"Show QR Code\".", comment: "")
// let scanQRCodeWrapperVC = ScanQRCodeWrapperVC(message: message)
// scanQRCodeWrapperVC.delegate = self
// self?.navigationController!.pushViewController(scanQRCodeWrapperVC, animated: true)
// } else {
// // Do nothing
// }
// })
// }
//
// func controller(_ controller: OWSQRCodeScanningViewController, didDetectQRCodeWith string: String) {
// Analytics.shared.track("QR Code Scanned")
// let hexEncodedPublicKey = string
// startNewConversationIfPossible(with: hexEncodedPublicKey)
// }
@objc private func handleNextButtonTapped() {
let hexEncodedPublicKey = publicKeyTextField.text?.trimmingCharacters(in: .whitespaces) ?? ""
startNewConversationIfPossible(with: hexEncodedPublicKey)
@ -109,9 +165,8 @@ final class NewConversationVC : OWSViewController, OWSQRScannerDelegate {
presentAlert(alert)
} else {
let thread = TSContactThread.getOrCreateThread(contactId: hexEncodedPublicKey)
Analytics.shared.track("New Conversation Started")
SignalApp.shared().presentConversation(for: thread, action: .compose, animated: false)
presentingViewController!.dismiss(animated: true, completion: nil)
SignalApp.shared().presentConversation(for: thread, action: .compose, animated: false)
}
}
}

@ -1,168 +0,0 @@
@objc(LKNewConversationVCV2)
final class NewConversationVCV2 : OWSViewController, OWSQRScannerDelegate {
private lazy var userHexEncodedPublicKey: String = {
let userDefaults = UserDefaults.standard
if let masterHexEncodedPublicKey = userDefaults.string(forKey: "masterDeviceHexEncodedPublicKey") {
return masterHexEncodedPublicKey
} else {
return OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
}
}()
// MARK: Components
private lazy var publicKeyTextField = TextField(placeholder: NSLocalizedString("Enter public key of recipient", comment: ""))
private lazy var userPublicKeyLabel: UILabel = {
let result = UILabel()
result.textColor = Colors.text
result.font = Fonts.spaceMono(ofSize: Values.mediumFontSize)
result.numberOfLines = 0
result.textAlignment = .center
result.lineBreakMode = .byCharWrapping
return result
}()
private lazy var copyButton: Button = {
let result = Button(style: .unimportant)
result.setTitle(NSLocalizedString("Copy", comment: ""), for: UIControl.State.normal)
return result
}()
// MARK: Lifecycle
override func viewDidLoad() {
// Set gradient background
view.backgroundColor = .clear
let gradient = Gradients.defaultLokiBackground
view.setGradient(gradient)
// Set navigation bar background color
if let navigationBar = navigationController?.navigationBar {
navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
navigationBar.shadowImage = UIImage()
navigationBar.isTranslucent = false
navigationBar.barTintColor = Colors.navigationBarBackground
}
// Set up the navigation bar buttons
let closeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "X"), style: .plain, target: self, action: #selector(close))
closeButton.tintColor = Colors.text
navigationItem.leftBarButtonItem = closeButton
// Customize title
let titleLabel = UILabel()
titleLabel.text = NSLocalizedString("New Conversation", comment: "")
titleLabel.textColor = Colors.text
titleLabel.font = UIFont.boldSystemFont(ofSize: Values.veryLargeFontSize)
navigationItem.titleView = titleLabel
// Set up explanation label
let explanationLabel = UILabel()
explanationLabel.textColor = Colors.text.withAlphaComponent(Values.unimportantElementOpacity)
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize)
explanationLabel.text = NSLocalizedString("Users can share their public key by going into their account settings and tapping \"Share Public Key\", or by sharing their QR code.", comment: "")
explanationLabel.numberOfLines = 0
explanationLabel.textAlignment = .center
explanationLabel.lineBreakMode = .byWordWrapping
// Set up separator
let separator = Separator(title: NSLocalizedString("Your Public Key", comment: ""))
separator.set(.height, to: 25)
// Set up user public key label
userPublicKeyLabel.text = userHexEncodedPublicKey
// Set up share button
let shareButton = Button(style: .unimportant)
shareButton.setTitle(NSLocalizedString("Share", comment: ""), for: UIControl.State.normal)
// Set up button container
let buttonContainer = UIStackView(arrangedSubviews: [ copyButton, shareButton ])
buttonContainer.axis = .horizontal
buttonContainer.spacing = Values.mediumSpacing
buttonContainer.distribution = .fillEqually
// Next button
let nextButton = Button(style: .prominent)
nextButton.setTitle(NSLocalizedString("Next", comment: ""), for: UIControl.State.normal)
// Stack view
let stackView = UIStackView(arrangedSubviews: [ publicKeyTextField, UIView.spacer(withHeight: Values.smallSpacing), explanationLabel, UIView.spacer(withHeight: Values.veryLargeSpacing), separator, UIView.spacer(withHeight: Values.veryLargeSpacing), userPublicKeyLabel, UIView.spacer(withHeight: Values.veryLargeSpacing), buttonContainer, UIView.spacer(withHeight: Values.veryLargeSpacing), nextButton, UIView.vStretchingSpacer() ])
stackView.axis = .vertical
stackView.alignment = .fill
stackView.layoutMargins = UIEdgeInsets(top: Values.mediumSpacing, left: Values.largeSpacing, bottom: Values.mediumSpacing, right: Values.largeSpacing)
stackView.isLayoutMarginsRelativeArrangement = true
view.addSubview(stackView)
stackView.pin(to: view)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
publicKeyTextField.becomeFirstResponder()
}
// MARK: General
@objc private func enableCopyButton() {
// copyButton.isUserInteractionEnabled = true
// UIView.transition(with: copyButton, duration: 0.25, options: .transitionCrossDissolve, animations: {
// self.copyButton.setTitle(NSLocalizedString("Copy", comment: ""))
// }, completion: nil)
}
// MARK: Interaction
@objc private func close() {
dismiss(animated: true, completion: nil)
}
@objc private func copyPublicKey() {
// UIPasteboard.general.string = userHexEncodedPublicKey
// copyButton.isUserInteractionEnabled = false
// UIView.transition(with: copyButton, duration: 0.25, options: .transitionCrossDissolve, animations: {
// self.copyButton.setTitle(NSLocalizedString("Copied ", comment: ""))
// }, completion: nil)
// Timer.scheduledTimer(timeInterval: 4, target: self, selector: #selector(enableCopyButton), userInfo: nil, repeats: false)
}
@objc private func sharePublicKey() {
let shareVC = UIActivityViewController(activityItems: [ userHexEncodedPublicKey ], applicationActivities: nil)
present(shareVC, animated: true, completion: nil)
// NSString *hexEncodedPublicKey;
// NSString *masterDeviceHexEncodedPublicKey = [NSUserDefaults.standardUserDefaults stringForKey:@"masterDeviceHexEncodedPublicKey"];
// if (masterDeviceHexEncodedPublicKey != nil) {
// hexEncodedPublicKey = masterDeviceHexEncodedPublicKey;
// } else {
// hexEncodedPublicKey = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey;
// }
// UIActivityViewController *shareVC = [[UIActivityViewController alloc] initWithActivityItems:@[ hexEncodedPublicKey ] applicationActivities:nil];
// [self presentViewController:shareVC animated:YES completion:nil];
// [LKAnalytics.shared track:@"Public Key Shared"];
}
// @objc private func scanQRCode() {
// ows_ask(forCameraPermissions: { [weak self] hasCameraAccess in
// if hasCameraAccess {
// let message = NSLocalizedString("Scan the QR code of the person you'd like to securely message. They can find their QR code by going into Loki Messenger's in-app settings and clicking \"Show QR Code\".", comment: "")
// let scanQRCodeWrapperVC = ScanQRCodeWrapperVC(message: message)
// scanQRCodeWrapperVC.delegate = self
// self?.navigationController!.pushViewController(scanQRCodeWrapperVC, animated: true)
// } else {
// // Do nothing
// }
// })
// }
//
// func controller(_ controller: OWSQRCodeScanningViewController, didDetectQRCodeWith string: String) {
// Analytics.shared.track("QR Code Scanned")
// let hexEncodedPublicKey = string
// startNewConversationIfPossible(with: hexEncodedPublicKey)
// }
@objc private func handleNextButtonTapped() {
let hexEncodedPublicKey = publicKeyTextField.text?.trimmingCharacters(in: .whitespaces) ?? ""
startNewConversationIfPossible(with: hexEncodedPublicKey)
}
private func startNewConversationIfPossible(with hexEncodedPublicKey: String) {
if !ECKeyPair.isValidHexEncodedPublicKey(candidate: hexEncodedPublicKey) {
let alert = UIAlertController(title: NSLocalizedString("Invalid Public Key", comment: ""), message: NSLocalizedString("Please check the public key you entered and try again.", comment: ""), preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default, handler: nil))
presentAlert(alert)
} else {
let thread = TSContactThread.getOrCreateThread(contactId: hexEncodedPublicKey)
Analytics.shared.track("New Conversation Started")
SignalApp.shared().presentConversation(for: thread, action: .compose, animated: false)
presentingViewController!.dismiss(animated: true, completion: nil)
}
}
}

@ -43,12 +43,7 @@ final class ProfilePictureView : UIView {
imageView.removeConstraint(imageViewHeightConstraint)
}
func getProfilePicture(of size: CGFloat, for hexEncodedPublicKey: String) -> UIImage {
let userHexEncodedPublicKey = OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
if hexEncodedPublicKey == userHexEncodedPublicKey, let profilePicture = OWSProfileManager.shared().localProfileAvatarImage() {
return profilePicture
} else {
return Identicon.generateIcon(string: hexEncodedPublicKey, size: size)
}
return OWSProfileManager.shared().profileAvatar(forRecipientId: hexEncodedPublicKey) ?? Identicon.generateIcon(string: hexEncodedPublicKey, size: size)
}
let size: CGFloat
if let additionalHexEncodedPublicKey = additionalHexEncodedPublicKey {

@ -15,7 +15,8 @@ final class Values : NSObject {
@objc static let massiveFontSize = CGFloat(50)
// MARK: - Element Sizes
@objc static let buttonHeight = CGFloat(34)
@objc static let mediumButtonHeight = CGFloat(34)
@objc static let largeButtonHeight = CGFloat(45)
@objc static let accentLineThickness = CGFloat(4)
@objc static let verySmallProfilePictureSize = CGFloat(26)
@objc static let smallProfilePictureSize = CGFloat(35)

@ -2684,5 +2684,6 @@
"Users can share their public key by going into their account settings and tapping \"Share Public Key\", or by sharing their QR code." = "Users can share their public key by going into their account settings and tapping \"Share Public Key\", or by sharing their QR code.";
"Your Public Key" = "Your Public Key";
"Copy" = "Copy";
"Copied" = "Copied";
"Share" = "Share";
"Next" = "Next";

Loading…
Cancel
Save