2016-06-14 09:13:48 -04:00
|
|
|
package eu.kanade.tachiyomi
|
|
|
|
|
|
|
|
import android.app.Application
|
|
|
|
import com.google.gson.Gson
|
|
|
|
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
|
|
|
import eu.kanade.tachiyomi.data.cache.CoverCache
|
|
|
|
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|
|
|
import eu.kanade.tachiyomi.data.download.DownloadManager
|
|
|
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
2017-01-20 15:22:17 -05:00
|
|
|
import eu.kanade.tachiyomi.data.track.TrackManager
|
2018-02-05 16:50:56 -05:00
|
|
|
import eu.kanade.tachiyomi.extension.ExtensionManager
|
2017-01-20 15:34:15 -05:00
|
|
|
import eu.kanade.tachiyomi.network.NetworkHelper
|
|
|
|
import eu.kanade.tachiyomi.source.SourceManager
|
2018-02-06 05:42:38 -05:00
|
|
|
import rx.Observable
|
|
|
|
import rx.schedulers.Schedulers
|
2018-02-05 16:50:56 -05:00
|
|
|
import uy.kohesive.injekt.api.*
|
2016-06-14 09:13:48 -04:00
|
|
|
|
|
|
|
class AppModule(val app: Application) : InjektModule {
|
|
|
|
|
|
|
|
override fun InjektRegistrar.registerInjectables() {
|
|
|
|
|
2018-02-05 16:50:56 -05:00
|
|
|
addSingleton(app)
|
2016-06-14 09:13:48 -04:00
|
|
|
|
2018-02-05 16:50:56 -05:00
|
|
|
addSingletonFactory { PreferencesHelper(app) }
|
2016-06-14 09:13:48 -04:00
|
|
|
|
2018-02-05 16:50:56 -05:00
|
|
|
addSingletonFactory { DatabaseHelper(app) }
|
2016-06-14 09:13:48 -04:00
|
|
|
|
2018-02-05 16:50:56 -05:00
|
|
|
addSingletonFactory { ChapterCache(app) }
|
2016-06-14 09:13:48 -04:00
|
|
|
|
2018-02-05 16:50:56 -05:00
|
|
|
addSingletonFactory { CoverCache(app) }
|
2016-06-14 09:13:48 -04:00
|
|
|
|
2018-02-05 16:50:56 -05:00
|
|
|
addSingletonFactory { NetworkHelper(app) }
|
2016-06-14 09:13:48 -04:00
|
|
|
|
2018-02-05 16:50:56 -05:00
|
|
|
addSingletonFactory { SourceManager(app).also { get<ExtensionManager>().init(it) } }
|
2016-06-14 09:13:48 -04:00
|
|
|
|
2018-02-05 16:50:56 -05:00
|
|
|
addSingletonFactory { ExtensionManager(app) }
|
2016-06-14 09:13:48 -04:00
|
|
|
|
2018-02-05 16:50:56 -05:00
|
|
|
addSingletonFactory { DownloadManager(app) }
|
|
|
|
|
|
|
|
addSingletonFactory { TrackManager(app) }
|
|
|
|
|
|
|
|
addSingletonFactory { Gson() }
|
|
|
|
|
|
|
|
// Asynchronously init expensive components for a faster cold start
|
|
|
|
|
2018-02-06 05:42:38 -05:00
|
|
|
rxAsync { get<PreferencesHelper>() }
|
2018-02-05 16:50:56 -05:00
|
|
|
|
2018-02-06 05:42:38 -05:00
|
|
|
rxAsync { get<NetworkHelper>() }
|
2018-02-05 16:50:56 -05:00
|
|
|
|
2018-02-06 05:42:38 -05:00
|
|
|
rxAsync { get<SourceManager>() }
|
2018-02-05 16:50:56 -05:00
|
|
|
|
2018-02-06 05:42:38 -05:00
|
|
|
rxAsync { get<DatabaseHelper>() }
|
2018-02-05 16:50:56 -05:00
|
|
|
|
2018-02-06 05:42:38 -05:00
|
|
|
rxAsync { get<DownloadManager>() }
|
2016-06-14 09:13:48 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-06 05:42:38 -05:00
|
|
|
private fun rxAsync(block: () -> Unit) {
|
|
|
|
Observable.fromCallable { block() }.subscribeOn(Schedulers.computation()).subscribe()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|