mirror of
https://github.com/AU-COVIDSafe/mobile-ios.git
synced 2025-04-19 04:55:19 +00:00
COVIDSafe code from version 1.4 (#3)
This commit is contained in:
parent
56c93f2079
commit
b2e0c5b34c
33 changed files with 6865 additions and 481 deletions
|
@ -8,14 +8,17 @@
|
|||
import UIKit
|
||||
import KeychainSwift
|
||||
|
||||
class InitialScreenViewController: UIViewController {
|
||||
class InitialScreenViewController: UIViewController, EncounterDBMigrationProgress {
|
||||
|
||||
let displayTimeSeconds: Int = 4
|
||||
let displayTimeSeconds = 4.0
|
||||
let giveupTimeSeconds = 8.0
|
||||
var migrationStart: Date?
|
||||
var isKeychainAvailable = false
|
||||
var isDisplayTimeElapsed = false
|
||||
let keychain = KeychainSwift()
|
||||
var giveupTimer: Timer?
|
||||
var initialDelayTimer: Timer?
|
||||
var migrationViewController: UIViewController?
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
@ -27,23 +30,26 @@ class InitialScreenViewController: UIViewController {
|
|||
NotificationCenter.default.addObserver(self, selector: #selector(setKeychainAvailable(_:)), name: UIApplication.protectedDataDidBecomeAvailableNotification, object: nil)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
view.window?.tintColor = .covidSafeColor
|
||||
|
||||
let showAppDelay = DispatchTime.now() + .seconds(displayTimeSeconds)
|
||||
DispatchQueue.main.asyncAfter(deadline: showAppDelay, execute: {
|
||||
self.isDisplayTimeElapsed = true
|
||||
if(self.proceedWithChecks()) {
|
||||
self.performCheck()
|
||||
}
|
||||
})
|
||||
continueAfterDelay(delay: displayTimeSeconds)
|
||||
// add give up action in case the keychain notification in not received after 8 seconds
|
||||
giveupTimer = Timer.scheduledTimer(withTimeInterval: giveupTimeSeconds, repeats: false) { timer in
|
||||
self.performSegue(withIdentifier: "initialPersonalDetailsSegue", sender: self)
|
||||
}
|
||||
EncounterDB.shared.setup(migrationDelegate: self)
|
||||
}
|
||||
|
||||
func continueAfterDelay(delay: TimeInterval) {
|
||||
initialDelayTimer = Timer.scheduledTimer(withTimeInterval: delay,
|
||||
repeats: false,
|
||||
block: { (_) in
|
||||
self.isDisplayTimeElapsed = true
|
||||
if(self.proceedWithChecks()) {
|
||||
self.performCheck()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@objc
|
||||
|
@ -61,9 +67,12 @@ class InitialScreenViewController: UIViewController {
|
|||
|
||||
private func performCheck() {
|
||||
giveupTimer?.invalidate()
|
||||
initialDelayTimer?.invalidate()
|
||||
if let migrationVc = migrationViewController {
|
||||
migrationVc.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
let isLoggedIn: Bool = (keychain.get("JWT_TOKEN") != nil)
|
||||
if !UserDefaults.standard.bool(forKey: "completedIWantToHelp") {
|
||||
// old app signed out here
|
||||
keychain.delete("JWT_TOKEN")
|
||||
self.performSegue(withIdentifier: "initialScreenToIWantToHelpSegue", sender: self)
|
||||
} else if !UserDefaults.standard.bool(forKey: "hasConsented") {
|
||||
|
@ -72,10 +81,40 @@ class InitialScreenViewController: UIViewController {
|
|||
self.performSegue(withIdentifier: "initialPersonalDetailsSegue", sender: self)
|
||||
} else if !UserDefaults.standard.bool(forKey: "allowedPermissions") {
|
||||
self.performSegue(withIdentifier: "initialScreenToAllowPermissionsSegue", sender: self)
|
||||
} else if !UserDefaults.standard.bool(forKey: "turnedOnBluetooth") {
|
||||
self.performSegue(withIdentifier: "initialScreenToTurnOnBtSegue", sender: self)
|
||||
} else {
|
||||
self.performSegue(withIdentifier: "initialScreenToHomeSegue", sender: self)
|
||||
}
|
||||
}
|
||||
|
||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||
if segue.identifier == "presentMigrationSegue" {
|
||||
migrationViewController = segue.destination
|
||||
}
|
||||
}
|
||||
|
||||
func migrationBegun() {
|
||||
DLog("MIGRATION BEGUN")
|
||||
giveupTimer?.invalidate()
|
||||
initialDelayTimer?.invalidate()
|
||||
migrationStart = Date()
|
||||
performSegue(withIdentifier: "presentMigrationSegue", sender: nil)
|
||||
}
|
||||
|
||||
func migrationComplete() {
|
||||
DLog("MIGRATION COMPLETE")
|
||||
if let migrationStart = migrationStart {
|
||||
let migrationDuration = abs(migrationStart.timeIntervalSinceNow)
|
||||
if migrationDuration > displayTimeSeconds {
|
||||
performCheck()
|
||||
} else {
|
||||
// migration was quick, still need to delay minimum 4 seconds
|
||||
DLog("Migration too quick, waiting \(displayTimeSeconds - migrationDuration) seconds")
|
||||
continueAfterDelay(delay: displayTimeSeconds - migrationDuration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func migrationFailed(error: Error) {
|
||||
fatalError("Migration Failed \(error)")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue