From e1dc534fe69cbb40ae2f6dfe198942d45f7365dc Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 18 Feb 2019 09:52:09 -0500 Subject: [PATCH] Respond to CR. --- .../Registration/OnboardingController.swift | 6 ++-- ...OnboardingVerificationViewController.swift | 35 +++++++++---------- SignalServiceKit/src/Util/String+SSK.swift | 8 +---- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/Signal/src/ViewControllers/Registration/OnboardingController.swift b/Signal/src/ViewControllers/Registration/OnboardingController.swift index e500f393f..000cce21f 100644 --- a/Signal/src/ViewControllers/Registration/OnboardingController.swift +++ b/Signal/src/ViewControllers/Registration/OnboardingController.swift @@ -201,7 +201,7 @@ public class OnboardingController: NSObject { Logger.info("") - self.backup.checkCanImport({ (canImport) in + backup.checkCanImport({ (canImport) in Logger.info("canImport: \(canImport)") if (canImport) { @@ -211,9 +211,9 @@ public class OnboardingController: NSObject { } else { self.showProfileView(fromView: view) } - }) { (_) in + }, failure: { (_) in self.showBackupCheckFailedAlert(fromView: view) - } + }) } private func showBackupCheckFailedAlert(fromView view: UIViewController) { diff --git a/Signal/src/ViewControllers/Registration/OnboardingVerificationViewController.swift b/Signal/src/ViewControllers/Registration/OnboardingVerificationViewController.swift index f5e64af43..751aa2d8b 100644 --- a/Signal/src/ViewControllers/Registration/OnboardingVerificationViewController.swift +++ b/Signal/src/ViewControllers/Registration/OnboardingVerificationViewController.swift @@ -152,7 +152,7 @@ private class OnboardingCodeView: UIView { guard index < digitText.count else { 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 @@ -199,10 +199,10 @@ extension OnboardingCodeView: UITextFieldDelegate { let unfiltered = left + newString + right let characterSet = CharacterSet(charactersIn: "0123456789") let filtered = unfiltered.components(separatedBy: characterSet.inverted).joined() - let filteredAndTrimmed = filtered.trim(after: 1) + let filteredAndTrimmed = filtered.substring(to: 1) textField.text = filteredAndTrimmed - digitText = digitText.trim(after: currentDigitIndex) + filteredAndTrimmed + digitText = digitText.substring(to: currentDigitIndex) + filteredAndTrimmed updateViewState() @@ -238,14 +238,14 @@ extension OnboardingCodeView: OnboardingCodeViewTextFieldDelegate { public class OnboardingVerificationViewController: OnboardingBaseViewController { private enum CodeState { - case pending - case possiblyNotDelivered + case sent + case readyForResend case resent } // MARK: - - private var codeState = CodeState.pending + private var codeState = CodeState.sent private var titleLabel: UILabel? private let phoneNumberTextField = UITextField() @@ -308,14 +308,12 @@ public class OnboardingVerificationViewController: OnboardingBaseViewController private var codeCountdownStart: NSDate? deinit { - if let codeCountdownTimer = codeCountdownTimer { - codeCountdownTimer.invalidate() - } + codeCountdownTimer?.invalidate() } private func startCodeCountdown() { 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 @@ -336,10 +334,10 @@ public class OnboardingVerificationViewController: OnboardingBaseViewController codeCountdownTimer.invalidate() self.codeCountdownTimer = nil - if codeState != .pending { + if codeState != .sent { owsFailDebug("Unexpected codeState: \(codeState)") } - codeState = .possiblyNotDelivered + codeState = .readyForResend updateCodeState() return } @@ -372,7 +370,7 @@ public class OnboardingVerificationViewController: OnboardingBaseViewController // Update titleLabel switch codeState { - case .pending, .possiblyNotDelivered: + 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) @@ -384,16 +382,15 @@ public class OnboardingVerificationViewController: OnboardingBaseViewController // Update codeStateLink switch codeState { - case .pending: + 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 '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) codeStateLink.setTitle(title: text, font: .ows_dynamicTypeBodyClamped, titleColor: Theme.secondaryColor) -// codeStateLink.setBackgroundColors(upColor: Theme.backgroundColor) - case .possiblyNotDelivered: + 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, @@ -424,10 +421,10 @@ public class OnboardingVerificationViewController: OnboardingBaseViewController Logger.info("") switch codeState { - case .pending: + case .sent: // Ignore taps until the countdown expires. break - case .possiblyNotDelivered, .resent: + case .readyForResend, .resent: showResendActionSheet() } } diff --git a/SignalServiceKit/src/Util/String+SSK.swift b/SignalServiceKit/src/Util/String+SSK.swift index 6312dd677..3b6684c5e 100644 --- a/SignalServiceKit/src/Util/String+SSK.swift +++ b/SignalServiceKit/src/Util/String+SSK.swift @@ -18,12 +18,6 @@ public extension String { } public func substring(to index: Int) -> String { - return String(self[.. String { - let index = min(maxCount, self.count) - return substring(to: index) + return String(prefix(index)) } }