Keep original view mode, fixes

This commit is contained in:
ismailgulek
2020-09-17 20:37:52 +03:00
parent 4aec7ae0bb
commit 5056924abf
2 changed files with 24 additions and 10 deletions

View File

@@ -25,6 +25,7 @@ final class EnterPinCodeViewModel: EnterPinCodeViewModelType {
// MARK: Private
private let session: MXSession?
private var originalViewMode: SetPinCoordinatorViewMode
private var viewMode: SetPinCoordinatorViewMode
private var firstPin: String = ""
@@ -45,6 +46,7 @@ final class EnterPinCodeViewModel: EnterPinCodeViewModelType {
init(session: MXSession?, viewMode: SetPinCoordinatorViewMode, pinCodePreferences: PinCodePreferences) {
self.session = session
self.originalViewMode = viewMode
self.viewMode = viewMode
self.pinCodePreferences = pinCodePreferences
}
@@ -88,9 +90,9 @@ final class EnterPinCodeViewModel: EnterPinCodeViewModelType {
// switch to setPin if blocked
if viewMode == .notAllowedPin {
// clear error UI
update(viewState: .choosePin)
// switch to normal flow
viewMode = .setPin
update(viewState: viewState(for: originalViewMode))
// switch back to original flow
viewMode = originalViewMode
}
}
} else {
@@ -101,16 +103,16 @@ final class EnterPinCodeViewModel: EnterPinCodeViewModelType {
// clear old pin first
currentPin.removeAll()
// clear error UI
update(viewState: .choosePin)
// switch to normal flow
viewMode = .setPin
update(viewState: viewState(for: originalViewMode))
// switch back to original flow
viewMode = originalViewMode
}
// add new digit
currentPin += String(tag)
if currentPin.count == pinCodePreferences.numberOfDigits {
switch viewMode {
case .setPin:
case .setPin, .setPinAfterLogin, .setPinAfterRegister:
// choosing pin
if firstPin.isEmpty {
// check if this PIN is allowed
@@ -164,10 +166,23 @@ final class EnterPinCodeViewModel: EnterPinCodeViewModelType {
}
}
private func viewState(for mode: SetPinCoordinatorViewMode) -> EnterPinCodeViewState {
switch mode {
case .setPin:
return .choosePin
case .setPinAfterLogin:
return .choosePinAfterLogin
case .setPinAfterRegister:
return .choosePinAfterRegister
default:
return .inactive
}
}
private func loadData() {
switch viewMode {
case .setPin:
update(viewState: .choosePin)
case .setPin, .setPinAfterLogin, .setPinAfterRegister:
update(viewState: viewState(for: viewMode))
self.viewDelegate?.enterPinCodeViewModel(self, didUpdateCancelButtonHidden: pinCodePreferences.forcePinProtection)
case .unlock:
update(viewState: .unlock)