diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index d88236ef9..5139d2609 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -569,6 +569,7 @@ B82584A02315024B001B41CB /* LokiRSSFeedPoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = B825849F2315024B001B41CB /* LokiRSSFeedPoller.swift */; }; B82B40882399EB0E00A248E7 /* LandingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82B40872399EB0E00A248E7 /* LandingVC.swift */; }; B82B408A2399EC0600A248E7 /* FakeChatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82B40892399EC0600A248E7 /* FakeChatView.swift */; }; + B82B408C239A068800A248E7 /* PublicKeyVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82B408B239A068800A248E7 /* PublicKeyVC.swift */; }; B846365B22B7418B00AF1514 /* Identicon+ObjC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */; }; B84664F5235022F30083A1CD /* MentionUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84664F4235022F30083A1CD /* MentionUtilities.swift */; }; B86BD08423399ACF000F5AE3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08323399ACF000F5AE3 /* Modal.swift */; }; @@ -1401,6 +1402,7 @@ B825849F2315024B001B41CB /* LokiRSSFeedPoller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LokiRSSFeedPoller.swift; sourceTree = ""; }; B82B40872399EB0E00A248E7 /* LandingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LandingVC.swift; sourceTree = ""; }; B82B40892399EC0600A248E7 /* FakeChatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FakeChatView.swift; sourceTree = ""; }; + B82B408B239A068800A248E7 /* PublicKeyVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublicKeyVC.swift; sourceTree = ""; }; B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Identicon+ObjC.swift"; sourceTree = ""; }; B84664F4235022F30083A1CD /* MentionUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentionUtilities.swift; sourceTree = ""; }; B86BD08323399ACF000F5AE3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = ""; }; @@ -2802,11 +2804,12 @@ B80C6B582384C4E700FDBC8B /* DeviceNameModal.swift */, B80C6B5A2384C7F900FDBC8B /* DeviceNameModalDelegate.swift */, B8BB82A4238F627000BA5194 /* HomeVC.swift */, + B8CCF63E23975CFB0091D419 /* JoinPublicChatVC.swift */, B82B40872399EB0E00A248E7 /* LandingVC.swift */, B86BD08323399ACF000F5AE3 /* Modal.swift */, B8CCF63623961D6D0091D419 /* NewPrivateChatVC.swift */, B894D0742339EDCF00B4D94D /* NukeDataModal.swift */, - B8CCF63E23975CFB0091D419 /* JoinPublicChatVC.swift */, + B82B408B239A068800A248E7 /* PublicKeyVC.swift */, B886B4A62398B23E00211ABE /* QRCodeVC.swift */, B893063E2383961A005EAA8E /* ScanQRCodeWrapperVC.swift */, B86BD08523399CEF000F5AE3 /* SeedModal.swift */, @@ -3922,6 +3925,7 @@ 4CC613362227A00400E21A3A /* ConversationSearch.swift in Sources */, 340FC8B2204DAC8D007AEB0F /* AdvancedSettingsTableViewController.m in Sources */, 452B999020A34B6B006F2F9E /* AddContactShareToExistingContactViewController.swift in Sources */, + B82B408C239A068800A248E7 /* PublicKeyVC.swift in Sources */, 346129991FD1E4DA00532771 /* SignalApp.m in Sources */, 3496957121A301A100DCFE74 /* OWSBackupImportJob.m in Sources */, 34BECE301F7ABCF800D7438D /* GifPickerLayout.swift in Sources */, diff --git a/Signal/src/Loki/Redesign/Components/FakeChatView.swift b/Signal/src/Loki/Redesign/Components/FakeChatView.swift index 64fdf6991..5c2272c8a 100644 --- a/Signal/src/Loki/Redesign/Components/FakeChatView.swift +++ b/Signal/src/Loki/Redesign/Components/FakeChatView.swift @@ -46,6 +46,9 @@ final class FakeChatView : UIView { let bubbleView = UIView() bubbleView.set(.width, to: Values.fakeChatBubbleWidth) bubbleView.layer.cornerRadius = Values.fakeChatBubbleCornerRadius + bubbleView.layer.shadowColor = UIColor.black.cgColor + bubbleView.layer.shadowRadius = 8 + bubbleView.layer.shadowOpacity = 0.64 let backgroundColor = wasSentByCurrentUser ? Colors.accent : Colors.fakeChatBubbleBackground bubbleView.backgroundColor = backgroundColor let label = UILabel() @@ -56,7 +59,7 @@ final class FakeChatView : UIView { label.lineBreakMode = .byWordWrapping label.text = text bubbleView.addSubview(label) - label.pin(to: bubbleView, withInset: Values.smallSpacing) + label.pin(to: bubbleView, withInset: 12) result.addSubview(bubbleView) bubbleView.pin(.top, to: .top, of: result) result.pin(.bottom, to: .bottom, of: bubbleView) diff --git a/Signal/src/Loki/Redesign/Style Guide/Values.swift b/Signal/src/Loki/Redesign/Style Guide/Values.swift index 0f9516330..dfbb30483 100644 --- a/Signal/src/Loki/Redesign/Style Guide/Values.swift +++ b/Signal/src/Loki/Redesign/Style Guide/Values.swift @@ -9,6 +9,7 @@ final class Values : NSObject { @objc static let modalBackgroundOpacity = CGFloat(0.75) // MARK: - Font Sizes + @objc static let verySmallFontSize = CGFloat(10) @objc static let smallFontSize = CGFloat(13) @objc static let mediumFontSize = CGFloat(15) @objc static let largeFontSize = CGFloat(20) @@ -37,7 +38,7 @@ final class Values : NSObject { @objc static let modalButtonCornerRadius = CGFloat(5) @objc static let fakeChatBubbleWidth = CGFloat(224) @objc static let fakeChatBubbleCornerRadius = CGFloat(10) - @objc static let fakeChatViewHeight = CGFloat(300) + @objc static let fakeChatViewHeight = CGFloat(320) // MARK: - Distances @objc static let verySmallSpacing = CGFloat(4) @@ -47,7 +48,7 @@ final class Values : NSObject { @objc static let veryLargeSpacing = CGFloat(35) @objc static let massiveSpacing = CGFloat(64) @objc static let newConversationButtonBottomOffset = CGFloat(52) - @objc static let restoreButtonBottomOffset = CGFloat(52) + @objc static let onboardingButtonBottomOffset = CGFloat(72) // MARK: - Animation Values @objc static let fakeChatStartDelay: TimeInterval = 2 diff --git a/Signal/src/Loki/Redesign/View Controllers/LandingVC.swift b/Signal/src/Loki/Redesign/View Controllers/LandingVC.swift index 98ab49f2e..70f9744f3 100644 --- a/Signal/src/Loki/Redesign/View Controllers/LandingVC.swift +++ b/Signal/src/Loki/Redesign/View Controllers/LandingVC.swift @@ -42,21 +42,24 @@ final class LandingVC : UIViewController { // Set up main stack view let mainStackView = UIStackView(arrangedSubviews: [ titleLabelContainer, fakeChatView ]) mainStackView.axis = .vertical - mainStackView.spacing = Values.mediumSpacing // The fake chat view has an internal top margin + mainStackView.spacing = Values.mediumSpacing // Not largeSpacing as the fake chat view has an internal top margin mainStackView.alignment = .fill view.addSubview(mainStackView) mainStackView.pin(.leading, to: .leading, of: view) view.pin(.trailing, to: .trailing, of: mainStackView) mainStackView.set(.height, to: Values.fakeChatViewHeight) - mainStackView.center(.vertical, in: view) + let verticalCenteringConstraint = mainStackView.center(.vertical, in: view) + verticalCenteringConstraint.constant = -20 // Set up view let screen = UIScreen.main.bounds + view.frame = screen view.set(.width, to: screen.width) view.set(.height, to: screen.height) // Set up register button let registerButton = Button(style: .prominentFilled, size: .large) registerButton.setTitle(NSLocalizedString("Create Account", comment: ""), for: UIControl.State.normal) registerButton.titleLabel!.font = .boldSystemFont(ofSize: Values.mediumFontSize) + registerButton.addTarget(self, action: #selector(register), for: UIControl.Event.touchUpInside) // Set up restore button let restoreButton = Button(style: .prominentOutline, size: .large) restoreButton.setTitle(NSLocalizedString("Continue your Loki Messenger", comment: ""), for: UIControl.State.normal) @@ -69,6 +72,12 @@ final class LandingVC : UIViewController { view.addSubview(buttonStackView) buttonStackView.pin(.leading, to: .leading, of: view, withInset: Values.massiveSpacing) view.pin(.trailing, to: .trailing, of: buttonStackView, withInset: Values.massiveSpacing) - view.pin(.bottom, to: .bottom, of: buttonStackView, withInset: Values.restoreButtonBottomOffset) + view.pin(.bottom, to: .bottom, of: buttonStackView, withInset: Values.onboardingButtonBottomOffset) + } + + // MARK: Interaction + @objc private func register() { + let publicKeyVC = PublicKeyVC() + navigationController!.pushViewController(publicKeyVC, animated: true) } } diff --git a/Signal/src/Loki/Redesign/View Controllers/PublicKeyVC.swift b/Signal/src/Loki/Redesign/View Controllers/PublicKeyVC.swift new file mode 100644 index 000000000..0757af9f0 --- /dev/null +++ b/Signal/src/Loki/Redesign/View Controllers/PublicKeyVC.swift @@ -0,0 +1,164 @@ + +final class PublicKeyVC : UIViewController { + private var seed: Data! { didSet { updateKeyPair() } } + private var keyPair: ECKeyPair! { didSet { updatePublicKeyLabel() } } + + // MARK: Components + private lazy var publicKeyLabel: UILabel = { + let result = UILabel() + result.textColor = Colors.text + result.font = Fonts.spaceMono(ofSize: Values.largeFontSize) + result.numberOfLines = 0 + result.textAlignment = .center + result.lineBreakMode = .byCharWrapping + return result + }() + + private lazy var copyPublicKeyButton: Button = { + let result = Button(style: .prominentOutline, size: .large) + result.setTitle(NSLocalizedString("Copy Public Key", comment: ""), for: UIControl.State.normal) + result.addTarget(self, action: #selector(copyPublicKey), for: UIControl.Event.touchUpInside) + return result + }() + + // MARK: Settings + override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } + + // MARK: Lifecycle + override func viewDidLoad() { + // Set gradient background + view.backgroundColor = .clear + let gradient = Gradients.defaultLokiBackground + view.setGradient(gradient) + // Set up navigation bar + let navigationBar = navigationController!.navigationBar + navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default) + navigationBar.shadowImage = UIImage() + navigationBar.isTranslucent = false + navigationBar.barTintColor = Colors.navigationBarBackground + // Set up logo image view + let logoImageView = UIImageView() + logoImageView.image = #imageLiteral(resourceName: "Loki") + logoImageView.contentMode = .scaleAspectFit + logoImageView.set(.width, to: 32) + logoImageView.set(.height, to: 32) + navigationItem.titleView = logoImageView + // Set up title label + let titleLabel = UILabel() + titleLabel.textColor = Colors.text + titleLabel.font = .boldSystemFont(ofSize: Values.veryLargeFontSize) + titleLabel.text = NSLocalizedString("Say hello to your unique public key", comment: "") + titleLabel.numberOfLines = 0 + titleLabel.lineBreakMode = .byWordWrapping + // Set up explanation label + let explanationLabel = UILabel() + explanationLabel.textColor = Colors.text + explanationLabel.font = .systemFont(ofSize: Values.smallFontSize) + explanationLabel.text = "explanation explanation explanation explanation explanation explanation explanation explanation explanation explanation explanation explanation explanation explanation explanation explanation" + explanationLabel.numberOfLines = 0 + explanationLabel.lineBreakMode = .byWordWrapping + // Set up public key label container + let publicKeyLabelContainer = UIView() + publicKeyLabelContainer.addSubview(publicKeyLabel) + publicKeyLabel.pin(to: publicKeyLabelContainer, withInset: Values.mediumSpacing) + publicKeyLabelContainer.layer.cornerRadius = Values.textFieldCornerRadius + publicKeyLabelContainer.layer.borderWidth = Values.borderThickness + publicKeyLabelContainer.layer.borderColor = Colors.text.cgColor + // Set up register button + let registerButton = Button(style: .prominentFilled, size: .large) + registerButton.setTitle(NSLocalizedString("Continue", comment: ""), for: UIControl.State.normal) + registerButton.titleLabel!.font = .boldSystemFont(ofSize: Values.mediumFontSize) + registerButton.addTarget(self, action: #selector(register), for: UIControl.Event.touchUpInside) + // Set up legal label + let legalLabel = UILabel() + legalLabel.textColor = Colors.text + legalLabel.font = .systemFont(ofSize: Values.verySmallFontSize) + let legalLabelText = "By using this service, you agree to our Terms and Conditions and Privacy Statement" + let attributedLegalLabelText = NSMutableAttributedString(string: legalLabelText) + attributedLegalLabelText.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: Values.verySmallFontSize), range: (legalLabelText as NSString).range(of: "Terms and Conditions")) + attributedLegalLabelText.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: Values.verySmallFontSize), range: (legalLabelText as NSString).range(of: "Privacy Statement")) + legalLabel.attributedText = attributedLegalLabelText + legalLabel.numberOfLines = 0 + legalLabel.textAlignment = .center + legalLabel.lineBreakMode = .byWordWrapping + // Set up button stack view + let buttonStackView = UIStackView(arrangedSubviews: [ registerButton, copyPublicKeyButton, legalLabel ]) + buttonStackView.axis = .vertical + buttonStackView.spacing = Values.mediumSpacing + buttonStackView.alignment = .fill + buttonStackView.layoutMargins = UIEdgeInsets(top: 0, left: Values.largeSpacing, bottom: Values.mediumSpacing, right: Values.largeSpacing) + buttonStackView.isLayoutMarginsRelativeArrangement = true + // Set up main stack view + let topSpacer = UIView() + let bottomSpacer = UIView() + let mainStackView = UIStackView(arrangedSubviews: [ topSpacer, titleLabel, explanationLabel, publicKeyLabelContainer, bottomSpacer, buttonStackView ]) + mainStackView.axis = .vertical + mainStackView.spacing = Values.largeSpacing + mainStackView.alignment = .fill + mainStackView.layoutMargins = UIEdgeInsets(top: 0, left: Values.veryLargeSpacing, bottom: 0, right: Values.veryLargeSpacing) + mainStackView.isLayoutMarginsRelativeArrangement = true + view.addSubview(mainStackView) + topSpacer.heightAnchor.constraint(equalTo: bottomSpacer.heightAnchor, multiplier: 1).isActive = true + mainStackView.pin(to: view) +// mainStackView.pin(.leading, to: .leading, of: view, withInset: Values.veryLargeSpacing) +// view.pin(.trailing, to: .trailing, of: mainStackView, withInset: Values.veryLargeSpacing) +// let verticalCenteringConstraint = mainStackView.center(.vertical, in: view) +// verticalCenteringConstraint.constant = -20 + // Set up view +// let screen = UIScreen.main.bounds +// view.set(.width, to: screen.width) +// view.set(.height, to: screen.height) +// buttonStackView.pin(.leading, to: .leading, of: view, withInset: Values.massiveSpacing) +// view.pin(.trailing, to: .trailing, of: buttonStackView, withInset: Values.massiveSpacing) +// view.pin(.bottom, to: .bottom, of: buttonStackView, withInset: Values.onboardingButtonBottomOffset) + // Peform initial seed update + updateSeed() + } + + // MARK: General + @objc private func enableCopyButton() { + copyPublicKeyButton.isUserInteractionEnabled = true + UIView.transition(with: copyPublicKeyButton, duration: 0.25, options: .transitionCrossDissolve, animations: { + self.copyPublicKeyButton.setTitle(NSLocalizedString("Copy Public Key", comment: ""), for: UIControl.State.normal) + }, completion: nil) + } + + // MARK: Updating + private func updateSeed() { + seed = Randomness.generateRandomBytes(16) + } + + private func updateKeyPair() { + keyPair = Curve25519.generateKeyPair(fromSeed: seed + seed) + } + + private func updatePublicKeyLabel() { + publicKeyLabel.text = keyPair.hexEncodedPublicKey + } + + // MARK: Interaction + @objc private func register() { + let identityManager = OWSIdentityManager.shared() + let databaseConnection = identityManager.value(forKey: "dbConnection") as! YapDatabaseConnection + databaseConnection.setObject(seed.toHexString(), forKey: "LKLokiSeed", inCollection: OWSPrimaryStorageIdentityKeyStoreCollection) + databaseConnection.setObject(keyPair!, forKey: OWSPrimaryStorageIdentityKeyStoreIdentityKey, inCollection: OWSPrimaryStorageIdentityKeyStoreCollection) + let keyPair = identityManager.identityKeyPair()! + let hexEncodedPublicKey = keyPair.hexEncodedPublicKey + let accountManager = TSAccountManager.sharedInstance() + accountManager.phoneNumberAwaitingVerification = hexEncodedPublicKey + TSAccountManager.sharedInstance().didRegister() + UserDefaults.standard.set(true, forKey: "didUpdateForMainnet") + OWSProfileManager.shared().updateLocalProfileName("User", avatarImage: nil, success: { }, failure: { }) // Try to save the user name but ignore the result + let homeVC = HomeVC() + navigationController!.setViewControllers([ homeVC ], animated: true) + } + + @objc private func copyPublicKey() { + UIPasteboard.general.string = keyPair.hexEncodedPublicKey + copyPublicKeyButton.isUserInteractionEnabled = false + UIView.transition(with: copyPublicKeyButton, duration: 0.25, options: .transitionCrossDissolve, animations: { + self.copyPublicKeyButton.setTitle(NSLocalizedString("Copied", comment: ""), for: UIControl.State.normal) + }, completion: nil) + Timer.scheduledTimer(timeInterval: 4, target: self, selector: #selector(enableCopyButton), userInfo: nil, repeats: false) + } +} diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 7dbbbf5d7..e392808db 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -2731,3 +2731,6 @@ "Friends don't let friends use compromised messengers. You're welcome." = "Friends don't let friends use compromised messengers. You're welcome."; "Create Account" = "Create Account"; "Continue your Loki Messenger" = "Continue your Loki Messenger"; +"Say hello to your unique public key" = "Say hello to your unique public key"; +"Continue" = "Continue"; +"Copy Public Key" = "Copy Public Key"; diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.h b/SignalServiceKit/src/Messages/OWSIdentityManager.h index f8f14d41b..58eccd90b 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.h +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.h @@ -7,6 +7,7 @@ NS_ASSUME_NONNULL_BEGIN +extern NSString *const OWSPrimaryStorageIdentityKeyStoreIdentityKey; extern NSString *const OWSPrimaryStorageIdentityKeyStoreCollection; extern NSString *const OWSPrimaryStorageTrustedKeysCollection;