From 4a6571d310ecf2bf77e86a303f1788aaaab3df25 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 11 Nov 2023 18:25:27 -0500 Subject: [PATCH] Minor cleanup --- .../TrackInfoDialogHomePreviewProvider.kt | 2 +- .../TrackLogoIconPreviewProvider.kt | 2 +- app/src/main/java/eu/kanade/tachiyomi/App.kt | 2 + .../eu/kanade/tachiyomi/{ => di}/AppModule.kt | 71 +---------------- .../kanade/tachiyomi/di/PreferenceModule.kt | 76 +++++++++++++++++++ .../tachiyomi/source/AndroidSourceManager.kt | 2 +- .../tachiyomi/source/SourceExtensions.kt | 6 -- .../source/model/SChapterExtensions.kt | 11 --- .../source/model/SMangaExtensions.kt | 54 ++----------- .../dev/preview => test}/DummyTracker.kt | 2 +- .../domain/source/model/StubSource.kt | 6 ++ 11 files changed, 95 insertions(+), 139 deletions(-) rename app/src/main/java/eu/kanade/tachiyomi/{ => di}/AppModule.kt (68%) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/di/PreferenceModule.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/source/model/SChapterExtensions.kt rename app/src/main/java/eu/kanade/{tachiyomi/dev/preview => test}/DummyTracker.kt (98%) diff --git a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHomePreviewProvider.kt b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHomePreviewProvider.kt index 00ef15ff1d..e2733b7bfa 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHomePreviewProvider.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHomePreviewProvider.kt @@ -2,8 +2,8 @@ package eu.kanade.presentation.track import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.PreviewParameterProvider -import eu.kanade.tachiyomi.dev.preview.DummyTracker import eu.kanade.tachiyomi.ui.manga.track.TrackItem +import eu.kanade.test.DummyTracker import tachiyomi.domain.track.model.Track import java.text.DateFormat diff --git a/app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIconPreviewProvider.kt b/app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIconPreviewProvider.kt index aeaa577a14..3f5e4b840a 100644 --- a/app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIconPreviewProvider.kt +++ b/app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIconPreviewProvider.kt @@ -4,7 +4,7 @@ import android.graphics.Color import androidx.compose.ui.tooling.preview.PreviewParameterProvider import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.track.Tracker -import eu.kanade.tachiyomi.dev.preview.DummyTracker +import eu.kanade.test.DummyTracker internal class TrackLogoIconPreviewProvider : PreviewParameterProvider { diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index 8459c8073c..bc0e4aa472 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -34,6 +34,8 @@ import eu.kanade.tachiyomi.data.coil.MangaCoverKeyer import eu.kanade.tachiyomi.data.coil.MangaKeyer import eu.kanade.tachiyomi.data.coil.TachiyomiImageDecoder import eu.kanade.tachiyomi.data.notification.Notifications +import eu.kanade.tachiyomi.di.AppModule +import eu.kanade.tachiyomi.di.PreferenceModule import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkPreferences import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate diff --git a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt b/app/src/main/java/eu/kanade/tachiyomi/di/AppModule.kt similarity index 68% rename from app/src/main/java/eu/kanade/tachiyomi/AppModule.kt rename to app/src/main/java/eu/kanade/tachiyomi/di/AppModule.kt index 51bd280986..6aab7c7bc9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/di/AppModule.kt @@ -1,4 +1,4 @@ -package eu.kanade.tachiyomi +package eu.kanade.tachiyomi.di import android.app.Application import android.os.Build @@ -7,12 +7,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory import app.cash.sqldelight.db.SqlDriver import app.cash.sqldelight.driver.android.AndroidSqliteDriver -import eu.kanade.domain.base.BasePreferences -import eu.kanade.domain.source.service.SourcePreferences -import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.domain.track.store.DelayedTrackingStore -import eu.kanade.domain.ui.UiPreferences -import eu.kanade.tachiyomi.core.security.SecurityPreferences +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.download.DownloadCache @@ -23,19 +19,12 @@ import eu.kanade.tachiyomi.data.track.TrackerManager import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.network.JavaScriptEngine import eu.kanade.tachiyomi.network.NetworkHelper -import eu.kanade.tachiyomi.network.NetworkPreferences import eu.kanade.tachiyomi.source.AndroidSourceManager -import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences -import eu.kanade.tachiyomi.util.system.isDevFlavor import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory import kotlinx.serialization.json.Json import nl.adaptivity.xmlutil.XmlDeclMode import nl.adaptivity.xmlutil.core.XmlVersion import nl.adaptivity.xmlutil.serialization.XML -import tachiyomi.core.preference.AndroidPreferenceStore -import tachiyomi.core.preference.PreferenceStore -import tachiyomi.core.provider.AndroidBackupFolderProvider -import tachiyomi.core.provider.AndroidDownloadFolderProvider import tachiyomi.data.AndroidDatabaseHandler import tachiyomi.data.Database import tachiyomi.data.DatabaseHandler @@ -44,9 +33,6 @@ import tachiyomi.data.History import tachiyomi.data.Mangas import tachiyomi.data.StringListColumnAdapter import tachiyomi.data.UpdateStrategyColumnAdapter -import tachiyomi.domain.backup.service.BackupPreferences -import tachiyomi.domain.download.service.DownloadPreferences -import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.source.service.SourceManager import tachiyomi.source.local.image.LocalCoverManager import tachiyomi.source.local.io.LocalSourceFileSystem @@ -152,56 +138,3 @@ class AppModule(val app: Application) : InjektModule { } } } - -class PreferenceModule(val application: Application) : InjektModule { - override fun InjektRegistrar.registerInjectables() { - addSingletonFactory { - AndroidPreferenceStore(application) - } - addSingletonFactory { - NetworkPreferences( - preferenceStore = get(), - verboseLogging = isDevFlavor, - ) - } - addSingletonFactory { - SourcePreferences(get()) - } - addSingletonFactory { - SecurityPreferences(get()) - } - addSingletonFactory { - LibraryPreferences(get()) - } - addSingletonFactory { - ReaderPreferences(get()) - } - addSingletonFactory { - TrackPreferences(get()) - } - addSingletonFactory { - AndroidDownloadFolderProvider(application) - } - addSingletonFactory { - DownloadPreferences( - folderProvider = get(), - preferenceStore = get(), - ) - } - addSingletonFactory { - AndroidBackupFolderProvider(application) - } - addSingletonFactory { - BackupPreferences( - folderProvider = get(), - preferenceStore = get(), - ) - } - addSingletonFactory { - UiPreferences(get()) - } - addSingletonFactory { - BasePreferences(application, get()) - } - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/di/PreferenceModule.kt b/app/src/main/java/eu/kanade/tachiyomi/di/PreferenceModule.kt new file mode 100644 index 0000000000..c7051cd474 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/di/PreferenceModule.kt @@ -0,0 +1,76 @@ +package eu.kanade.tachiyomi.di + +import android.app.Application +import eu.kanade.domain.base.BasePreferences +import eu.kanade.domain.source.service.SourcePreferences +import eu.kanade.domain.track.service.TrackPreferences +import eu.kanade.domain.ui.UiPreferences +import eu.kanade.tachiyomi.core.security.SecurityPreferences +import eu.kanade.tachiyomi.network.NetworkPreferences +import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences +import eu.kanade.tachiyomi.util.system.isDevFlavor +import tachiyomi.core.preference.AndroidPreferenceStore +import tachiyomi.core.preference.PreferenceStore +import tachiyomi.core.provider.AndroidBackupFolderProvider +import tachiyomi.core.provider.AndroidDownloadFolderProvider +import tachiyomi.domain.backup.service.BackupPreferences +import tachiyomi.domain.download.service.DownloadPreferences +import tachiyomi.domain.library.service.LibraryPreferences +import uy.kohesive.injekt.api.InjektModule +import uy.kohesive.injekt.api.InjektRegistrar +import uy.kohesive.injekt.api.addSingletonFactory +import uy.kohesive.injekt.api.get + +class PreferenceModule(val app: Application) : InjektModule { + + override fun InjektRegistrar.registerInjectables() { + addSingletonFactory { + AndroidPreferenceStore(app) + } + addSingletonFactory { + NetworkPreferences( + preferenceStore = get(), + verboseLogging = isDevFlavor, + ) + } + addSingletonFactory { + SourcePreferences(get()) + } + addSingletonFactory { + SecurityPreferences(get()) + } + addSingletonFactory { + LibraryPreferences(get()) + } + addSingletonFactory { + ReaderPreferences(get()) + } + addSingletonFactory { + TrackPreferences(get()) + } + addSingletonFactory { + AndroidDownloadFolderProvider(app) + } + addSingletonFactory { + DownloadPreferences( + folderProvider = get(), + preferenceStore = get(), + ) + } + addSingletonFactory { + AndroidBackupFolderProvider(app) + } + addSingletonFactory { + BackupPreferences( + folderProvider = get(), + preferenceStore = get(), + ) + } + addSingletonFactory { + UiPreferences(get()) + } + addSingletonFactory { + BasePreferences(app, get()) + } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/AndroidSourceManager.kt b/app/src/main/java/eu/kanade/tachiyomi/source/AndroidSourceManager.kt index dcbae8b4d1..a7618bd8c3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/AndroidSourceManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/AndroidSourceManager.kt @@ -56,7 +56,7 @@ class AndroidSourceManager( extensions.forEach { extension -> extension.sources.forEach { mutableMap[it.id] = it - registerStubSource(it.toStubSource()) + registerStubSource(StubSource.from(it)) } } sourcesMapFlow.value = mutableMap diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/SourceExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/source/SourceExtensions.kt index 7be9c4d20b..bac6ed5cd4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/SourceExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/SourceExtensions.kt @@ -1,17 +1,11 @@ package eu.kanade.tachiyomi.source -import android.graphics.drawable.Drawable import eu.kanade.domain.source.service.SourcePreferences -import eu.kanade.tachiyomi.extension.ExtensionManager import tachiyomi.domain.source.model.StubSource import tachiyomi.source.local.isLocal import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -fun Source.icon(): Drawable? = Injekt.get().getAppIconForSource(this.id) - -fun Source.toStubSource(): StubSource = StubSource(id = id, lang = lang, name = name) - fun Source.getNameForMangaInfo(): String { val preferences = Injekt.get() val enabledLanguages = preferences.enabledLanguages().get() diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapterExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapterExtensions.kt deleted file mode 100644 index 0fd2f860f9..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapterExtensions.kt +++ /dev/null @@ -1,11 +0,0 @@ -package eu.kanade.tachiyomi.source.model - -import tachiyomi.data.Chapters - -fun SChapter.copyFrom(other: Chapters) { - name = other.name - url = other.url - date_upload = other.date_upload - chapter_number = other.chapter_number.toFloat() - scanlator = other.scanlator -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/model/SMangaExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/source/model/SMangaExtensions.kt index 7147db9dec..812c6110fb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/model/SMangaExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/model/SMangaExtensions.kt @@ -3,58 +3,14 @@ package eu.kanade.tachiyomi.source.model import tachiyomi.data.Mangas import tachiyomi.domain.manga.model.Manga -fun SManga.copyFrom(other: Mangas) { - if (other.author != null) { - author = other.author - } - - if (other.artist != null) { - artist = other.artist - } - - if (other.description != null) { - description = other.description - } - - if (other.genre != null) { - genre = other.genre!!.joinToString(separator = ", ") - } - - if (other.thumbnail_url != null) { - thumbnail_url = other.thumbnail_url - } - - status = other.status.toInt() - - if (!initialized) { - initialized = other.initialized - } -} - fun Manga.copyFrom(other: Mangas): Manga { var manga = this - if (other.author != null) { - manga = manga.copy(author = other.author) - } - - if (other.artist != null) { - manga = manga.copy(artist = other.artist) - } - - if (other.description != null) { - manga = manga.copy(description = other.description) - } - - if (other.genre != null) { - manga = manga.copy(genre = other.genre) - } - - if (other.thumbnail_url != null) { - manga = manga.copy(thumbnailUrl = other.thumbnail_url) - } - + other.author?.let { manga = manga.copy(author = it) } + other.artist?.let { manga = manga.copy(artist = it) } + other.description?.let { manga = manga.copy(description = it) } + other.genre?.let { manga = manga.copy(genre = it) } + other.thumbnail_url?.let { manga = manga.copy(thumbnailUrl = it) } manga = manga.copy(status = other.status) - if (!initialized) { manga = manga.copy(initialized = other.initialized) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/dev/preview/DummyTracker.kt b/app/src/main/java/eu/kanade/test/DummyTracker.kt similarity index 98% rename from app/src/main/java/eu/kanade/tachiyomi/dev/preview/DummyTracker.kt rename to app/src/main/java/eu/kanade/test/DummyTracker.kt index 2315912ba0..c9e53f9f57 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/dev/preview/DummyTracker.kt +++ b/app/src/main/java/eu/kanade/test/DummyTracker.kt @@ -1,4 +1,4 @@ -package eu.kanade.tachiyomi.dev.preview +package eu.kanade.test import android.graphics.Color import eu.kanade.tachiyomi.R diff --git a/domain/src/main/java/tachiyomi/domain/source/model/StubSource.kt b/domain/src/main/java/tachiyomi/domain/source/model/StubSource.kt index 8b5f67ef5e..544326a4cc 100644 --- a/domain/src/main/java/tachiyomi/domain/source/model/StubSource.kt +++ b/domain/src/main/java/tachiyomi/domain/source/model/StubSource.kt @@ -23,6 +23,12 @@ class StubSource( override fun toString(): String = if (isInvalid.not()) "$name (${lang.uppercase()})" else id.toString() + + companion object { + fun from(source: Source): StubSource { + return StubSource(id = source.id, lang = source.lang, name = source.name) + } + } } class SourceNotInstalledException : Exception()