Merge branch 'charlesmchen/onboardingVerification'

pull/2/head
Matthew Chen 6 years ago
commit 260d3253ff

@ -165,6 +165,7 @@
3496957321A301A100DCFE74 /* OWSBackupJob.m in Sources */ = {isa = PBXBuildFile; fileRef = 3496956A21A301A100DCFE74 /* OWSBackupJob.m */; };
3496957421A301A100DCFE74 /* OWSBackupAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3496956B21A301A100DCFE74 /* OWSBackupAPI.swift */; };
349EA07C2162AEA800F7B17F /* OWS111UDAttributesMigration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349EA07B2162AEA700F7B17F /* OWS111UDAttributesMigration.swift */; };
34A4C61E221613D00042EF2E /* OnboardingVerificationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34A4C61D221613D00042EF2E /* OnboardingVerificationViewController.swift */; };
34A55F3720485465002CC6DE /* OWS2FARegistrationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34A55F3520485464002CC6DE /* OWS2FARegistrationViewController.m */; };
34A6C28021E503E700B5B12E /* OWSImagePickerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34A6C27F21E503E600B5B12E /* OWSImagePickerController.swift */; };
34A8B3512190A40E00218A25 /* MediaAlbumCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34A8B3502190A40E00218A25 /* MediaAlbumCellView.swift */; };
@ -846,6 +847,7 @@
3496956C21A301A100DCFE74 /* OWSBackupImportJob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSBackupImportJob.h; sourceTree = "<group>"; };
3496956D21A301A100DCFE74 /* OWSBackupIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSBackupIO.h; sourceTree = "<group>"; };
349EA07B2162AEA700F7B17F /* OWS111UDAttributesMigration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWS111UDAttributesMigration.swift; sourceTree = "<group>"; };
34A4C61D221613D00042EF2E /* OnboardingVerificationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OnboardingVerificationViewController.swift; sourceTree = "<group>"; };
34A55F3520485464002CC6DE /* OWS2FARegistrationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWS2FARegistrationViewController.m; sourceTree = "<group>"; };
34A55F3620485464002CC6DE /* OWS2FARegistrationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWS2FARegistrationViewController.h; sourceTree = "<group>"; };
34A6C27F21E503E600B5B12E /* OWSImagePickerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSImagePickerController.swift; sourceTree = "<group>"; };
@ -1473,6 +1475,7 @@
3448E15B22133274004B052E /* OnboardingPermissionsViewController.swift */,
3448E16322135FFA004B052E /* OnboardingPhoneNumberViewController.swift */,
3448E15F22134C88004B052E /* OnboardingSplashViewController.swift */,
34A4C61D221613D00042EF2E /* OnboardingVerificationViewController.swift */,
346E9D5321B040B600562252 /* RegistrationController.swift */,
340FC878204DAC8C007AEB0F /* RegistrationViewController.h */,
340FC876204DAC8C007AEB0F /* RegistrationViewController.m */,
@ -3537,6 +3540,7 @@
34D1F0521F7E8EA30066283D /* GiphyDownloader.swift in Sources */,
340FC8BC204DAC8D007AEB0F /* FingerprintViewController.m in Sources */,
450DF2051E0D74AC003D14BE /* Platform.swift in Sources */,
34A4C61E221613D00042EF2E /* OnboardingVerificationViewController.swift in Sources */,
340FC8B2204DAC8D007AEB0F /* AdvancedSettingsTableViewController.m in Sources */,
452B999020A34B6B006F2F9E /* AddContactShareToExistingContactViewController.swift in Sources */,
346129991FD1E4DA00532771 /* SignalApp.m in Sources */,

