Restore Backend class; replace TaskRunner by Kotlin Coroutines

This commit is contained in:
2019-04-13 09:20:37 -05:00
parent b0cedde0a9
commit 5ea19c9475
26 changed files with 313 additions and 405 deletions

View File

@@ -19,27 +19,36 @@
import UIKit
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, BackendListener {
var window: UIWindow?
var backend = Backend(databaseName: "dev.db",
databaseOpener: IosDatabaseOpener(withLog: StandardLog()),
fileOpener: IosFileOpener(),
localeHelper: IosLocaleHelper(NSLocale.preferredLanguages),
log: StandardLog(),
taskRunner: SequentialTaskRunner())
var nav: UINavigationController?
let log = StandardLog()
var backend: Backend?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
backend = Backend(databaseName: "uhabits.db",
databaseOpener: IosDatabaseOpener(withLog: log),
fileOpener: IosFileOpener(),
localeHelper: IosLocaleHelper(NSLocale.preferredLanguages),
log: log,
crCtx: UIDispatcher())
backend?.observable.addListener(listener: self)
backend?.doInit()
window = UIWindow(frame: UIScreen.main.bounds)
if let window = window {
let nav = UINavigationController()
nav.viewControllers = [MainScreenController(withBackend: backend)]
window.backgroundColor = UIColor.white
window.rootViewController = nav
window.makeKeyAndVisible()
}
nav = UINavigationController()
window?.backgroundColor = UIColor.white
window?.rootViewController = nav
window?.makeKeyAndVisible()
return true
}
func onReady() {
nav?.viewControllers = [MainScreenController(withBackend: backend!)]
}
}

View File

@@ -100,7 +100,7 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
var preferences: Preferences
var theme: Theme
var nButtons = 3
var strings: Strings
var strings = Strings()
required init?(coder aDecoder: NSCoder) {
fatalError()
@@ -109,9 +109,9 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
init(withBackend backend:Backend) {
self.backend = backend
self.strings = backend.strings
self.dataSource = backend.mainScreenDataSource!
self.dataSource = backend.mainScreenDataSource
self.theme = backend.theme
self.preferences = backend.preferences!
self.preferences = backend.preferences
super.init(nibName: nil, bundle: nil)
self.dataSource.observable.addListener(listener: self)
self.dataSource.requestData()
@@ -189,7 +189,7 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
@objc func onMoreActionsClicked() {
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
if preferences.showArchived {
alert.addAction(UIAlertAction(title: strings.hide_archived, style: .default) {
(action: UIAlertAction) -> Void in
@@ -203,7 +203,7 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
self.dataSource.requestData()
})
}
if preferences.showCompleted {
alert.addAction(UIAlertAction(title: strings.hide_completed, style: .default) {
(action: UIAlertAction) -> Void in
@@ -217,7 +217,7 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
self.dataSource.requestData()
})
}
if preferences.nightMode {
alert.addAction(UIAlertAction(title: strings.day_mode, style: .default) {
(action: UIAlertAction) -> Void in
@@ -229,7 +229,7 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
self.preferences.nightMode = true
})
}
alert.addAction(UIAlertAction(title: strings.help, style: .default) {
(action: UIAlertAction) -> Void in
if let link = URL(string: "http://loophabits.org/faq") {

View File

@@ -124,7 +124,7 @@ class IosDatabaseOpener : NSObject, DatabaseOpener {
}
func open(file: UserFile) -> Database {
let dbPath = (file as! IosUserFile).path
let dbPath = (file as! IosFile).path
let version = String(cString: sqlite3_libversion())
log.info(tag: "IosDatabaseOpener", msg: "SQLite \(version)")