Merge branch 'master' into tweak-share-app-screen-text

pull/234/head
James Sangalli 7 years ago committed by GitHub
commit 0af42e8097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift
  2. 18
      Trust/Protection/Coordinators/ProtectionCoordinator.swift
  3. 12
      TrustTests/Coordinators/LockEnterPasscodeCoordinatorTest.swift

@ -5,8 +5,7 @@ import UIKit
class LockEnterPasscodeCoordinator: Coordinator { class LockEnterPasscodeCoordinator: Coordinator {
var coordinators: [Coordinator] = [] var coordinators: [Coordinator] = []
var protectionWasShown = false let window: UIWindow = UIWindow()
private let window: UIWindow = UIWindow()
private let model: LockEnterPasscodeViewModel private let model: LockEnterPasscodeViewModel
private let lock: LockInterface private let lock: LockInterface
private lazy var lockEnterPasscodeViewController: LockEnterPasscodeViewController = { private lazy var lockEnterPasscodeViewController: LockEnterPasscodeViewController = {
@ -20,21 +19,20 @@ class LockEnterPasscodeCoordinator: Coordinator {
if state { if state {
self?.stop() self?.stop()
} }
self?.protectionWasShown = bioUnlock
} }
} }
func start() { func start() {
guard lock.isPasscodeSet() else { guard lock.isPasscodeSet() else { return }
return
}
protectionWasShown = true
window.rootViewController = lockEnterPasscodeViewController window.rootViewController = lockEnterPasscodeViewController
window.makeKeyAndVisible() window.makeKeyAndVisible()
//Because of the usage of the window and rootViewController we are not able to receive properly view life circle events. So we should call this methods manually.
lockEnterPasscodeViewController.showKeyboard()
lockEnterPasscodeViewController.showBioMerickAuth()
} }
func stop() { func stop() {
window.isHidden = true window.isHidden = true
} }
func showAuthentication() {
guard lock.isPasscodeSet() else { return }
lockEnterPasscodeViewController.showKeyboard()
lockEnterPasscodeViewController.showBioMerickAuth()
}
} }

@ -19,29 +19,25 @@ class ProtectionCoordinator: Coordinator {
func didFinishLaunchingWithOptions() { func didFinishLaunchingWithOptions() {
splashCoordinator.start() splashCoordinator.start()
lockEnterPasscodeCoordinator.start() lockEnterPasscodeCoordinator.start()
} lockEnterPasscodeCoordinator.showAuthentication()
func applicationWillResignActive() {
splashCoordinator.start()
} }
func applicationDidBecomeActive() { func applicationDidBecomeActive() {
//We track protectionWasShown because of the Touch ID that will trigger applicationDidBecomeActive method after valdiation. splashCoordinator.stop()
if !lockEnterPasscodeCoordinator.protectionWasShown {
lockEnterPasscodeCoordinator.start()
} else {
lockEnterPasscodeCoordinator.protectionWasShown = false
} }
//We should dismiss spalsh screen when app become active. func applicationWillResignActive() {
splashCoordinator.stop() splashCoordinator.start()
} }
func applicationDidEnterBackground() { func applicationDidEnterBackground() {
splashCoordinator.start() splashCoordinator.start()
lockEnterPasscodeCoordinator.start()
} }
func applicationWillEnterForeground() { func applicationWillEnterForeground() {
splashCoordinator.stop() splashCoordinator.stop()
lockEnterPasscodeCoordinator.start()
lockEnterPasscodeCoordinator.showAuthentication()
} }
} }

@ -8,26 +8,26 @@ class LockEnterPasscodeCoordinatorTest: XCTestCase {
let viewModel = LockEnterPasscodeViewModel() let viewModel = LockEnterPasscodeViewModel()
let fakeLock = FakeLockProtocol() let fakeLock = FakeLockProtocol()
let coordinator = LockEnterPasscodeCoordinator(model: viewModel, lock: fakeLock) let coordinator = LockEnterPasscodeCoordinator(model: viewModel, lock: fakeLock)
XCTAssertFalse(coordinator.protectionWasShown) XCTAssertTrue(coordinator.window.isHidden)
coordinator.start() coordinator.start()
XCTAssertTrue(coordinator.protectionWasShown) XCTAssertFalse(coordinator.window.isHidden)
} }
func testStop() { func testStop() {
let viewModel = LockEnterPasscodeViewModel() let viewModel = LockEnterPasscodeViewModel()
let fakeLock = FakeLockProtocol() let fakeLock = FakeLockProtocol()
let coordinator = LockEnterPasscodeCoordinator(model: viewModel, lock: fakeLock) let coordinator = LockEnterPasscodeCoordinator(model: viewModel, lock: fakeLock)
XCTAssertFalse(coordinator.protectionWasShown)
coordinator.start() coordinator.start()
XCTAssertTrue(coordinator.protectionWasShown) XCTAssertFalse(coordinator.window.isHidden)
coordinator.stop() coordinator.stop()
XCTAssertTrue(coordinator.window.isHidden)
} }
func testDisableLock() { func testDisableLock() {
let viewModel = LockEnterPasscodeViewModel() let viewModel = LockEnterPasscodeViewModel()
let fakeLock = FakeLockProtocol() let fakeLock = FakeLockProtocol()
fakeLock.passcodeSet = false fakeLock.passcodeSet = false
let coordinator = LockEnterPasscodeCoordinator(model: viewModel, lock: fakeLock) let coordinator = LockEnterPasscodeCoordinator(model: viewModel, lock: fakeLock)
XCTAssertFalse(coordinator.protectionWasShown) XCTAssertTrue(coordinator.window.isHidden)
coordinator.start() coordinator.start()
XCTAssertFalse(coordinator.protectionWasShown) XCTAssertTrue(coordinator.window.isHidden)
} }
} }

Loading…
Cancel
Save