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
|
2022-09-25 16:07:06 +02:00
|
|
|
import eu.kanade.domain.base.BasePreferences
|
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-12-02 05:01:24 +01:00
|
|
|
import eu.kanade.domain.track.store.DelayedTrackingStore
|
2022-09-25 16:07:06 +02:00
|
|
|
import eu.kanade.domain.ui.UiPreferences
|
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
|
2022-10-21 20:29:44 +02:00
|
|
|
import eu.kanade.tachiyomi.data.download.DownloadCache
|
2016-06-14 15:13:48 +02:00
|
|
|
import eu.kanade.tachiyomi.data.download.DownloadManager
|
2022-10-21 20:29:44 +02:00
|
|
|
import eu.kanade.tachiyomi.data.download.DownloadProvider
|
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
|
2018-02-05 22:50:56 +01:00
|
|
|
import eu.kanade.tachiyomi.extension.ExtensionManager
|
2022-10-08 15:45:06 +02:00
|
|
|
import eu.kanade.tachiyomi.network.JavaScriptEngine
|
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
|
2023-03-05 18:38:31 +01:00
|
|
|
import eu.kanade.tachiyomi.source.AndroidSourceManager
|
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-11-11 22:16:37 +01:00
|
|
|
import nl.adaptivity.xmlutil.XmlDeclMode
|
|
|
|
import nl.adaptivity.xmlutil.core.XmlVersion
|
2022-09-18 16:55:30 +02:00
|
|
|
import nl.adaptivity.xmlutil.serialization.UnknownChildHandler
|
|
|
|
import nl.adaptivity.xmlutil.serialization.XML
|
2023-01-28 04:31:12 +01:00
|
|
|
import tachiyomi.core.preference.AndroidPreferenceStore
|
|
|
|
import tachiyomi.core.preference.PreferenceStore
|
|
|
|
import tachiyomi.core.provider.AndroidBackupFolderProvider
|
|
|
|
import tachiyomi.core.provider.AndroidDownloadFolderProvider
|
2023-01-21 16:37:07 +01:00
|
|
|
import tachiyomi.data.AndroidDatabaseHandler
|
|
|
|
import tachiyomi.data.Database
|
|
|
|
import tachiyomi.data.DatabaseHandler
|
|
|
|
import tachiyomi.data.History
|
|
|
|
import tachiyomi.data.Mangas
|
|
|
|
import tachiyomi.data.dateAdapter
|
|
|
|
import tachiyomi.data.listOfStringsAdapter
|
|
|
|
import tachiyomi.data.updateStrategyAdapter
|
2023-03-05 18:38:31 +01:00
|
|
|
import tachiyomi.domain.backup.service.BackupPreferences
|
2023-03-05 18:11:47 +01:00
|
|
|
import tachiyomi.domain.download.service.DownloadPreferences
|
2023-03-05 18:38:31 +01:00
|
|
|
import tachiyomi.domain.source.service.SourceManager
|
2023-02-26 22:16:49 +01:00
|
|
|
import tachiyomi.source.local.image.LocalCoverManager
|
|
|
|
import tachiyomi.source.local.io.LocalSourceFileSystem
|
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-09-25 16:12:36 +02:00
|
|
|
update_strategyAdapter = updateStrategyAdapter,
|
2022-05-10 23:54:52 +02:00
|
|
|
),
|
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
|
|
|
|
}
|
|
|
|
}
|
2022-09-18 16:55:30 +02:00
|
|
|
addSingletonFactory {
|
|
|
|
XML {
|
|
|
|
unknownChildHandler = UnknownChildHandler { _, _, _, _, _ -> emptyList() }
|
|
|
|
autoPolymorphic = true
|
2022-11-11 22:16:37 +01:00
|
|
|
xmlDeclMode = XmlDeclMode.Charset
|
|
|
|
indent = 4
|
|
|
|
xmlVersion = XmlVersion.XML10
|
2022-09-18 16:55:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-05 22:50:56 +01:00
|
|
|
addSingletonFactory { ChapterCache(app) }
|
|
|
|
addSingletonFactory { CoverCache(app) }
|
2016-06-14 15:13:48 +02:00
|
|
|
|
2023-02-21 01:02:38 +01:00
|
|
|
addSingletonFactory { NetworkHelper(app, get()) }
|
2022-10-08 15:45:06 +02:00
|
|
|
addSingletonFactory { JavaScriptEngine(app) }
|
2016-06-14 15:13:48 +02:00
|
|
|
|
2023-03-05 18:38:31 +01:00
|
|
|
addSingletonFactory<SourceManager> { AndroidSourceManager(app, get(), get()) }
|
2022-10-08 15:45:06 +02:00
|
|
|
addSingletonFactory { ExtensionManager(app) }
|
2022-07-16 21:08:15 +02:00
|
|
|
|
2022-10-21 20:29:44 +02:00
|
|
|
addSingletonFactory { DownloadProvider(app) }
|
2018-02-05 22:50:56 +01:00
|
|
|
addSingletonFactory { DownloadManager(app) }
|
2022-10-21 20:29:44 +02:00
|
|
|
addSingletonFactory { DownloadCache(app) }
|
2018-02-05 22:50:56 +01:00
|
|
|
|
|
|
|
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) }
|
|
|
|
|
2023-03-05 16:16:19 +01:00
|
|
|
addSingletonFactory { LocalSourceFileSystem(app) }
|
|
|
|
addSingletonFactory { LocalCoverManager(app, get()) }
|
2023-02-26 22:16:49 +01:00
|
|
|
|
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-22 14:57:42 +02:00
|
|
|
addSingletonFactory {
|
|
|
|
AndroidBackupFolderProvider(application)
|
|
|
|
}
|
|
|
|
addSingletonFactory {
|
|
|
|
BackupPreferences(
|
|
|
|
folderProvider = get<AndroidBackupFolderProvider>(),
|
|
|
|
preferenceStore = get(),
|
|
|
|
)
|
|
|
|
}
|
2022-09-17 17:48:24 +02:00
|
|
|
addSingletonFactory {
|
2022-09-25 16:07:06 +02:00
|
|
|
UiPreferences(get())
|
|
|
|
}
|
|
|
|
addSingletonFactory {
|
|
|
|
BasePreferences(application, get())
|
2022-09-17 17:48:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|