Minor refactoring

pull/2/head
Niels Andriesse 6 years ago
parent 8e5327f915
commit b64bb79254

@ -23,11 +23,10 @@ final class OnboardingAccountDetailsViewController : OnboardingBaseViewControlle
result.isSecureTextEntry = true result.isSecureTextEntry = true
return result return result
}() }()
private var normalizedName: String? { private var normalizedName: String? {
get { let result = displayNameTextField.text!.ows_stripped()
return displayNameTextField.text?.ows_stripped() return !result.isEmpty ? result : nil
}
} }
override func viewDidLoad() { override func viewDidLoad() {
@ -73,21 +72,16 @@ final class OnboardingAccountDetailsViewController : OnboardingBaseViewControlle
displayNameTextField.becomeFirstResponder() displayNameTextField.becomeFirstResponder()
} }
@objc private func goToSeedStep(profileName: String? = nil) {
onboardingController.pushPublicKeyViewController(from: self, profileName: profileName)
}
@objc private func updateProfile() { @objc private func updateProfile() {
guard let normalizedName = self.normalizedName else { if let normalizedName = normalizedName {
self.goToSeedStep() guard !OWSProfileManager.shared().isProfileNameTooLong(normalizedName) else {
return return OWSAlerts.showErrorAlert(message: NSLocalizedString("PROFILE_VIEW_ERROR_PROFILE_NAME_TOO_LONG", comment: "Error message shown when user tries to update profile with a profile name that is too long"))
} }
if (OWSProfileManager.shared().isProfileNameTooLong(normalizedName)) {
OWSAlerts.showErrorAlert(message: NSLocalizedString("PROFILE_VIEW_ERROR_PROFILE_NAME_TOO_LONG", comment: "Error message shown when user tries to update profile with a profile name that is too long"))
return
} }
goToSeedStep()
self.goToSeedStep(profileName: normalizedName) }
@objc private func goToSeedStep() {
onboardingController.pushPublicKeyViewController(from: self, userName: normalizedName)
} }
} }

@ -128,9 +128,9 @@ public class OnboardingController: NSObject {
viewController.navigationController?.pushViewController(accountDetailsVC, animated: true) viewController.navigationController?.pushViewController(accountDetailsVC, animated: true)
} }
func pushPublicKeyViewController(from viewController: UIViewController, profileName: String?) { func pushPublicKeyViewController(from viewController: UIViewController, userName: String?) {
AssertIsOnMainThread() AssertIsOnMainThread()
let publicKeyVC = OnboardingPublicKeyViewController(onboardingController: self, profileName: profileName) let publicKeyVC = OnboardingPublicKeyViewController(onboardingController: self, userName: userName)
viewController.navigationController?.pushViewController(publicKeyVC, animated: true) viewController.navigationController?.pushViewController(publicKeyVC, animated: true)
} }

@ -5,7 +5,7 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController {
private var keyPair: ECKeyPair! { didSet { updateMnemonic() } } private var keyPair: ECKeyPair! { didSet { updateMnemonic() } }
private var hexEncodedPublicKey: String! private var hexEncodedPublicKey: String!
private var mnemonic: String! { didSet { mnemonicLabel.text = mnemonic } } private var mnemonic: String! { didSet { mnemonicLabel.text = mnemonic } }
private var profileName: String? private var userName: String?
private lazy var mnemonicLabel: UILabel = { private lazy var mnemonicLabel: UILabel = {
let result = createExplanationLabel(text: "") let result = createExplanationLabel(text: "")
@ -17,10 +17,9 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController {
return result return result
}() }()
@objc init(onboardingController: OnboardingController, userName: String?) {
public init(onboardingController: OnboardingController, profileName: String?) { super.init(onboardingController: onboardingController)
super.init(onboardingController: onboardingController); self.userName = userName
self.profileName = profileName
} }
override public func viewDidLoad() { override public func viewDidLoad() {
@ -81,10 +80,10 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController {
strongSelf.onboardingController.verificationDidComplete(fromView: strongSelf) strongSelf.onboardingController.verificationDidComplete(fromView: strongSelf)
} }
if let name = self.profileName { if let userName = userName {
// Try save the profile name // Try save the profile name
OWSProfileManager.shared().updateLocalProfileName(name, avatarImage: nil, success: verificationComplete, failure: { OWSProfileManager.shared().updateLocalProfileName(userName, avatarImage: nil, success: verificationComplete, failure: {
Logger.warn("Failed to set profile name") Logger.warn("Failed to set user name")
verificationComplete() verificationComplete()
}) })
} else { } else {

Loading…
Cancel
Save