Update device linking modal for linkee

pull/55/head
Niels Andriesse 5 years ago
parent 16eb1855f0
commit 395d167f56

@ -570,6 +570,7 @@
B86BD08123399883000F5AE3 /* QRCodeModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08023399883000F5AE3 /* QRCodeModal.swift */; };
B86BD08423399ACF000F5AE3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08323399ACF000F5AE3 /* Modal.swift */; };
B86BD08623399CEF000F5AE3 /* SeedModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08523399CEF000F5AE3 /* SeedModal.swift */; };
B86BD08C2339AE43000F5AE3 /* DeviceLinkingModalDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08B2339AE43000F5AE3 /* DeviceLinkingModalDelegate.swift */; };
B885D5F4233491AB00EE0D8E /* DeviceLinkingModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B885D5F3233491AB00EE0D8E /* DeviceLinkingModal.swift */; };
B885D5F62334A32100EE0D8E /* UIView+Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = B885D5F52334A32100EE0D8E /* UIView+Constraint.swift */; };
B891105C2320872800F15FCC /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B891105B2320872800F15FCC /* GoogleService-Info.plist */; };
@ -1377,6 +1378,7 @@
B86BD08023399883000F5AE3 /* QRCodeModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeModal.swift; sourceTree = "<group>"; };
B86BD08323399ACF000F5AE3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; };
B86BD08523399CEF000F5AE3 /* SeedModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedModal.swift; sourceTree = "<group>"; };
B86BD08B2339AE43000F5AE3 /* DeviceLinkingModalDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceLinkingModalDelegate.swift; sourceTree = "<group>"; };
B885D5F3233491AB00EE0D8E /* DeviceLinkingModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceLinkingModal.swift; sourceTree = "<group>"; };
B885D5F52334A32100EE0D8E /* UIView+Constraint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Constraint.swift"; sourceTree = "<group>"; };
B891105B2320872800F15FCC /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
@ -2666,6 +2668,7 @@
isa = PBXGroup;
children = (
B885D5F3233491AB00EE0D8E /* DeviceLinkingModal.swift */,
B86BD08B2339AE43000F5AE3 /* DeviceLinkingModalDelegate.swift */,
B86BD08023399883000F5AE3 /* QRCodeModal.swift */,
B86BD08523399CEF000F5AE3 /* SeedModal.swift */,
);
@ -3910,6 +3913,7 @@
45E5A6991F61E6DE001E4A8A /* MarqueeLabel.swift in Sources */,
34D1F0B01F867BFC0066283D /* OWSSystemMessageCell.m in Sources */,
45A663C51F92EC760027B59E /* GroupTableViewCell.swift in Sources */,
B86BD08C2339AE43000F5AE3 /* DeviceLinkingModalDelegate.swift in Sources */,
34CA631B2097806F00E526A0 /* OWSContactShareView.m in Sources */,
B86BD08423399ACF000F5AE3 /* Modal.swift in Sources */,
34D1F0861F8678AA0066283D /* ConversationViewController.m in Sources */,