@ -50,29 +50,22 @@ public class OnboardingBaseViewController: OWSViewController {
}
func button(title: String, selector: Selector) -> OWSFlatButton {
// TODO: Make sure this all fits if dynamic font sizes are maxed out.
let font = UIFont.ows_dynamicTypeBodyClamped.ows_mediumWeight()
// Button height should be 48pt if the font is 17pt.
let buttonHeight = font.pointSize * 48 / 17
let button = OWSFlatButton.button(title: title,
font: font,
titleColor: .white,
backgroundColor: .ows_materialBlue,
target: self,
selector: selector)
button.autoSetDimension(.height, toSize: buttonHeight)
return button
return button(title: title, selector: selector, titleColor: .white, backgroundColor: .ows_materialBlue)
}
func linkButton(title: String, selector: Selector) -> OWSFlatButton {
return button(title: title, selector: selector, titleColor: .ows_materialBlue, backgroundColor: .white)
}
private func button(title: String, selector: Selector, titleColor: UIColor, backgroundColor: UIColor) -> OWSFlatButton {
// TODO: Make sure this all fits if dynamic font sizes are maxed out.
let font = UIFont.ows_dynamicTypeBodyClamped.ows_mediumWeight()
// Button height should be 48pt if the font is 17pt.
let buttonHeight = font.pointSize * 48 / 17
let button = OWSFlatButton.button(title: title,
font: font,
titleColor: .ows_materialBlue,
backgroundColor: .white,
titleColor: titleColor,
backgroundColor: backgroundColor,
target: self,
selector: selector)
button.autoSetDimension(.height, toSize: buttonHeight)
@ -85,6 +78,8 @@ public class OnboardingBaseViewController: OWSViewController {
super.viewWillAppear(animated)
self.navigationController?.isNavigationBarHidden = true
// Disable "back" gesture.
self.navigationController?.navigationItem.backBarButtonItem?.isEnabled = false
// TODO: Is there a better way to do this?
if let navigationController = self.navigationController as? OWSNavigationController {
@ -98,6 +93,8 @@ public class OnboardingBaseViewController: OWSViewController {
super.viewDidAppear(animated)
self.navigationController?.isNavigationBarHidden = true
// Disable "back" gesture.
self.navigationController?.navigationItem.backBarButtonItem?.isEnabled = false
}
// MARK: - Orientation

@ -114,7 +114,7 @@ public class OnboardingCaptchaViewController: OnboardingBaseViewController {
}
onboardingController.update(captchaToken: captchaToken)
onboardingController.tryToRegister(fromViewController: self, smsVerification: false)
onboardingController.tryToRegister(fromViewController: self, smsVerification: true)
}
private func parseCaptcha(url: URL) -> String? {

@ -66,6 +66,14 @@ public class OnboardingController: NSObject {
return TSAccountManager.sharedInstance()
}
private var accountManager: AccountManager {
return AppEnvironment.shared.accountManager
}
private var backup: OWSBackup {
return AppEnvironment.shared.backup
}
// MARK: -
@objc
@ -122,8 +130,8 @@ public class OnboardingController: NSObject {
Logger.info("")
// CodeVerificationViewController *vc = [CodeVerificationViewController new];
// [weakSelf.navigationController pushViewController:vc animated:YES];
let view = OnboardingVerificationViewController(onboardingController: self)
viewController.navigationController?.pushViewController(view, animated: true)
}
public func onboardingDidRequireCaptcha(viewController: UIViewController) {
@ -148,6 +156,97 @@ public class OnboardingController: NSObject {
navigationController.pushViewController(view, animated: true)
}
@objc
public func verificationDidComplete(fromView view: UIViewController) {
AssertIsOnMainThread()
Logger.info("")
if tsAccountManager.isReregistering() {
showProfileView(fromView: view)
} else {
checkCanImportBackup(fromView: view)
}
}
private func showProfileView(fromView view: UIViewController) {
AssertIsOnMainThread()
Logger.info("")
guard let navigationController = view.navigationController else {
owsFailDebug("Missing navigationController")
return
}
ProfileViewController.present(forRegistration: navigationController)
}
private func showBackupRestoreView(fromView view: UIViewController) {
AssertIsOnMainThread()
Logger.info("")
guard let navigationController = view.navigationController else {
owsFailDebug("Missing navigationController")
return
}
let restoreView = BackupRestoreViewController()
navigationController.setViewControllers([restoreView], animated: true)
}
private func checkCanImportBackup(fromView view: UIViewController) {
AssertIsOnMainThread()
Logger.info("")
backup.checkCanImport({ (canImport) in
Logger.info("canImport: \(canImport)")
if (canImport) {
self.backup.setHasPendingRestoreDecision(true)
self.showBackupRestoreView(fromView: view)
} else {
self.showProfileView(fromView: view)
}
}, failure: { (_) in
self.showBackupCheckFailedAlert(fromView: view)
})
}
private func showBackupCheckFailedAlert(fromView view: UIViewController) {
AssertIsOnMainThread()
Logger.info("")
let alert = UIAlertController(title: NSLocalizedString("CHECK_FOR_BACKUP_FAILED_TITLE",
comment: "Title for alert shown when the app failed to check for an existing backup."),
message: NSLocalizedString("CHECK_FOR_BACKUP_FAILED_MESSAGE",
comment: "Message for alert shown when the app failed to check for an existing backup."),
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("REGISTER_FAILED_TRY_AGAIN", comment: ""),
style: .default) { (_) in
self.checkCanImportBackup(fromView: view)
})
alert.addAction(UIAlertAction(title: NSLocalizedString("CHECK_FOR_BACKUP_DO_NOT_RESTORE", comment: "The label for the 'do not restore backup' button."),
style: .destructive) { (_) in
self.showProfileView(fromView: view)
})
view.present(alert, animated: true)
}
public func onboardingDidRequire2FAPin(viewController: UIViewController) {
AssertIsOnMainThread()
Logger.info("")
// TODO:
// let view = OnboardingCaptchaViewController(onboardingController: self)
// navigationController.pushViewController(view, animated: true)
}
// MARK: - State
public private(set) var countryState: OnboardingCountryState = .defaultValue
@ -276,7 +375,6 @@ public class OnboardingController: NSObject {
Logger.info("Captcha requested.")
onboardingDidRequireCaptcha(viewController: viewController)
return
} else if error.code == 400 {
OWSAlerts.showAlert(title: NSLocalizedString("REGISTRATION_ERROR", comment: ""),
message: NSLocalizedString("REGISTRATION_NON_VALID_NUMBER", comment: ""))
@ -286,4 +384,57 @@ public class OnboardingController: NSObject {
message: error.localizedRecoverySuggestion)
}
}
// MARK: - Verification
public func tryToVerify(fromViewController: UIViewController,
verificationCode: String,
pin: String?) {
AssertIsOnMainThread()
guard let phoneNumber = phoneNumber else {
owsFailDebug("Missing phoneNumber.")
return
}
// Ensure the account manager state is up-to-date.
//
// TODO: We could skip this in production.
tsAccountManager.phoneNumberAwaitingVerification = phoneNumber.e164
ModalActivityIndicatorViewController.present(fromViewController: fromViewController,
canCancel: true) { (modal) in
self.accountManager.register(verificationCode: verificationCode, pin: pin)
.done { (_) in
DispatchQueue.main.async {
modal.dismiss(completion: {
self.verificationDidComplete(fromView: fromViewController)
})
}
}.catch({ (error) in
Logger.error("Error: \(error)")
DispatchQueue.main.async {
modal.dismiss(completion: {
self.verificationFailed(fromViewController: fromViewController, error: error as NSError)
})
}
}).retainUntilComplete()
}
}
private func verificationFailed(fromViewController: UIViewController, error: NSError) {
if error.domain == OWSSignalServiceKitErrorDomain &&
error.code == OWSErrorCode.registrationMissing2FAPIN.rawValue {
Logger.info("Missing 2FA PIN.")
onboardingDidRequire2FAPin(viewController: fromViewController)
} else {
OWSAlerts.showAlert(title: NSLocalizedString("REGISTRATION_VERIFICATION_FAILED_TITLE", comment: "Alert view title"),
message: error.localizedDescription,
fromViewController: fromViewController)
}
}
}

@ -368,10 +368,10 @@ public class OnboardingPhoneNumberViewController: OnboardingBaseViewController {
proceedTitle: NSLocalizedString("REGISTRATION_IPAD_CONFIRM_BUTTON",
comment: "button text to proceed with registration when on an iPad"),
proceedAction: { (_) in
self.onboardingController.tryToRegister(fromViewController: self, smsVerification: false)
self.onboardingController.tryToRegister(fromViewController: self, smsVerification: true)
})
} else {
onboardingController.tryToRegister(fromViewController: self, smsVerification: false)
onboardingController.tryToRegister(fromViewController: self, smsVerification: true)
}
}
}

