mihon/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt

60 lines
1.8 KiB
Kotlin
Raw Normal View History

package eu.kanade.tachiyomi
import android.app.Application
2021-06-05 17:49:20 -04:00
import androidx.core.content.ContextCompat
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
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
2020-11-01 15:12:16 -05:00
import kotlinx.serialization.json.Json
2020-02-26 18:12:44 -05:00
import uy.kohesive.injekt.api.InjektModule
import uy.kohesive.injekt.api.InjektRegistrar
import uy.kohesive.injekt.api.addSingleton
import uy.kohesive.injekt.api.addSingletonFactory
import uy.kohesive.injekt.api.get
class AppModule(val app: Application) : InjektModule {
override fun InjektRegistrar.registerInjectables() {
addSingleton(app)
addSingletonFactory { PreferencesHelper(app) }
addSingletonFactory { DatabaseHelper(app) }
addSingletonFactory { ChapterCache(app) }
addSingletonFactory { CoverCache(app) }
addSingletonFactory { NetworkHelper(app) }
addSingletonFactory { SourceManager(app).also { get<ExtensionManager>().init(it) } }
addSingletonFactory { ExtensionManager(app) }
addSingletonFactory { DownloadManager(app) }
addSingletonFactory { TrackManager(app) }
2020-11-01 15:12:16 -05:00
addSingletonFactory { Json { ignoreUnknownKeys = true } }
// Asynchronously init expensive components for a faster cold start
2021-06-05 17:49:20 -04:00
ContextCompat.getMainExecutor(app).execute {
2021-01-10 11:01:10 -05:00
get<PreferencesHelper>()
2021-01-10 11:01:10 -05:00
get<NetworkHelper>()
2021-01-10 11:01:10 -05:00
get<SourceManager>()
2021-01-10 11:01:10 -05:00
get<DatabaseHelper>()
2021-01-10 11:01:10 -05:00
get<DownloadManager>()
}
}
}