2016-06-14 09:13:48 -04:00
|
|
|
package eu.kanade.tachiyomi
|
|
|
|
|
|
|
|
import android.app.Application
|
2022-06-06 08:25:03 -04:00
|
|
|
import android.os.Build
|
2021-06-05 17:49:20 -04:00
|
|
|
import androidx.core.content.ContextCompat
|
2022-07-09 17:35:49 -04:00
|
|
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
2022-04-29 08:04:59 -04:00
|
|
|
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
|
2022-04-22 17:29:24 -04:00
|
|
|
import com.squareup.sqldelight.android.AndroidSqliteDriver
|
|
|
|
import com.squareup.sqldelight.db.SqlDriver
|
|
|
|
import data.History
|
|
|
|
import data.Mangas
|
|
|
|
import eu.kanade.data.AndroidDatabaseHandler
|
|
|
|
import eu.kanade.data.DatabaseHandler
|
|
|
|
import eu.kanade.data.dateAdapter
|
|
|
|
import eu.kanade.data.listOfStringsAdapter
|
2016-06-14 09:13:48 -04:00
|
|
|
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
|
|
|
import eu.kanade.tachiyomi.data.cache.CoverCache
|
|
|
|
import eu.kanade.tachiyomi.data.download.DownloadManager
|
|
|
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
2022-03-19 16:46:23 -04:00
|
|
|
import eu.kanade.tachiyomi.data.saver.ImageSaver
|
2017-01-20 15:22:17 -05:00
|
|
|
import eu.kanade.tachiyomi.data.track.TrackManager
|
2021-09-04 16:37:35 -04:00
|
|
|
import eu.kanade.tachiyomi.data.track.job.DelayedTrackingStore
|
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
|
2022-06-06 08:25:03 -04:00
|
|
|
import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory
|
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
|
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
|
|
|
|
2022-04-22 17:29:24 -04:00
|
|
|
addSingletonFactory<SqlDriver> {
|
2022-07-03 11:48:59 -04:00
|
|
|
AndroidSqliteDriver(
|
|
|
|
schema = Database.Schema,
|
|
|
|
context = app,
|
|
|
|
name = "tachiyomi.db",
|
|
|
|
factory = if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
// Support database inspector in Android Studio
|
|
|
|
FrameworkSQLiteOpenHelperFactory()
|
|
|
|
} else {
|
|
|
|
RequerySQLiteOpenHelperFactory()
|
|
|
|
},
|
2022-07-09 17:35:49 -04:00
|
|
|
callback = object : AndroidSqliteDriver.Callback(Database.Schema) {
|
|
|
|
override fun onOpen(db: SupportSQLiteDatabase) {
|
|
|
|
super.onOpen(db)
|
|
|
|
setPragma(db, "foreign_keys = ON")
|
|
|
|
setPragma(db, "journal_mode = WAL")
|
|
|
|
setPragma(db, "synchronous = NORMAL")
|
|
|
|
}
|
|
|
|
private fun setPragma(db: SupportSQLiteDatabase, pragma: String) {
|
|
|
|
val cursor = db.query("PRAGMA $pragma")
|
|
|
|
cursor.moveToFirst()
|
|
|
|
cursor.close()
|
|
|
|
}
|
|
|
|
},
|
2022-07-03 11:48:59 -04:00
|
|
|
)
|
2022-04-22 17:29:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
addSingletonFactory {
|
|
|
|
Database(
|
|
|
|
driver = get(),
|
|
|
|
historyAdapter = History.Adapter(
|
2022-05-28 09:09:27 -04:00
|
|
|
last_readAdapter = dateAdapter,
|
2022-04-22 17:29:24 -04:00
|
|
|
),
|
|
|
|
mangasAdapter = Mangas.Adapter(
|
2022-05-10 17:54:52 -04:00
|
|
|
genreAdapter = listOfStringsAdapter,
|
|
|
|
),
|
2022-04-22 17:29:24 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
addSingletonFactory<DatabaseHandler> { AndroidDatabaseHandler(get(), get()) }
|
|
|
|
|
2021-09-04 16:37:35 -04:00
|
|
|
addSingletonFactory { Json { ignoreUnknownKeys = true } }
|
|
|
|
|
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 { 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) }
|
|
|
|
|
2021-09-04 16:37:35 -04:00
|
|
|
addSingletonFactory { DelayedTrackingStore(app) }
|
2020-11-01 15:12:16 -05:00
|
|
|
|
2022-03-19 16:46:23 -04:00
|
|
|
addSingletonFactory { ImageSaver(app) }
|
|
|
|
|
2018-02-05 16:50:56 -05:00
|
|
|
// 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>()
|
2018-02-05 16:50:56 -05:00
|
|
|
|
2021-01-10 11:01:10 -05:00
|
|
|
get<NetworkHelper>()
|
2018-02-05 16:50:56 -05:00
|
|
|
|
2021-01-10 11:01:10 -05:00
|
|
|
get<SourceManager>()
|
2018-02-05 16:50:56 -05:00
|
|
|
|
2022-04-22 17:29:24 -04:00
|
|
|
get<Database>()
|
|
|
|
|
2021-01-10 11:01:10 -05:00
|
|
|
get<DownloadManager>()
|
|
|
|
}
|
2016-06-14 09:13:48 -04:00
|
|
|
}
|
2018-02-06 05:42:38 -05:00
|
|
|
}
|