@ -0,0 +1,474 @@
//
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
import UIKit
import PromiseKit
private protocol OnboardingCodeViewTextFieldDelegate {
func textFieldDidDeletePrevious()
}
// MARK: -
// Editing a code should feel seamless, as even though
// the UITextField only lets you edit a single digit at
// a time. For deletes to work properly, we need to
// detect delete events that would affect the _previous_
// digit.
private class OnboardingCodeViewTextField: UITextField {
fileprivate var codeDelegate: OnboardingCodeViewTextFieldDelegate?
override func deleteBackward() {
var isDeletePrevious = false
if let selectedTextRange = selectedTextRange {
let cursorPosition = offset(from: beginningOfDocument, to: selectedTextRange.start)
if cursorPosition == 0 {
isDeletePrevious = true
}
}
super.deleteBackward()
if isDeletePrevious {
codeDelegate?.textFieldDidDeletePrevious()
}
}
}
// MARK: -
protocol OnboardingCodeViewDelegate {
func codeViewDidChange()
}
// MARK: -
// The OnboardingCodeView is a special "verification code"
// editor that should feel like editing a single piece
// of text (ala UITextField) even though the individual
// digits of the code are visually separated.
//
// We use a separate UILabel for each digit, and move
// around a single UITextfield to let the user edit the
// last/next digit.
private class OnboardingCodeView: UIView {
var delegate: OnboardingCodeViewDelegate?
public init() {
super.init(frame: .zero)
createSubviews()
updateViewState()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private let digitCount = 6
private var digitLabels = [UILabel]()
// We use a single text field to edit the "current" digit.
// The "current" digit is usually the "last"
fileprivate let textfield = OnboardingCodeViewTextField()
private var currentDigitIndex = 0
private var textfieldConstraints = [NSLayoutConstraint]()
// The current complete text - the "model" for this view.
private var digitText = ""
var isComplete: Bool {
return digitText.count == digitCount
}
var verificationCode: String {
return digitText
}
private func createSubviews() {
textfield.textAlignment = .left
textfield.delegate = self
textfield.keyboardType = .numberPad
textfield.textColor = Theme.primaryColor
textfield.font = UIFont.ows_dynamicTypeLargeTitle1Clamped
textfield.codeDelegate = self
var digitViews = [UIView]()
(0..<digitCount).forEach { (_) in
let (digitView, digitLabel) = makeCellView(text: "", hasStroke: true)
digitLabels.append(digitLabel)
digitViews.append(digitView)
}
let (hyphenView, _) = makeCellView(text: "-", hasStroke: false)
digitViews.insert(hyphenView, at: 3)
let stackView = UIStackView(arrangedSubviews: digitViews)
stackView.axis = .horizontal
stackView.alignment = .center
stackView.spacing = 8
addSubview(stackView)
stackView.autoPinHeightToSuperview()
stackView.autoHCenterInSuperview()
self.addSubview(textfield)
}
private func makeCellView(text: String, hasStroke: Bool) -> (UIView, UILabel) {
let digitView = UIView()
let digitLabel = UILabel()
digitLabel.text = text
digitLabel.font = UIFont.ows_dynamicTypeLargeTitle1Clamped
digitLabel.textColor = Theme.primaryColor
digitLabel.textAlignment = .center
digitView.addSubview(digitLabel)
digitLabel.autoCenterInSuperview()
if hasStroke {
let strokeView = UIView.container()
strokeView.backgroundColor = Theme.primaryColor
digitView.addSubview(strokeView)
strokeView.autoPinWidthToSuperview()
strokeView.autoPinEdge(toSuperviewEdge: .bottom)
strokeView.autoSetDimension(.height, toSize: 1)
}
let vMargin: CGFloat = 4
let cellHeight: CGFloat = digitLabel.font.lineHeight + vMargin * 2
let cellWidth: CGFloat = cellHeight * 2 / 3
digitView.autoSetDimensions(to: CGSize(width: cellWidth, height: cellHeight))
return (digitView, digitLabel)
}
private func digit(at index: Int) -> String {
guard index < digitText.count else {
return ""
}
return digitText.substring(from: index).substring(to: 1)
}
// Ensure that all labels are displaying the correct
// digit (if any) and that the UITextField has replaced
// the "current" digit.
private func updateViewState() {
currentDigitIndex = min(digitCount - 1,
digitText.count)
(0..<digitCount).forEach { (index) in
let digitLabel = digitLabels[index]
digitLabel.text = digit(at: index)
digitLabel.isHidden = index == currentDigitIndex
}
NSLayoutConstraint.deactivate(textfieldConstraints)
textfieldConstraints.removeAll()
let digitLabelToReplace = digitLabels[currentDigitIndex]
textfield.text = digit(at: currentDigitIndex)
textfieldConstraints.append(textfield.autoAlignAxis(.horizontal, toSameAxisOf: digitLabelToReplace))
textfieldConstraints.append(textfield.autoAlignAxis(.vertical, toSameAxisOf: digitLabelToReplace))
// Move cursor to end of text.
let newPosition = textfield.endOfDocument
textfield.selectedTextRange = textfield.textRange(from: newPosition, to: newPosition)
}
public override func becomeFirstResponder() -> Bool {
return textfield.becomeFirstResponder()
}
}
// MARK: -
extension OnboardingCodeView: UITextFieldDelegate {
public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString newString: String) -> Bool {
var oldText = ""
if let textFieldText = textField.text {
oldText = textFieldText
}
let left = oldText.substring(to: range.location)
let right = oldText.substring(from: range.location + range.length)
let unfiltered = left + newString + right
let characterSet = CharacterSet(charactersIn: "0123456789")
let filtered = unfiltered.components(separatedBy: characterSet.inverted).joined()
let filteredAndTrimmed = filtered.substring(to: 1)
textField.text = filteredAndTrimmed
digitText = digitText.substring(to: currentDigitIndex) + filteredAndTrimmed
updateViewState()
self.delegate?.codeViewDidChange()
// Inform our caller that we took care of performing the change.
return false
}
public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.delegate?.codeViewDidChange()
return false
}
}
// MARK: -
extension OnboardingCodeView: OnboardingCodeViewTextFieldDelegate {
public func textFieldDidDeletePrevious() {
guard digitText.count > 0 else {
return
}
digitText = digitText.substring(to: currentDigitIndex - 1)
updateViewState()
}
}
// MARK: -
@objc
public class OnboardingVerificationViewController: OnboardingBaseViewController {
private enum CodeState {
case sent
case readyForResend
case resent
}
// MARK: -
private var codeState = CodeState.sent
private var titleLabel: UILabel?
private let phoneNumberTextField = UITextField()
private let onboardingCodeView = OnboardingCodeView()
private var codeStateLink: OWSFlatButton?
override public func loadView() {
super.loadView()
view.backgroundColor = Theme.backgroundColor
view.layoutMargins = .zero
let titleLabel = self.titleLabel(text: "")
self.titleLabel = titleLabel
let backLink = self.linkButton(title: NSLocalizedString("ONBOARDING_VERIFICATION_BACK_LINK",
comment: "Label for the link that lets users change their phone number."),
selector: #selector(backLinkTapped))
onboardingCodeView.delegate = self
let codeStateLink = self.linkButton(title: "",
selector: #selector(resendCodeLinkTapped))
codeStateLink.enableMultilineLabel()
self.codeStateLink = codeStateLink
let topSpacer = UIView.vStretchingSpacer()
let bottomSpacer = UIView.vStretchingSpacer()
let stackView = UIStackView(arrangedSubviews: [
titleLabel,
UIView.spacer(withHeight: 12),
backLink,
topSpacer,
onboardingCodeView,
bottomSpacer,
codeStateLink
])
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)
// Ensure whitespace is balanced, so inputs are vertically centered.
topSpacer.autoMatch(.height, to: .height, of: bottomSpacer)
startCodeCountdown()
updateCodeState()
}
// MARK: - Code State
private let countdownDuration: TimeInterval = 60
private var codeCountdownTimer: Timer?
private var codeCountdownStart: NSDate?
deinit {
codeCountdownTimer?.invalidate()
}
private func startCodeCountdown() {
codeCountdownStart = NSDate()
codeCountdownTimer = Timer.weakScheduledTimer(withTimeInterval: 0.25, target: self, selector: #selector(codeCountdownTimerFired), userInfo: nil, repeats: true)
}
@objc
public func codeCountdownTimerFired() {
guard let codeCountdownStart = codeCountdownStart else {
owsFailDebug("Missing codeCountdownStart.")
return
}
guard let codeCountdownTimer = codeCountdownTimer else {
owsFailDebug("Missing codeCountdownTimer.")
return
}
let countdownInterval = abs(codeCountdownStart.timeIntervalSinceNow)
guard countdownInterval < countdownDuration else {
// Countdown complete.
codeCountdownTimer.invalidate()
self.codeCountdownTimer = nil
if codeState != .sent {
owsFailDebug("Unexpected codeState: \(codeState)")
}
codeState = .readyForResend
updateCodeState()
return
}
// Update the "code state" UI to reflect the countdown.
updateCodeState()
}
private func updateCodeState() {
AssertIsOnMainThread()
guard let codeCountdownStart = codeCountdownStart else {
owsFailDebug("Missing codeCountdownStart.")
return
}
guard let titleLabel = titleLabel else {
owsFailDebug("Missing titleLabel.")
return
}
guard let codeStateLink = codeStateLink else {
owsFailDebug("Missing codeStateLink.")
return
}
var e164PhoneNumber = ""
if let phoneNumber = onboardingController.phoneNumber {
e164PhoneNumber = phoneNumber.e164
}
let formattedPhoneNumber = PhoneNumber.bestEffortLocalizedPhoneNumber(withE164: e164PhoneNumber)
// Update titleLabel
switch codeState {
case .sent, .readyForResend:
titleLabel.text = String(format: NSLocalizedString("ONBOARDING_VERIFICATION_TITLE_DEFAULT_FORMAT",
comment: "Format for the title of the 'onboarding verification' view. Embeds {{the user's phone number}}."),
formattedPhoneNumber)
case .resent:
titleLabel.text = String(format: NSLocalizedString("ONBOARDING_VERIFICATION_TITLE_RESENT_FORMAT",
comment: "Format for the title of the 'onboarding verification' view after the verification code has been resent. Embeds {{the user's phone number}}."),
formattedPhoneNumber)
}
// Update codeStateLink
switch codeState {
case .sent:
let countdownInterval = abs(codeCountdownStart.timeIntervalSinceNow)
let countdownRemaining = max(0, countdownDuration - countdownInterval)
let formattedCountdown = OWSFormat.formatDurationSeconds(Int(round(countdownRemaining)))
let text = String(format: NSLocalizedString("ONBOARDING_VERIFICATION_CODE_COUNTDOWN_FORMAT",
comment: "Format for the label of the 'sent code' label of the 'onboarding verification' view. Embeds {{the time until the code can be resent}}."),
formattedCountdown)
codeStateLink.setTitle(title: text, font: .ows_dynamicTypeBodyClamped, titleColor: Theme.secondaryColor)
case .readyForResend:
codeStateLink.setTitle(title: NSLocalizedString("ONBOARDING_VERIFICATION_ORIGINAL_CODE_MISSING_LINK",
comment: "Label for link that can be used when the original code did not arrive."),
font: .ows_dynamicTypeBodyClamped,
titleColor: .ows_materialBlue)
case .resent:
codeStateLink.setTitle(title: NSLocalizedString("ONBOARDING_VERIFICATION_RESENT_CODE_MISSING_LINK",
comment: "Label for link that can be used when the resent code did not arrive."),
font: .ows_dynamicTypeBodyClamped,
titleColor: .ows_materialBlue)
}
}
public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
_ = onboardingCodeView.becomeFirstResponder()
}
// MARK: - Events
@objc func backLinkTapped() {
Logger.info("")
self.navigationController?.popViewController(animated: true)
}
@objc func resendCodeLinkTapped() {
Logger.info("")
switch codeState {
case .sent:
// Ignore taps until the countdown expires.
break
case .readyForResend, .resent:
showResendActionSheet()
}
}
private func showResendActionSheet() {
Logger.info("")
let actionSheet = UIAlertController(title: NSLocalizedString("ONBOARDING_VERIFICATION_RESEND_CODE_ALERT_TITLE",
comment: "Title for the 'resend code' alert in the 'onboarding verification' view."),
message: NSLocalizedString("ONBOARDING_VERIFICATION_RESEND_CODE_ALERT_MESSAGE",
comment: "Message for the 'resend code' alert in the 'onboarding verification' view."),
preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: NSLocalizedString("ONBOARDING_VERIFICATION_RESEND_CODE_BY_SMS_BUTTON",
comment: "Label for the 'resend code by SMS' button in the 'onboarding verification' view."),
style: .default) { _ in
self.onboardingController.tryToRegister(fromViewController: self, smsVerification: true)
})
actionSheet.addAction(UIAlertAction(title: NSLocalizedString("ONBOARDING_VERIFICATION_RESEND_CODE_BY_VOICE_BUTTON",
comment: "Label for the 'resend code by voice' button in the 'onboarding verification' view."),
style: .default) { _ in
self.onboardingController.tryToRegister(fromViewController: self, smsVerification: false)
})
actionSheet.addAction(OWSAlerts.cancelAction)
self.present(actionSheet, animated: true)
}
private func tryToVerify() {
Logger.info("")
guard onboardingCodeView.isComplete else {
return
}
onboardingController.tryToVerify(fromViewController: self, verificationCode: onboardingCodeView.verificationCode, pin: nil)
}
}
// MARK: -
extension OnboardingVerificationViewController: OnboardingCodeViewDelegate {
public func codeViewDidChange() {
AssertIsOnMainThread()
tryToVerify()
}
}

