Respond to CR.

pull/2/head
Matthew Chen 7 years ago
parent b4aec58795
commit e1dc534fe6

@ -201,7 +201,7 @@ public class OnboardingController: NSObject {
Logger.info("") Logger.info("")
self.backup.checkCanImport({ (canImport) in backup.checkCanImport({ (canImport) in
Logger.info("canImport: \(canImport)") Logger.info("canImport: \(canImport)")
if (canImport) { if (canImport) {
@ -211,9 +211,9 @@ public class OnboardingController: NSObject {
} else { } else {
self.showProfileView(fromView: view) self.showProfileView(fromView: view)
} }
}) { (_) in }, failure: { (_) in
self.showBackupCheckFailedAlert(fromView: view) self.showBackupCheckFailedAlert(fromView: view)
} })
} }
private func showBackupCheckFailedAlert(fromView view: UIViewController) { private func showBackupCheckFailedAlert(fromView view: UIViewController) {

@ -152,7 +152,7 @@ private class OnboardingCodeView: UIView {
guard index < digitText.count else { guard index < digitText.count else {
return "" return ""
} }
return digitText.substring(from: index).trim(after: 1) return digitText.substring(from: index).substring(to: 1)
} }
// Ensure that all labels are displaying the correct // Ensure that all labels are displaying the correct
@ -199,10 +199,10 @@ extension OnboardingCodeView: UITextFieldDelegate {
let unfiltered = left + newString + right let unfiltered = left + newString + right
let characterSet = CharacterSet(charactersIn: "0123456789") let characterSet = CharacterSet(charactersIn: "0123456789")
let filtered = unfiltered.components(separatedBy: characterSet.inverted).joined() let filtered = unfiltered.components(separatedBy: characterSet.inverted).joined()
let filteredAndTrimmed = filtered.trim(after: 1) let filteredAndTrimmed = filtered.substring(to: 1)
textField.text = filteredAndTrimmed textField.text = filteredAndTrimmed
digitText = digitText.trim(after: currentDigitIndex) + filteredAndTrimmed digitText = digitText.substring(to: currentDigitIndex) + filteredAndTrimmed
updateViewState() updateViewState()
@ -238,14 +238,14 @@ extension OnboardingCodeView: OnboardingCodeViewTextFieldDelegate {
public class OnboardingVerificationViewController: OnboardingBaseViewController { public class OnboardingVerificationViewController: OnboardingBaseViewController {
private enum CodeState { private enum CodeState {
case pending case sent
case possiblyNotDelivered case readyForResend
case resent case resent
} }
// MARK: - // MARK: -
private var codeState = CodeState.pending private var codeState = CodeState.sent
private var titleLabel: UILabel? private var titleLabel: UILabel?
private let phoneNumberTextField = UITextField() private let phoneNumberTextField = UITextField()
@ -308,14 +308,12 @@ public class OnboardingVerificationViewController: OnboardingBaseViewController
private var codeCountdownStart: NSDate? private var codeCountdownStart: NSDate?
deinit { deinit {
if let codeCountdownTimer = codeCountdownTimer { codeCountdownTimer?.invalidate()
codeCountdownTimer.invalidate()
}
} }
private func startCodeCountdown() { private func startCodeCountdown() {
codeCountdownStart = NSDate() codeCountdownStart = NSDate()
codeCountdownTimer = Timer.weakScheduledTimer(withTimeInterval: 1, target: self, selector: #selector(codeCountdownTimerFired), userInfo: nil, repeats: true) codeCountdownTimer = Timer.weakScheduledTimer(withTimeInterval: 0.25, target: self, selector: #selector(codeCountdownTimerFired), userInfo: nil, repeats: true)
} }
@objc @objc
@ -336,10 +334,10 @@ public class OnboardingVerificationViewController: OnboardingBaseViewController
codeCountdownTimer.invalidate() codeCountdownTimer.invalidate()
self.codeCountdownTimer = nil self.codeCountdownTimer = nil
if codeState != .pending { if codeState != .sent {
owsFailDebug("Unexpected codeState: \(codeState)") owsFailDebug("Unexpected codeState: \(codeState)")
} }
codeState = .possiblyNotDelivered codeState = .readyForResend
updateCodeState() updateCodeState()
return return
} }
@ -372,7 +370,7 @@ public class OnboardingVerificationViewController: OnboardingBaseViewController
// Update titleLabel // Update titleLabel
switch codeState { switch codeState {
case .pending, .possiblyNotDelivered: case .sent, .readyForResend:
titleLabel.text = String(format: NSLocalizedString("ONBOARDING_VERIFICATION_TITLE_DEFAULT_FORMAT", 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}}."), comment: "Format for the title of the 'onboarding verification' view. Embeds {{the user's phone number}}."),
formattedPhoneNumber) formattedPhoneNumber)
@ -384,16 +382,15 @@ public class OnboardingVerificationViewController: OnboardingBaseViewController
// Update codeStateLink // Update codeStateLink
switch codeState { switch codeState {
case .pending: case .sent:
let countdownInterval = abs(codeCountdownStart.timeIntervalSinceNow) let countdownInterval = abs(codeCountdownStart.timeIntervalSinceNow)
let countdownRemaining = max(0, countdownDuration - countdownInterval) let countdownRemaining = max(0, countdownDuration - countdownInterval)
let formattedCountdown = OWSFormat.formatDurationSeconds(Int(round(countdownRemaining))) let formattedCountdown = OWSFormat.formatDurationSeconds(Int(round(countdownRemaining)))
let text = String(format: NSLocalizedString("ONBOARDING_VERIFICATION_CODE_COUNTDOWN_FORMAT", let text = String(format: NSLocalizedString("ONBOARDING_VERIFICATION_CODE_COUNTDOWN_FORMAT",
comment: "Format for the label of the 'pending code' label of the 'onboarding verification' view. Embeds {{the time until the code can be resent}}."), 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) formattedCountdown)
codeStateLink.setTitle(title: text, font: .ows_dynamicTypeBodyClamped, titleColor: Theme.secondaryColor) codeStateLink.setTitle(title: text, font: .ows_dynamicTypeBodyClamped, titleColor: Theme.secondaryColor)
// codeStateLink.setBackgroundColors(upColor: Theme.backgroundColor) case .readyForResend:
case .possiblyNotDelivered:
codeStateLink.setTitle(title: NSLocalizedString("ONBOARDING_VERIFICATION_ORIGINAL_CODE_MISSING_LINK", 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."), comment: "Label for link that can be used when the original code did not arrive."),
font: .ows_dynamicTypeBodyClamped, font: .ows_dynamicTypeBodyClamped,
@ -424,10 +421,10 @@ public class OnboardingVerificationViewController: OnboardingBaseViewController
Logger.info("") Logger.info("")
switch codeState { switch codeState {
case .pending: case .sent:
// Ignore taps until the countdown expires. // Ignore taps until the countdown expires.
break break
case .possiblyNotDelivered, .resent: case .readyForResend, .resent:
showResendActionSheet() showResendActionSheet()
} }
} }

@ -18,12 +18,6 @@ public extension String {
} }
public func substring(to index: Int) -> String { public func substring(to index: Int) -> String {
return String(self[..<self.index(self.startIndex, offsetBy: index)]) return String(prefix(index))
}
// Ensures that the result is <= in length the maxCount.
public func trim(after maxCount: Int) -> String {
let index = min(maxCount, self.count)
return substring(to: index)
} }
} }

Loading…
Cancel
Save