Skip to content

Commit

Permalink
Autoformat project
Browse files Browse the repository at this point in the history
  • Loading branch information
ivnsch committed Aug 2, 2020
1 parent 649c529 commit a6c6c75
Show file tree
Hide file tree
Showing 108 changed files with 1,362 additions and 1,304 deletions.
41 changes: 23 additions & 18 deletions CoEpi/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import UIKit
import CoreData
import Dip
import AppCenter
import AppCenterDistribute
import CoreData
import Dip
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -13,9 +13,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
private var rootWireframe: RootWireFrame?

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)
-> Bool {
_: UIApplication,
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?
)
-> Bool
{
MSAppCenter.start("2581ac81-eb5b-423a-83e6-65cab9d64dd8", withServices: [MSDistribute.self])

let bgManager: BackgroundTasksManager = try! container.resolve()
Expand All @@ -24,34 +26,37 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

func applicationDidEnterBackground(_ application: UIApplication) {
func applicationDidEnterBackground(_: UIApplication) {
let bgManager: BackgroundTasksManager = try! container.resolve()
bgManager.applicationDidEnterBackground()
}

// MARK: UISceneSession Lifecycle

func application(
_ application: UIApplication,
_: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions)
-> UISceneConfiguration {
options _: UIScene.ConnectionOptions
)
-> UISceneConfiguration
{
UISceneConfiguration(
name: "Default Configuration",
sessionRole: connectingSceneSession.role)
sessionRole: connectingSceneSession.role
)
}

// MARK: - Core Data stack

lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = NSPersistentContainer(name: "CoEpi")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
container.loadPersistentStores(completionHandler: { _, error in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
Expand All @@ -72,7 +77,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// MARK: - Core Data Saving support

func saveContext () {
func saveContext() {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
Expand Down
33 changes: 19 additions & 14 deletions CoEpi/Dependencies.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import Foundation
import Dip
import Foundation

class Dependencies {

func createContainer() -> DependencyContainer {

let container = DependencyContainer()

let fileSystem: FileSystem = FileSystemImpl()
container.register { fileSystem }

// NOTE: Has to be initialized before everything else (besides FileSystem)
// to ensure that core services are available to all dependencies.
// TODO consider initializing dependencies asynchronously.
// TODO: consider initializing dependencies asynchronously.
registerAndInitNativeCore(container: container, fileSystem: fileSystem)

let alertFilterSettings = AlertFilterSettings(
Expand Down Expand Up @@ -56,11 +54,11 @@ class Dependencies {
.register(.singleton) { nativeCore as ObservedTcnsRecorder }
container
.register(.singleton) { nativeCore as TcnGenerator }

}

private func registerViewModels(container: DependencyContainer,
alertFilterSettings: AlertFilterSettings) {
alertFilterSettings: AlertFilterSettings)
{
container.register { HomeViewModel(startPermissions: try container.resolve(),
rootNav: try container.resolve(),
alertRepo: try container.resolve(),
Expand Down Expand Up @@ -98,7 +96,8 @@ class Dependencies {
.register { SymptomReportViewModel(
symptomRepo: try container.resolve(),
rootNav: try container.resolve(),
symptomFlowManager: try container.resolve())}
symptomFlowManager: try container.resolve()
) }

container
.register { OnboardingWireframe(container: container) }
Expand All @@ -109,15 +108,17 @@ class Dependencies {
container
.register { AlertsViewModel(
alertRepo: try container.resolve(),
nav: try container.resolve()) }
nav: try container.resolve()
) }

container
.register { DebugBleViewModel(
bleAdapter: try container.resolve()) }
container
.register { LogsViewModel(
log: cachingLog, clipboard: try container.resolve(),
envInfos: try container.resolve()) }
envInfos: try container.resolve()
) }

container.register { AlertDetailsViewModel(pars: $0,
alertRepo: try container.resolve(),
Expand All @@ -140,7 +141,8 @@ class Dependencies {
.register(.singleton) { AlertRepoImpl(
alertsApi: try container.resolve(),
notificationShower: try container.resolve(),
alertFilters: try container.resolve()) as AlertRepo
alertFilters: try container.resolve()
) as AlertRepo
}
}

Expand All @@ -155,12 +157,13 @@ class Dependencies {
container
.register(.eagerSingleton) { FetchAlertsBackgroundRegisterer(
tasksManager: try container.resolve(),
alertRepo: try container.resolve()) }
alertRepo: try container.resolve()
) }
container.register(.eagerSingleton) { NotificationsDelegate(
rootNav: try container.resolve()) }
}

private func registerLogic(container: DependencyContainer) {
private func registerLogic(container _: DependencyContainer) {
// container.register(.eagerSingleton) { AlertNotificationsShower(alertsRepo: try container.resolve()) }
}

Expand All @@ -171,7 +174,8 @@ class Dependencies {
container
.register(.eagerSingleton) { ScannedCensHandler(
bleAdapter: try container.resolve(),
tcnsRecorder: try container.resolve())}
tcnsRecorder: try container.resolve()
) }
container
.register(.eagerSingleton) { PeriodicAlertsFetcher(
alertRepo: try container.resolve()) }
Expand All @@ -185,7 +189,8 @@ class Dependencies {
.register(.singleton) { SymptomFlowManager(
symptomRouter: try container.resolve(),
rootNavigation: try container.resolve(),
inputsManager: try container.resolve()) }
inputsManager: try container.resolve()
) }
container.register {
ObservableAlertFiltersImpl(
kvStore: try container.resolve(),
Expand Down
10 changes: 5 additions & 5 deletions CoEpi/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import UIKit
import SwiftUI
import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?
private var rootWireframe: RootWireFrame?

lazy var container = (UIApplication.shared.delegate as! AppDelegate).container

func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
willConnectTo _: UISceneSession,
options _: UIScene.ConnectionOptions
) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
rootWireframe = RootWireFrame(container: container, window: window)
self.window = window
}
}

func sceneDidBecomeActive(_ scene: UIScene) {
func sceneDidBecomeActive(_: UIScene) {
let badgeUpdater: AppBadgeUpdater = try! container.resolve()
badgeUpdater.updateAppBadge(number: 0)

Expand Down
3 changes: 1 addition & 2 deletions CoEpi/bg task/BackgroundTask.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import Foundation
import BackgroundTasks
import Foundation
import RxSwift

/// Long running background task
protocol BackgroundTask {

var identifier: String { get }

var scheduleInterval: TimeInterval { get }
Expand Down
11 changes: 5 additions & 6 deletions CoEpi/bg task/BackgroundTaskScheduler.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import UIKit
import BackgroundTasks
import UIKit

/// Registers and schedules background processing tasks
class BackgroundTaskScheduler {

private let task: BackgroundTask

init(task: BackgroundTask) {
Expand Down Expand Up @@ -43,10 +42,10 @@ class BackgroundTaskScheduler {
let request = BGProcessingTaskRequest(identifier: task.identifier)
request.earliestBeginDate = Date(timeIntervalSinceNow: delay)
do {
// NOTE: This has to be called on a bg thread if used while app is launched.
// Not needed if used when app is send to bg.
// TODO flag to use bg thread. Or maybe just use always thread.
try BGTaskScheduler.shared.submit(request)
// NOTE: This has to be called on a bg thread if used while app is launched.
// Not needed if used when app is send to bg.
// TODO: flag to use bg thread. Or maybe just use always thread.
try BGTaskScheduler.shared.submit(request)
} catch let e {
log.e("Unable to submit task: \(request), error: \(e)")
}
Expand Down
1 change: 0 additions & 1 deletion CoEpi/bg task/BackgroundTasksManager.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import BackgroundTasks

class BackgroundTasksManager {

private var tasks: [BackgroundTaskScheduler] = []

func register(task: BackgroundTask) {
Expand Down
1 change: 0 additions & 1 deletion CoEpi/bg task/alerts/FetchAlertsBackgroundRegisterer.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class FetchAlertsBackgroundRegisterer {

init(tasksManager: BackgroundTasksManager, alertRepo: AlertRepo) {
tasksManager.register(task: FetchAlertsBackgroundTask(alertRepo: alertRepo))
}
Expand Down
8 changes: 3 additions & 5 deletions CoEpi/bg task/alerts/FetchAlertsBackgroundTask.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import RxSwift
import BackgroundTasks
import Action
import BackgroundTasks
import RxSwift

class FetchAlertsBackgroundTask: BackgroundTask {

let identifier: String = "org.coepi.tcn_matching"

let scheduleInterval: TimeInterval = 60 * 60 // 1h
Expand All @@ -20,10 +19,9 @@ class FetchAlertsBackgroundTask: BackgroundTask {
.asVoidObservable()
}
self.fetchAlertsAction = fetchAlertsAction

}

func execute(task: BGProcessingTask) {
func execute(task _: BGProcessingTask) {
log.d("Starting fetch alerts bg task...")

fetchAlertsAction.execute()
Expand Down
13 changes: 6 additions & 7 deletions CoEpi/ble/BleAdapter.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import TCNClient
import RxSwift
import TCNClient

class BleAdapter {
private let tcnService: TCNBluetoothService
Expand All @@ -9,12 +9,11 @@ class BleAdapter {
let myTcn: ReplaySubject<String> = .create(bufferSize: 1)

init(tcnGenerator: TcnGenerator) {

// Sometimes the device appears to observe its own TCN
// This is a quick fix to alleviate this
// (It does not handle multiple devices reading simultaneously, in which case the device still could
// observe its own TCN)
// TODO investigate why it happens.
// TODO: investigate why it happens.
var lastGeneratedTcn: Data?

tcnService = TCNBluetoothService(tcnGenerator: { [myTcn] in
Expand All @@ -23,21 +22,21 @@ class BleAdapter {

return {
switch tcnResult {
case .success(let data):
case let .success(data):
myTcn.onNext(data.toHex())
lastGeneratedTcn = data
return data
case .failure(let error):
case let .failure(error):
fatalError("Couldn't generate TCN: \(error)")
}
}()

}, tcnFinder: { [discovered] (data, distance) in
}, tcnFinder: { [discovered] data, distance in
if lastGeneratedTcn != data {
discovered.onNext((data, Float(distance ?? 0)))
}
}) { error in
// TODO What kind of errors? Should we notify the user?
// TODO: What kind of errors? Should we notify the user?
log.e("TCN service error: \(error)")
}

Expand Down
Loading

0 comments on commit a6c6c75

Please sign in to comment.