2019-04-26 07:57:06 +02:00
final class OnboardingAccountDetailsViewController : OnboardingBaseViewController {
private lazy var displayNameTextField : UITextField = {
let result = UITextField ( )
result . textColor = Theme . primaryColor
result . font = UIFont . ows_dynamicTypeBodyClamped
result . textAlignment = . center
result . placeholder = NSLocalizedString ( " Display Name (Optional) " , comment : " " )
result . accessibilityIdentifier = " onboarding.accountDetailsStep.displayNameTextField "
return result
} ( )
private lazy var passwordTextField : UITextField = {
let result = UITextField ( )
result . textColor = Theme . primaryColor
result . font = UIFont . ows_dynamicTypeBodyClamped
result . textAlignment = . center
result . placeholder = NSLocalizedString ( " Password (Optional) " , comment : " " )
result . accessibilityIdentifier = " onboarding.accountDetailsStep.passwordTextField "
result . isSecureTextEntry = true
return result
} ( )
2019-04-29 06:35:12 +02:00
2019-04-29 05:48:27 +02:00
private var normalizedName : String ? {
2019-04-29 06:35:12 +02:00
let result = displayNameTextField . text ! . ows_stripped ( )
return ! result . isEmpty ? result : nil
2019-04-29 05:48:27 +02:00
}
2019-04-26 07:57:06 +02:00
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 ( )
2019-04-29 03:34:11 +02:00
let displayNameLabel = createExplanationLabel ( text : NSLocalizedString ( " Enter a name to be shown to your contacts " , comment : " " ) )
2019-04-26 07:57:06 +02:00
displayNameLabel . accessibilityIdentifier = " onboarding.accountDetailsStep.displayNameLabel "
let passwordLabel = createExplanationLabel ( text : NSLocalizedString ( " Type an optional password for added security " , comment : " " ) )
passwordLabel . accessibilityIdentifier = " onboarding.accountDetailsStep.passwordLabel "
let bottomSpacer = UIView . vStretchingSpacer ( )
2019-04-30 06:27:39 +02:00
let nextButton = createButton ( title : NSLocalizedString ( " Next " , comment : " " ) , selector : #selector ( handleNextButtonPressed ) )
2019-04-26 07:57:06 +02:00
nextButton . accessibilityIdentifier = " onboarding.accountDetailsStep.nextButton "
let stackView = UIStackView ( arrangedSubviews : [
titleLabel ,
topSpacer ,
displayNameLabel ,
UIView . spacer ( withHeight : 8 ) ,
displayNameTextField ,
UIView . spacer ( withHeight : 16 ) ,
passwordLabel ,
UIView . spacer ( withHeight : 8 ) ,
passwordTextField ,
bottomSpacer ,
nextButton
2019-04-26 08:13:29 +02:00
] )
2019-04-26 07:57:06 +02:00
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 )
}
public override func viewDidAppear ( _ animated : Bool ) {
super . viewDidAppear ( animated )
displayNameTextField . becomeFirstResponder ( )
}
2019-04-30 06:27:39 +02:00
@objc private func handleNextButtonPressed ( ) {
2019-04-29 06:35:12 +02:00
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 " ) )
}
2019-04-29 05:48:27 +02:00
}
2019-04-30 07:12:15 +02:00
onboardingController . pushKeyPairViewController ( from : self , userName : normalizedName )
2019-04-26 07:57:06 +02:00
}
}