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
return result
}()
private var normalizedName: String? {
get {
return displayNameTextField.text?.ows_stripped()
}
let result = displayNameTextField.text!.ows_stripped()
return !result.isEmpty ? result : nil
}
override func viewDidLoad() {
@ -73,21 +72,16 @@ final class OnboardingAccountDetailsViewController : OnboardingBaseViewControlle
displayNameTextField.becomeFirstResponder()
}
@objc private func goToSeedStep(profileName: String? = nil) {
onboardingController.pushPublicKeyViewController(from: self, profileName: profileName)
}
@objc private func updateProfile() {
guard let normalizedName = self.normalizedName else {
self.goToSeedStep()
return
}
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
if let normalizedName = normalizedName {
guard !OWSProfileManager.shared().isProfileNameTooLong(normalizedName) else {
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"))
}
}
self.goToSeedStep(profileName: normalizedName)
goToSeedStep()
}
@objc private func goToSeedStep() {
onboardingController.pushPublicKeyViewController(from: self, userName: normalizedName)
}
}

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

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

Loading…
Cancel
Save