diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 5139d2609..599bab5a9 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -564,12 +564,12 @@ B80C6B5B2384C7F900FDBC8B /* DeviceNameModalDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B80C6B5A2384C7F900FDBC8B /* DeviceNameModalDelegate.swift */; }; B8162F0322891AD600D46544 /* FriendRequestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8162F0222891AD600D46544 /* FriendRequestView.swift */; }; B8162F0522892C5F00D46544 /* FriendRequestViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8162F0422892C5F00D46544 /* FriendRequestViewDelegate.swift */; }; - B821F2F82272CED3002C88C0 /* DisplayNameVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B821F2F72272CED3002C88C0 /* DisplayNameVC.swift */; }; B821F2FA2272CEEE002C88C0 /* SeedVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B821F2F92272CEEE002C88C0 /* SeedVC.swift */; }; 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 */; }; + B82B408E239DC00D00A248E7 /* DisplayNameVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82B408D239DC00D00A248E7 /* DisplayNameVC.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 */; }; @@ -1397,12 +1397,12 @@ B80C6B5A2384C7F900FDBC8B /* DeviceNameModalDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceNameModalDelegate.swift; sourceTree = ""; }; B8162F0222891AD600D46544 /* FriendRequestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendRequestView.swift; sourceTree = ""; }; B8162F0422892C5F00D46544 /* FriendRequestViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendRequestViewDelegate.swift; sourceTree = ""; }; - B821F2F72272CED3002C88C0 /* DisplayNameVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayNameVC.swift; sourceTree = ""; }; B821F2F92272CEEE002C88C0 /* SeedVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedVC.swift; sourceTree = ""; }; 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 = ""; }; + B82B408D239DC00D00A248E7 /* DisplayNameVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayNameVC.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 = ""; }; @@ -2713,7 +2713,6 @@ B86BD0872339A1ED000F5AE3 /* Onboarding */ = { isa = PBXGroup; children = ( - B821F2F72272CED3002C88C0 /* DisplayNameVC.swift */, B821F2F92272CEEE002C88C0 /* SeedVC.swift */, ); path = Onboarding; @@ -2803,6 +2802,7 @@ B80C6B562384A56D00FDBC8B /* DeviceLinksVC.swift */, B80C6B582384C4E700FDBC8B /* DeviceNameModal.swift */, B80C6B5A2384C7F900FDBC8B /* DeviceNameModalDelegate.swift */, + B82B408D239DC00D00A248E7 /* DisplayNameVC.swift */, B8BB82A4238F627000BA5194 /* HomeVC.swift */, B8CCF63E23975CFB0091D419 /* JoinPublicChatVC.swift */, B82B40872399EB0E00A248E7 /* LandingVC.swift */, @@ -3935,6 +3935,7 @@ 4556FA681F54AA9500AF40DD /* DebugUIProfile.swift in Sources */, 45A6DAD61EBBF85500893231 /* ReminderView.swift in Sources */, 34D1F0881F8678AA0066283D /* ConversationViewLayout.m in Sources */, + B82B408E239DC00D00A248E7 /* DisplayNameVC.swift in Sources */, 4CA485BB2232339F004B9E7D /* PhotoCaptureViewController.swift in Sources */, 34330AA31E79686200DF2FB9 /* OWSProgressView.m in Sources */, 344825C6211390C800DB4BD8 /* OWSOrphanDataCleaner.m in Sources */, @@ -3976,7 +3977,6 @@ 34B3F8851E8DF1700035BE1A /* NewGroupViewController.m in Sources */, B8CCF63F23975CFB0091D419 /* JoinPublicChatVC.swift in Sources */, 34ABC0E421DD20C500ED9469 /* ConversationMessageMapping.swift in Sources */, - B821F2F82272CED3002C88C0 /* DisplayNameVC.swift in Sources */, 34D8C0271ED3673300188D7C /* DebugUIMessages.m in Sources */, B885D5F62334A32100EE0D8E /* UIView+Constraints.swift in Sources */, 34DBF003206BD5A500025978 /* OWSMessageTextView.m in Sources */, diff --git a/Signal/src/Loki/Onboarding/DisplayNameVC.swift b/Signal/src/Loki/Onboarding/DisplayNameVC.swift deleted file mode 100644 index 1569e297c..000000000 --- a/Signal/src/Loki/Onboarding/DisplayNameVC.swift +++ /dev/null @@ -1,77 +0,0 @@ - -final class DisplayNameVC : OnboardingBaseViewController { - - private lazy var userNameTextField: UITextField = { - let result = UITextField() - result.textColor = Theme.primaryColor - result.font = .ows_dynamicTypeBodyClamped - result.textAlignment = .center - let placeholder = NSMutableAttributedString(string: NSLocalizedString("Display Name", comment: "")) - placeholder.addAttribute(.foregroundColor, value: Theme.placeholderColor, range: NSRange(location: 0, length: placeholder.length)) - result.attributedPlaceholder = placeholder - result.tintColor = .lokiGreen() - result.accessibilityIdentifier = "onboarding.accountDetailsStep.userNameTextField" - result.keyboardAppearance = .dark - return result - }() - - override func viewDidLoad() { - super.viewDidLoad() - view.backgroundColor = Theme.backgroundColor - view.layoutMargins = .zero - let titleLabel = self.createTitleLabel(text: NSLocalizedString("Create Your Loki Messenger Account", comment: "")) - titleLabel.accessibilityIdentifier = "onboarding.accountDetailsStep.titleLabel" - let topSpacer = UIView.vStretchingSpacer() - let displayNameLabel = createExplanationLabel(text: NSLocalizedString("Enter a name to be shown to your contacts", comment: "")) - displayNameLabel.accessibilityIdentifier = "onboarding.accountDetailsStep.displayNameLabel" - let bottomSpacer = UIView.vStretchingSpacer() - let nextButton = createButton(title: NSLocalizedString("Next", comment: ""), selector: #selector(handleNextButtonPressed)) - nextButton.accessibilityIdentifier = "onboarding.accountDetailsStep.nextButton" - let stackView = UIStackView(arrangedSubviews: [ - titleLabel, - topSpacer, - displayNameLabel, - UIView.spacer(withHeight: 8), - userNameTextField, - bottomSpacer, - nextButton - ]) - stackView.axis = .vertical - stackView.alignment = .fill - stackView.layoutMargins = UIEdgeInsets(top: 32, left: 32, bottom: 32, right: 32) - stackView.isLayoutMarginsRelativeArrangement = true - view.addSubview(stackView) - stackView.autoPinWidthToSuperview() - stackView.autoPin(toTopLayoutGuideOf: self, withInset: 0) - autoPinView(toBottomOfViewControllerOrKeyboard: stackView, avoidNotch: true) - topSpacer.autoMatch(.height, to: .height, of: bottomSpacer) - Analytics.shared.track("Display Name Screen Viewed") - } - - override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - userNameTextField.becomeFirstResponder() - } - - @objc private func handleNextButtonPressed() { - let displayName = userNameTextField.text!.ows_stripped() - guard !displayName.isEmpty else { - return OWSAlerts.showErrorAlert(message: NSLocalizedString("Please pick a display name", comment: "")) - } - guard displayName.allSatisfy({ "0"..."9" ~= $0 || "a"..."z" ~= $0 || "A"..."Z" ~= $0 || $0 == "_" || $0 == " " }) else { - return OWSAlerts.showErrorAlert(message: NSLocalizedString("Please pick a display name that consists of only a-z, A-Z, 0-9 and _ characters", comment: "")) - } - guard !OWSProfileManager.shared().isProfileNameTooLong(displayName) else { - return OWSAlerts.showErrorAlert(message: NSLocalizedString("Please pick a shorter display name", comment: "")) - } - TSAccountManager.sharedInstance().didRegister() - UserDefaults.standard.set(true, forKey: "didUpdateForMainnet") - onboardingController.verificationDidComplete(fromView: self) - let appDelegate = UIApplication.shared.delegate as! AppDelegate - appDelegate.setUpDefaultPublicChatsIfNeeded() - appDelegate.createRSSFeedsIfNeeded() - LokiPublicChatManager.shared.startPollersIfNeeded() - appDelegate.startRSSFeedPollersIfNeeded() - OWSProfileManager.shared().updateLocalProfileName(displayName, avatarImage: nil, success: { }, failure: { }) // Try to save the user name but ignore the result - } -} diff --git a/Signal/src/Loki/Redesign/View Controllers/DisplayNameVC.swift b/Signal/src/Loki/Redesign/View Controllers/DisplayNameVC.swift new file mode 100644 index 000000000..75cae0279 --- /dev/null +++ b/Signal/src/Loki/Redesign/View Controllers/DisplayNameVC.swift @@ -0,0 +1,163 @@ + +final class DisplayNameVC : UIViewController { + private var spacer1HeightConstraint: NSLayoutConstraint! + private var spacer2HeightConstraint: NSLayoutConstraint! + private var registerButtonBottomOffsetConstraint: NSLayoutConstraint! + private var bottomConstraint: NSLayoutConstraint! + + // MARK: Components + private lazy var displayNameTextField: TextField = { + let result = TextField(placeholder: NSLocalizedString("Enter a display name", comment: "")) + result.layer.borderColor = Colors.text.cgColor + 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("Pick your public display name", 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 spacers + let topSpacer = UIView.vStretchingSpacer() + let spacer1 = UIView() + spacer1HeightConstraint = spacer1.set(.height, to: Values.veryLargeSpacing) + let spacer2 = UIView() + spacer2HeightConstraint = spacer2.set(.height, to: Values.veryLargeSpacing) + let bottomSpacer = UIView.vStretchingSpacer() + let registerButtonBottomOffsetSpacer = UIView() + registerButtonBottomOffsetConstraint = registerButtonBottomOffsetSpacer.set(.height, to: Values.onboardingButtonBottomOffset) + // 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 register button container + let registerButtonContainer = UIView() + registerButtonContainer.addSubview(registerButton) + registerButton.pin(.leading, to: .leading, of: registerButtonContainer, withInset: Values.massiveSpacing) + registerButton.pin(.top, to: .top, of: registerButtonContainer) + registerButtonContainer.pin(.trailing, to: .trailing, of: registerButton, withInset: Values.massiveSpacing) + registerButtonContainer.pin(.bottom, to: .bottom, of: registerButton) + // Set up top stack view + let topStackView = UIStackView(arrangedSubviews: [ titleLabel, spacer1, explanationLabel, spacer2, displayNameTextField ]) + topStackView.axis = .vertical + topStackView.alignment = .fill + // Set up top stack view container + let topStackViewContainer = UIView() + topStackViewContainer.addSubview(topStackView) + topStackView.pin(.leading, to: .leading, of: topStackViewContainer, withInset: Values.veryLargeSpacing) + topStackView.pin(.top, to: .top, of: topStackViewContainer) + topStackViewContainer.pin(.trailing, to: .trailing, of: topStackView, withInset: Values.veryLargeSpacing) + topStackViewContainer.pin(.bottom, to: .bottom, of: topStackView) + // Set up main stack view + let mainStackView = UIStackView(arrangedSubviews: [ topSpacer, topStackViewContainer, bottomSpacer, registerButtonContainer, registerButtonBottomOffsetSpacer ]) + mainStackView.axis = .vertical + mainStackView.alignment = .fill + view.addSubview(mainStackView) + mainStackView.pin(.leading, to: .leading, of: view) + mainStackView.pin(.top, to: .top, of: view) + mainStackView.pin(.trailing, to: .trailing, of: view) + bottomConstraint = mainStackView.pin(.bottom, to: .bottom, of: view) + topSpacer.heightAnchor.constraint(equalTo: bottomSpacer.heightAnchor, multiplier: 1).isActive = true + // Dismiss keyboard on tap + let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) + view.addGestureRecognizer(tapGestureRecognizer) + // Listen to keyboard notifications + let notificationCenter = NotificationCenter.default + notificationCenter.addObserver(self, selector: #selector(handleKeyboardWillChangeFrameNotification(_:)), name: UIResponder.keyboardWillChangeFrameNotification, object: nil) + notificationCenter.addObserver(self, selector: #selector(handleKeyboardWillHideNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil) + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + displayNameTextField.becomeFirstResponder() + } + + deinit { + NotificationCenter.default.removeObserver(self) + } + + // MARK: General + @objc private func dismissKeyboard() { + displayNameTextField.resignFirstResponder() + } + + // MARK: Updating + @objc private func handleKeyboardWillChangeFrameNotification(_ notification: Notification) { + guard let newHeight = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size.height else { return } + bottomConstraint.constant = -newHeight // Negative due to how the constraint is set up + registerButtonBottomOffsetConstraint.constant = Values.largeSpacing + spacer1HeightConstraint.constant = Values.mediumSpacing + spacer2HeightConstraint.constant = Values.mediumSpacing + UIView.animate(withDuration: 0.25) { + self.view.layoutIfNeeded() + } + } + + @objc private func handleKeyboardWillHideNotification(_ notification: Notification) { + bottomConstraint.constant = 0 + registerButtonBottomOffsetConstraint.constant = Values.onboardingButtonBottomOffset + spacer1HeightConstraint.constant = Values.veryLargeSpacing + spacer2HeightConstraint.constant = Values.veryLargeSpacing + UIView.animate(withDuration: 0.25) { + self.view.layoutIfNeeded() + } + } + + // MARK: Interaction + @objc private func register() { + func showError(title: String, message: String = "") { + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default, handler: nil)) + presentAlert(alert) + } + let displayName = displayNameTextField.text!.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) + guard !displayName.isEmpty else { + return showError(title: NSLocalizedString("Please pick a display name", comment: "")) + } + let allowedCharacters = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_ ") + let hasInvalidCharacters = !displayName.allSatisfy { $0.unicodeScalars.allSatisfy { allowedCharacters.contains($0) } } + guard !hasInvalidCharacters else { + return showError(title: NSLocalizedString("Please pick a display name that consists of only a-z, A-Z, 0-9 and _ characters", comment: "")) + } + guard !OWSProfileManager.shared().isProfileNameTooLong(displayName) else { + return showError(title: NSLocalizedString("Please pick a shorter display name", comment: "")) + } + 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) + } +} diff --git a/Signal/src/Loki/Redesign/View Controllers/PublicKeyVC.swift b/Signal/src/Loki/Redesign/View Controllers/PublicKeyVC.swift index 353fc1a93..b43dcc248 100644 --- a/Signal/src/Loki/Redesign/View Controllers/PublicKeyVC.swift +++ b/Signal/src/Loki/Redesign/View Controllers/PublicKeyVC.swift @@ -161,13 +161,9 @@ final class PublicKeyVC : UIViewController { let databaseConnection = identityManager.value(forKey: "dbConnection") as! YapDatabaseConnection databaseConnection.setObject(seed.toHexString(), forKey: "LKLokiSeed", inCollection: OWSPrimaryStorageIdentityKeyStoreCollection) databaseConnection.setObject(keyPair!, forKey: OWSPrimaryStorageIdentityKeyStoreIdentityKey, inCollection: OWSPrimaryStorageIdentityKeyStoreCollection) - let hexEncodedPublicKey = keyPair!.hexEncodedPublicKey - TSAccountManager.sharedInstance().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) + TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = keyPair!.hexEncodedPublicKey + let displayNameVC = DisplayNameVC() + navigationController!.pushViewController(displayNameVC, animated: true) } @objc private func copyPublicKey() { diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index e392808db..ab34e4bbd 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -2734,3 +2734,5 @@ "Say hello to your unique public key" = "Say hello to your unique public key"; "Continue" = "Continue"; "Copy Public Key" = "Copy Public Key"; +"Pick your public display name" = "Pick your public display name"; +"Enter a display name" = "Enter a display name";