2016-06-14 15:13:48 +02:00
|
|
|
package eu.kanade.tachiyomi
|
|
|
|
|
|
|
|
import android.app.Application
|
2022-06-06 14:25:03 +02:00
|
|
|
import android.os.Build
|
2021-06-05 23:49:20 +02:00
|
|
|
import androidx.core.content.ContextCompat
|
2022-07-09 23:35:49 +02:00
|
|
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
2022-04-29 14:04:59 +02:00
|
|
|
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
|
2022-04-22 23:29:24 +02: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
|
2022-09-21 23:45:07 +02:00
|
|
|
import eu.kanade.domain.download.service.DownloadPreferences
|
2022-09-20 05:55:07 +02:00
|
|
|
import eu.kanade.domain.library.service.LibraryPreferences
|
2022-09-18 16:36:41 +02:00
|
|
|
import eu.kanade.domain.source.service.SourcePreferences
|
2022-09-21 15:18:53 +02:00
|
|
|
import eu.kanade.domain.track.service.TrackPreferences
|
2022-09-17 17:48:24 +02:00
|
|
|
import eu.kanade.tachiyomi.core.preference.AndroidPreferenceStore
|
|
|
|
import eu.kanade.tachiyomi.core.preference.PreferenceStore
|
2022-09-21 23:45:07 +02:00
|
|
|
import eu.kanade.tachiyomi.core.provider.AndroidDownloadFolderProvider
|
2022-09-18 19:07:48 +02:00
|
|
|
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
2016-06-14 15:13:48 +02: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 21:46:23 +01:00
|
|
|
import eu.kanade.tachiyomi.data.saver.ImageSaver
|
2017-01-20 21:22:17 +01:00
|
|
|
import eu.kanade.tachiyomi.data.track.TrackManager
|
2021-09-04 22:37:35 +02:00
|
|
|
import eu.kanade.tachiyomi.data.track.job.DelayedTrackingStore
|
2018-02-05 22:50:56 +01:00
|
|
|
import eu.kanade.tachiyomi.extension.ExtensionManager
|
2017-01-20 21:34:15 +01:00
|
|
|
import eu.kanade.tachiyomi.network.NetworkHelper
|
2022-09-17 17:48:24 +02:00
|
|
|
import eu.kanade.tachiyomi.network.NetworkPreferences
|
2017-01-20 21:34:15 +01:00
|
|
|
import eu.kanade.tachiyomi.source.SourceManager
|
2022-09-20 14:36:57 +02:00
|
|
|
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
|
2022-09-17 17:48:24 +02:00
|
|
|
import eu.kanade.tachiyomi.util.system.isDevFlavor
|
2022-06-06 14:25:03 +02:00
|
|
|
import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory
|
2020-11-01 21:12:16 +01:00
|
|
|
import kotlinx.serialization.json.Json
|
2022-09-18 16:55:30 +02:00
|
|
|
import nl.adaptivity.xmlutil.serialization.UnknownChildHandler
|
|
|
|
import nl.adaptivity.xmlutil.serialization.XML
|
2020-02-27 00:12:44 +01: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 15:13:48 +02:00
|
|
|
|
|
|
|
class AppModule(val app: Application) : InjektModule {
|
|
|
|
|
|
|
|
override fun InjektRegistrar.registerInjectables() {
|
2018-02-05 22:50:56 +01:00
|
|
|
addSingleton(app)
|
2016-06-14 15:13:48 +02:00
|
|
|
|
2022-04-22 23:29:24 +02:00
|
|
|
addSingletonFactory<SqlDriver> {
|
2022-07-03 17:48:59 +02:00
|
|
|
AndroidSqliteDriver(
|
|
|
|
schema = Database.Schema,
|
|
|
|
context = app,
|
|
|
|
name = "tachiyomi.db",
|
2022-07-17 02:54:27 +02:00
|
|
|
factory = if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
2022-07-03 17:48:59 +02:00
|
|
|
// Support database inspector in Android Studio
|
|
|
|
FrameworkSQLiteOpenHelperFactory()
|
|
|
|
} else {
|
|
|
|
RequerySQLiteOpenHelperFactory()
|
|
|
|
},
|
2022-07-09 23:35:49 +02: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 17:48:59 +02:00
|
|
|
)
|
2022-04-22 23:29:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
addSingletonFactory {
|
|
|
|
Database(
|
|
|
|
driver = get(),
|
|
|
|
historyAdapter = History.Adapter(
|
2022-05-28 15:09:27 +02:00
|
|
|
last_readAdapter = dateAdapter,
|
2022-04-22 23:29:24 +02:00
|
|
|
),
|
|
|
|
mangasAdapter = Mangas.Adapter(
|
2022-05-10 23:54:52 +02:00
|
|
|
genreAdapter = listOfStringsAdapter,
|
|
|
|
),
|
2022-04-22 23:29:24 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
addSingletonFactory<DatabaseHandler> { AndroidDatabaseHandler(get(), get()) }
|
|
|
|
|
2022-08-20 17:48:50 +02:00
|
|
|
addSingletonFactory {
|
|
|
|
Json {
|
|
|
|
ignoreUnknownKeys = true
|
|
|
|
explicitNulls = false
|
|
|
|
}
|
|
|
|
}
|
2021-09-04 22:37:35 +02:00
|
|
|
|
2022-09-18 16:55:30 +02:00
|
|
|
addSingletonFactory {
|
|
|
|
XML {
|
|
|
|
unknownChildHandler = UnknownChildHandler { _, _, _, _, _ -> emptyList() }
|
|
|
|
autoPolymorphic = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-05 22:50:56 +01:00
|
|
|
addSingletonFactory { ChapterCache(app) }
|
2016-06-14 15:13:48 +02:00
|
|
|
|
2018-02-05 22:50:56 +01:00
|
|
|
addSingletonFactory { CoverCache(app) }
|
2016-06-14 15:13:48 +02:00
|
|
|
|
2018-02-05 22:50:56 +01:00
|
|
|
addSingletonFactory { NetworkHelper(app) }
|
2016-06-14 15:13:48 +02:00
|
|
|
|
2018-02-05 22:50:56 +01:00
|
|
|
addSingletonFactory { ExtensionManager(app) }
|
2016-06-14 15:13:48 +02:00
|
|
|
|
2022-07-16 21:08:15 +02:00
|
|
|
addSingletonFactory { SourceManager(app, get(), get()) }
|
|
|
|
|
2018-02-05 22:50:56 +01:00
|
|
|
addSingletonFactory { DownloadManager(app) }
|
|
|
|
|
|
|
|
addSingletonFactory { TrackManager(app) }
|
|
|
|
|
2021-09-04 22:37:35 +02:00
|
|
|
addSingletonFactory { DelayedTrackingStore(app) }
|
2020-11-01 21:12:16 +01:00
|
|
|
|
2022-03-19 21:46:23 +01:00
|
|
|
addSingletonFactory { ImageSaver(app) }
|
|
|
|
|
2018-02-05 22:50:56 +01:00
|
|
|
// Asynchronously init expensive components for a faster cold start
|
2021-06-05 23:49:20 +02:00
|
|
|
ContextCompat.getMainExecutor(app).execute {
|
2021-01-10 17:01:10 +01:00
|
|
|
get<NetworkHelper>()
|
2018-02-05 22:50:56 +01:00
|
|
|
|
2021-01-10 17:01:10 +01:00
|
|
|
get<SourceManager>()
|
2018-02-05 22:50:56 +01:00
|
|
|
|
2022-04-22 23:29:24 +02:00
|
|
|
get<Database>()
|
|
|
|
|
2021-01-10 17:01:10 +01:00
|
|
|
get<DownloadManager>()
|
|
|
|
}
|
2016-06-14 15:13:48 +02:00
|
|
|
}
|
2018-02-06 11:42:38 +01:00
|
|
|
}
|
2022-09-17 17:48:24 +02:00
|
|
|
|
|
|
|
class PreferenceModule(val application: Application) : InjektModule {
|
|
|
|
override fun InjektRegistrar.registerInjectables() {
|
|
|
|
addSingletonFactory<PreferenceStore> {
|
|
|
|
AndroidPreferenceStore(application)
|
|
|
|
}
|
|
|
|
addSingletonFactory {
|
|
|
|
NetworkPreferences(
|
|
|
|
preferenceStore = get(),
|
|
|
|
verboseLogging = isDevFlavor,
|
|
|
|
)
|
|
|
|
}
|
2022-09-18 16:36:41 +02:00
|
|
|
addSingletonFactory {
|
|
|
|
SourcePreferences(get())
|
|
|
|
}
|
2022-09-18 19:07:48 +02:00
|
|
|
addSingletonFactory {
|
|
|
|
SecurityPreferences(get())
|
|
|
|
}
|
2022-09-20 05:55:07 +02:00
|
|
|
addSingletonFactory {
|
|
|
|
LibraryPreferences(get())
|
|
|
|
}
|
2022-09-20 14:36:57 +02:00
|
|
|
addSingletonFactory {
|
|
|
|
ReaderPreferences(get())
|
|
|
|
}
|
2022-09-21 15:18:53 +02:00
|
|
|
addSingletonFactory {
|
|
|
|
TrackPreferences(get())
|
|
|
|
}
|
2022-09-21 23:45:07 +02:00
|
|
|
addSingletonFactory {
|
|
|
|
AndroidDownloadFolderProvider(application)
|
|
|
|
}
|
|
|
|
addSingletonFactory {
|
|
|
|
DownloadPreferences(
|
|
|
|
folderProvider = get<AndroidDownloadFolderProvider>(),
|
|
|
|
preferenceStore = get(),
|
|
|
|
)
|
|
|
|
}
|
2022-09-17 17:48:24 +02:00
|
|
|
addSingletonFactory {
|
|
|
|
PreferencesHelper(
|
|
|
|
context = application,
|
|
|
|
preferenceStore = get(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|