@ -1535,6 +1535,36 @@
/* Title of the 'onboarding splash' view. */
"ONBOARDING_SPLASH_TITLE" = "Signal is the private messenger for everybody";
/* Label for the link that lets users change their phone number. */
"ONBOARDING_VERIFICATION_BACK_LINK" = "Wrong number?";
/* Format for the label of the 'pending code' label of the 'onboarding verification' view. Embeds {{the time until the code can be resent}}. */
"ONBOARDING_VERIFICATION_CODE_COUNTDOWN_FORMAT" = "I didn't get a code (available in %@)";
/* Label for link that can be used when the original code did not arrive. */
"ONBOARDING_VERIFICATION_ORIGINAL_CODE_MISSING_LINK" = "I didn't get a code";
/* Message for the 'resend code' alert in the 'onboarding verification' view. */
"ONBOARDING_VERIFICATION_RESEND_CODE_ALERT_MESSAGE" = "Please ensure that you have cellular service and can receive SMS messages.";
/* Title for the 'resend code' alert in the 'onboarding verification' view. */
"ONBOARDING_VERIFICATION_RESEND_CODE_ALERT_TITLE" = "No code?";
/* Label for the 'resend code by SMS' button in the 'onboarding verification' view. */
"ONBOARDING_VERIFICATION_RESEND_CODE_BY_SMS_BUTTON" = "Resend code";
/* Label for the 'resend code by voice' button in the 'onboarding verification' view. */
"ONBOARDING_VERIFICATION_RESEND_CODE_BY_VOICE_BUTTON" = "Call me instead";
/* Label for link that can be used when the resent code did not arrive. */
"ONBOARDING_VERIFICATION_RESENT_CODE_MISSING_LINK" = "Still no code?";
/* Format for the title of the 'onboarding verification' view. Embeds {{the user's phone number}}. */
"ONBOARDING_VERIFICATION_TITLE_DEFAULT_FORMAT" = "Enter the code we sent to %@";
/* Format for the title of the 'onboarding verification' view after the verification code has been resent. Embeds {{the user's phone number}}. */
"ONBOARDING_VERIFICATION_TITLE_RESENT_FORMAT" = "We just resent a code to %@";
/* Button text which opens the settings app */
"OPEN_SETTINGS_BUTTON" = "Settings";