@ -39,7 +39,7 @@ final class FriendRequestView : UIView {
private lazy var buttonFont = UIFont.ows_dynamicTypeBodyClamped.ows_mediumWeight()
private lazy var buttonHeight = buttonFont.pointSize * 48 / 17
// MARK: Initialization
// MARK: Lifecycle
@objc init(message: TSMessage) {
self.message = message
super.init(frame: CGRect.zero)

@ -1,7 +1,7 @@
// TODO: Split this into multiple VCs
final class SeedVC : OnboardingBaseViewController {
final class SeedVC : OnboardingBaseViewController, DeviceLinkingModalDelegate {
private var mode: Mode = .register { didSet { if mode != oldValue { handleModeChanged() } } }
private var seed: Data! { didSet { updateMnemonic() } }
private var mnemonic: String! { didSet { handleMnemonicChanged() } }
@ -124,7 +124,7 @@ final class SeedVC : OnboardingBaseViewController {
}()
private lazy var explanationLabel3: UILabel = {
let result = createExplanationLabel(text: NSLocalizedString("Link an existing device by going into Loki Messenger's in-app settings and clicking \"Link Device\".", comment: ""))
let result = createExplanationLabel(text: NSLocalizedString("Link to an existing device by going into Loki Messenger's in-app settings and clicking \"Link Device\".", comment: ""))
result.accessibilityIdentifier = "onboarding.keyPairStep.explanationLabel3"
result.textColor = Theme.primaryColor
var fontTraits = result.font.fontDescriptor.symbolicTraits
@ -302,7 +302,7 @@ final class SeedVC : OnboardingBaseViewController {
var seed: Data
let mode = self.mode
switch mode {
case .register, .link: seed = self.seed
case .register: seed = self.seed
case .restore:
let mnemonic = mnemonicTextField.text!
do {
@ -313,6 +313,13 @@ final class SeedVC : OnboardingBaseViewController {
errorLabel1Spacer.isHidden = false
return errorLabel1.text = error.errorDescription
}
case .link:
seed = self.seed
let hexEncodedPublicKey = masterHexEncodedPublicKeyTextField.text!.trimmingCharacters(in: CharacterSet.whitespaces)
if !ECKeyPair.isValidHexEncodedPublicKey(candidate: hexEncodedPublicKey) {
errorLabel2Spacer.isHidden = false
return errorLabel2.text = NSLocalizedString("Invalid public key", comment: "")
}
}
// Use KVC to access dbConnection even though it's private
let identityManager = OWSIdentityManager.shared()
@ -330,8 +337,17 @@ final class SeedVC : OnboardingBaseViewController {
case .link: Analytics.shared.track("Device Linked")
}
if mode == .link {
let deviceLinkingModal = DeviceLinkingModal(mode: .slave, delegate: self)
deviceLinkingModal.modalPresentationStyle = .overFullScreen
present(deviceLinkingModal, animated: true, completion: nil)
} else {
onboardingController.pushDisplayNameVC(from: self)
}
onboardingController.pushDisplayNameVC(from: self)
}
func handleDeviceLinked() {
TSAccountManager.sharedInstance().didRegister()
UserDefaults.standard.set(true, forKey: "didUpdateForMainnet")
onboardingController.verificationDidComplete(fromView: self)
}
}

@ -2,8 +2,13 @@ import NVActivityIndicatorView
@objc(LKDeviceLinkingModal)
final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
private let mode: Mode
private let delegate: DeviceLinkingModalDelegate?
private var deviceLink: DeviceLink?
// MARK: Types
enum Mode : String { case master, slave }
// MARK: Components
private lazy var topSpacer = UIView.spacer(withHeight: 8)
@ -13,7 +18,6 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
let result = UILabel()
result.textColor = Theme.primaryColor
result.font = UIFont.ows_dynamicTypeHeadlineClamped
result.text = NSLocalizedString("Waiting for Device", comment: "")
result.numberOfLines = 0
result.lineBreakMode = .byWordWrapping
result.textAlignment = .center
@ -24,7 +28,6 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
let result = UILabel()
result.textColor = Theme.primaryColor
result.font = UIFont.ows_dynamicTypeCaption1Clamped
result.text = NSLocalizedString("Click the \"Link Device\" button on your other device to start the linking process", comment: "")
result.numberOfLines = 0
result.lineBreakMode = .byWordWrapping
result.textAlignment = .center
@ -49,6 +52,23 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
}()
// MARK: Lifecycle
init(mode: Mode, delegate: DeviceLinkingModalDelegate?) {
self.mode = mode
if mode == .slave {
guard delegate != nil else { preconditionFailure("Missing delegate for device linking modal in slave mode.") }
}
self.delegate = delegate
super.init(nibName: nil, bundle: nil)
}
@objc convenience init(modeAsString: String, delegate: DeviceLinkingModalDelegate?) {
guard let mode = Mode(rawValue: modeAsString) else { preconditionFailure("Invalid mode: \(modeAsString).") }
self.init(mode: mode, delegate: delegate)
}
required init?(coder: NSCoder) { preconditionFailure() }
override init(nibName: String?, bundle: Bundle?) { preconditionFailure() }
override func viewDidLoad() {
super.viewDidLoad()
let _ = DeviceLinkingSession.startListeningForLinkingRequests(with: self)
@ -64,7 +84,19 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
buttonStackView.distribution = .fillEqually
spinner.set(.height, to: 64)
spinner.startAnimating()
mnemonicLabel.isHidden = true
titleLabel.text = {
switch mode {
case .master: return NSLocalizedString("Waiting for Device", comment: "")
case .slave: return NSLocalizedString("Waiting for Authorization", comment: "")
}
}()
subtitleLabel.text = {
switch mode {
case .master: return NSLocalizedString("Click the \"Link Device\" button on your other device to start the linking process", comment: "")
case .slave: return NSLocalizedString("Please verify that the words below match the ones shown on your other device.", comment: "")
}
}()
mnemonicLabel.isHidden = (mode == .master)
let buttonHeight = cancelButton.button.titleLabel!.font.pointSize * 48 / 17
authorizeButton.set(.height, to: buttonHeight)
cancelButton.set(.height, to: buttonHeight)

@ -0,0 +1,6 @@
@objc(LKDeviceLinkingModalDelegate)
protocol DeviceLinkingModalDelegate {
func handleDeviceLinked()
}

@ -515,7 +515,7 @@
- (void)linkDevice
{
LKDeviceLinkingModal *deviceLinkingModal = [LKDeviceLinkingModal new];
LKDeviceLinkingModal *deviceLinkingModal = [[LKDeviceLinkingModal alloc] initWithModeAsString:@"master" delegate:nil];
deviceLinkingModal.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:deviceLinkingModal animated:YES completion:nil];
}

@ -2623,5 +2623,9 @@
"Copy Public Key" = "Copy Public Key";
"Link Device" = "Link Device";
"Waiting for Device" = "Waiting for Device";
"Waiting for Authorization" = "Waiting for Authorization";
"Click the \"Link Device\" button on your other device to start the linking process" = "Click the \"Link Device\" button on your other device to start the linking process";
"Linking Request Received" = "Linking Request Received";
"Invalid public key" = "Invalid public key";
"Please verify that the words below match the ones shown on your other device." = "Please verify that the words below match the ones shown on your other device.";
"Link to an existing device by going into Loki Messenger's in-app settings and clicking \"Link Device\"." = "Link to an existing device by going into Loki Messenger's in-app settings and clicking \"Link Device\".";

Loading…
Cancel
Save