@ -1,5 +1,5 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -167,4 +167,11 @@ public class OWSFlatButton: UIView {
internal func buttonPressed() {
pressedBlock?()
}
@objc
public func enableMultilineLabel() {
button.titleLabel?.numberOfLines = 0
button.titleLabel?.lineBreakMode = .byWordWrapping
button.titleLabel?.textAlignment = .center
}
}

@ -38,6 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Dynamic Type Clamped
@property (class, readonly, nonatomic) UIFont *ows_dynamicTypeLargeTitle1ClampedFont;
@property (class, readonly, nonatomic) UIFont *ows_dynamicTypeTitle1ClampedFont;
@property (class, readonly, nonatomic) UIFont *ows_dynamicTypeTitle2ClampedFont;
@property (class, readonly, nonatomic) UIFont *ows_dynamicTypeTitle3ClampedFont;

@ -107,6 +107,7 @@ NS_ASSUME_NONNULL_BEGIN
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
maxPointSizeMap = @{
UIFontTextStyleLargeTitle : @(40.0),
UIFontTextStyleTitle1 : @(34.0),
UIFontTextStyleTitle2 : @(28.0),
UIFontTextStyleTitle3 : @(26.0),
@ -132,6 +133,11 @@ NS_ASSUME_NONNULL_BEGIN
return font;
}
+ (UIFont *)ows_dynamicTypeLargeTitle1ClampedFont
{
return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleLargeTitle];
}
+ (UIFont *)ows_dynamicTypeTitle1ClampedFont
{
return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleTitle1];

@ -32,6 +32,8 @@ typedef NS_ENUM(NSUInteger, OWSRegistrationState) {
@property (nonatomic, nullable) NSString *phoneNumberAwaitingVerification;
#endif
- (void)setPhoneNumberAwaitingVerification:(NSString *_Nullable)phoneNumberAwaitingVerification;
#pragma mark - Initializers
- (instancetype)init NS_UNAVAILABLE;

@ -5,6 +5,10 @@
import Foundation
public extension String {
public var digitsOnly: String {
return (self as NSString).digitsOnly()
}
func rtlSafeAppend(_ string: String) -> String {
return (self as NSString).rtlSafeAppend(string)
}
@ -12,4 +16,8 @@ public extension String {
public func substring(from index: Int) -> String {
return String(self[self.index(self.startIndex, offsetBy: index)...])
}
public func substring(to index: Int) -> String {
return String(prefix(index))
}
}

Loading…
Cancel
Save