From 30b3b2d3ffd5d90aee293e9ae22b3cb2a4924c2b Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 18 Sep 2022 16:36:41 +0200 Subject: [PATCH] Split source preferences from PreferencesHelper (#8029) --- .../interactor/GetExtensionLanguages.kt | 4 +-- .../interactor/GetExtensionSources.kt | 4 +-- .../interactor/GetExtensionsByType.kt | 4 +-- .../source/interactor/GetEnabledSources.kt | 4 +-- .../interactor/GetLanguagesWithSources.kt | 4 +-- .../interactor/GetSourcesWithFavoriteCount.kt | 4 +-- .../source/interactor/SetMigrateSorting.kt | 6 ++-- .../source/interactor/ToggleLanguage.kt | 6 ++-- .../domain/source/interactor/ToggleSource.kt | 14 ++++---- .../source/interactor/ToggleSourcePin.kt | 6 ++-- .../source/service/SourcePreferences.kt | 33 +++++++++++++++++++ .../java/eu/kanade/tachiyomi/AppModule.kt | 4 +++ .../java/eu/kanade/tachiyomi/Migrations.kt | 6 ++-- .../data/preference/PreferenceKeys.kt | 5 --- .../data/preference/PreferencesHelper.kt | 23 ------------- .../tachiyomi/extension/ExtensionManager.kt | 4 +-- .../extension/util/ExtensionLoader.kt | 4 +-- .../tachiyomi/source/SourceExtensions.kt | 4 +-- .../extension/ExtensionFilterPresenter.kt | 4 +-- .../browse/extension/ExtensionsPresenter.kt | 4 +-- .../migration/search/SearchController.kt | 2 +- .../sources/MigrationSourcesPresenter.kt | 4 +-- .../browse/source/SourcesFilterPresenter.kt | 4 +-- .../ui/browse/source/SourcesPresenter.kt | 4 ++- .../globalsearch/GlobalSearchController.kt | 6 ++-- .../globalsearch/GlobalSearchPresenter.kt | 14 ++++---- .../kanade/tachiyomi/ui/main/MainActivity.kt | 10 ++++-- .../ui/setting/SettingsBrowseController.kt | 13 ++++---- 28 files changed, 111 insertions(+), 93 deletions(-) create mode 100644 app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt diff --git a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionLanguages.kt b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionLanguages.kt index ff277f832f..16d2ae8f85 100644 --- a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionLanguages.kt +++ b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionLanguages.kt @@ -1,13 +1,13 @@ package eu.kanade.domain.extension.interactor -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.util.system.LocaleHelper import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine class GetExtensionLanguages( - private val preferences: PreferencesHelper, + private val preferences: SourcePreferences, private val extensionManager: ExtensionManager, ) { fun subscribe(): Flow> { diff --git a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionSources.kt b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionSources.kt index b28de4a134..ba77bbc46b 100644 --- a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionSources.kt +++ b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionSources.kt @@ -1,6 +1,6 @@ package eu.kanade.domain.extension.interactor -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.ui.browse.extension.details.ExtensionSourceItem @@ -8,7 +8,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map class GetExtensionSources( - private val preferences: PreferencesHelper, + private val preferences: SourcePreferences, ) { fun subscribe(extension: Extension.Installed): Flow> { diff --git a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionsByType.kt b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionsByType.kt index 76fbcda7e8..1a5ba8069d 100644 --- a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionsByType.kt +++ b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionsByType.kt @@ -1,14 +1,14 @@ package eu.kanade.domain.extension.interactor import eu.kanade.domain.extension.model.Extensions -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.extension.model.Extension import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine class GetExtensionsByType( - private val preferences: PreferencesHelper, + private val preferences: SourcePreferences, private val extensionManager: ExtensionManager, ) { diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt b/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt index acc2bf583f..2c6322f48f 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt @@ -4,7 +4,7 @@ import eu.kanade.domain.source.model.Pin import eu.kanade.domain.source.model.Pins import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.repository.SourceRepository -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.source.LocalSource import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine @@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged class GetEnabledSources( private val repository: SourceRepository, - private val preferences: PreferencesHelper, + private val preferences: SourcePreferences, ) { fun subscribe(): Flow> { diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/GetLanguagesWithSources.kt b/app/src/main/java/eu/kanade/domain/source/interactor/GetLanguagesWithSources.kt index 44c4bea85a..8fa640f539 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/GetLanguagesWithSources.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/GetLanguagesWithSources.kt @@ -2,14 +2,14 @@ package eu.kanade.domain.source.interactor import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.repository.SourceRepository -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.util.system.LocaleHelper import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine class GetLanguagesWithSources( private val repository: SourceRepository, - private val preferences: PreferencesHelper, + private val preferences: SourcePreferences, ) { fun subscribe(): Flow>> { diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithFavoriteCount.kt b/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithFavoriteCount.kt index c60bac7bd1..c04acab1da 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithFavoriteCount.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithFavoriteCount.kt @@ -2,7 +2,7 @@ package eu.kanade.domain.source.interactor import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.repository.SourceRepository -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.source.service.SourcePreferences import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine import java.text.Collator @@ -11,7 +11,7 @@ import java.util.Locale class GetSourcesWithFavoriteCount( private val repository: SourceRepository, - private val preferences: PreferencesHelper, + private val preferences: SourcePreferences, ) { fun subscribe(): Flow>> { diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/SetMigrateSorting.kt b/app/src/main/java/eu/kanade/domain/source/interactor/SetMigrateSorting.kt index 0b257a5d87..4e4ae4bdd3 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/SetMigrateSorting.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/SetMigrateSorting.kt @@ -1,9 +1,9 @@ package eu.kanade.domain.source.interactor -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.source.service.SourcePreferences class SetMigrateSorting( - private val preferences: PreferencesHelper, + private val preferences: SourcePreferences, ) { fun await(mode: Mode, direction: Direction) { @@ -14,12 +14,10 @@ class SetMigrateSorting( enum class Mode { ALPHABETICAL, TOTAL, - ; } enum class Direction { ASCENDING, DESCENDING, - ; } } diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleLanguage.kt b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleLanguage.kt index 846690c2a6..a266892186 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleLanguage.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleLanguage.kt @@ -1,12 +1,10 @@ package eu.kanade.domain.source.interactor +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.core.preference.getAndSet -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.util.preference.minusAssign -import eu.kanade.tachiyomi.util.preference.plusAssign class ToggleLanguage( - val preferences: PreferencesHelper, + val preferences: SourcePreferences, ) { fun await(language: String) { diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSource.kt b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSource.kt index 8416206672..bb602da5c4 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSource.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSource.kt @@ -1,22 +1,24 @@ package eu.kanade.domain.source.interactor import eu.kanade.domain.source.model.Source +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.core.preference.getAndSet -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.util.preference.minusAssign -import eu.kanade.tachiyomi.util.preference.plusAssign class ToggleSource( - private val preferences: PreferencesHelper, + private val preferences: SourcePreferences, ) { - fun await(source: Source, enable: Boolean = source.id.toString() in preferences.disabledSources().get()) { + fun await(source: Source, enable: Boolean = isEnabled(source.id)) { await(source.id, enable) } - fun await(sourceId: Long, enable: Boolean = sourceId.toString() in preferences.disabledSources().get()) { + fun await(sourceId: Long, enable: Boolean = isEnabled(sourceId)) { preferences.disabledSources().getAndSet { disabled -> if (enable) disabled.minus("$sourceId") else disabled.plus("$sourceId") } } + + private fun isEnabled(sourceId: Long): Boolean { + return sourceId.toString() in preferences.disabledSources().get() + } } diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSourcePin.kt b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSourcePin.kt index c5d360848a..6f79035e5b 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSourcePin.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSourcePin.kt @@ -1,13 +1,11 @@ package eu.kanade.domain.source.interactor import eu.kanade.domain.source.model.Source +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.core.preference.getAndSet -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.util.preference.minusAssign -import eu.kanade.tachiyomi.util.preference.plusAssign class ToggleSourcePin( - private val preferences: PreferencesHelper, + private val preferences: SourcePreferences, ) { fun await(source: Source) { diff --git a/app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt b/app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt new file mode 100644 index 0000000000..2ee3b3eb11 --- /dev/null +++ b/app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt @@ -0,0 +1,33 @@ +package eu.kanade.domain.source.service + +import eu.kanade.domain.source.interactor.SetMigrateSorting +import eu.kanade.tachiyomi.core.preference.PreferenceStore +import eu.kanade.tachiyomi.core.preference.getEnum +import eu.kanade.tachiyomi.util.system.LocaleHelper + +class SourcePreferences( + private val preferenceStore: PreferenceStore, +) { + + fun enabledLanguages() = this.preferenceStore.getStringSet("source_languages", LocaleHelper.getDefaultEnabledLanguages()) + + fun disabledSources() = this.preferenceStore.getStringSet("hidden_catalogues", emptySet()) + + fun pinnedSources() = this.preferenceStore.getStringSet("pinned_catalogues", emptySet()) + + fun duplicatePinnedSources() = this.preferenceStore.getBoolean("duplicate_pinned_sources", false) + + fun lastUsedSource() = this.preferenceStore.getLong("last_catalogue_source", -1) + + fun showNsfwSource() = this.preferenceStore.getBoolean("show_nsfw_source", true) + + fun migrationSortingMode() = this.preferenceStore.getEnum("pref_migration_sorting", SetMigrateSorting.Mode.ALPHABETICAL) + + fun migrationSortingDirection() = this.preferenceStore.getEnum("pref_migration_direction", SetMigrateSorting.Direction.ASCENDING) + + fun extensionUpdatesCount() = this.preferenceStore.getInt("ext_updates_count", 0) + + fun trustedSignatures() = this.preferenceStore.getStringSet("trusted_signatures", emptySet()) + + fun searchPinnedSourcesOnly() = this.preferenceStore.getBoolean("search_pinned_sources_only", false) +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt index ff7278054c..7c4e831ecb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt @@ -13,6 +13,7 @@ import eu.kanade.data.AndroidDatabaseHandler import eu.kanade.data.DatabaseHandler import eu.kanade.data.dateAdapter import eu.kanade.data.listOfStringsAdapter +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.core.preference.AndroidPreferenceStore import eu.kanade.tachiyomi.core.preference.PreferenceStore import eu.kanade.tachiyomi.data.cache.ChapterCache @@ -130,6 +131,9 @@ class PreferenceModule(val application: Application) : InjektModule { verboseLogging = isDevFlavor, ) } + addSingletonFactory { + SourcePreferences(get()) + } addSingletonFactory { PreferencesHelper( context = application, diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index b5911fb46a..0c6977e18a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -4,6 +4,7 @@ import android.content.Context import android.os.Build import androidx.core.content.edit import androidx.preference.PreferenceManager +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.data.backup.BackupCreatorJob import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED @@ -37,6 +38,7 @@ object Migrations { context: Context, preferences: PreferencesHelper, networkPreferences: NetworkPreferences, + sourcePreferences: SourcePreferences, ): Boolean { val oldVersion = preferences.lastVersionCode().get() if (oldVersion < BuildConfig.VERSION_CODE) { @@ -231,8 +233,8 @@ object Migrations { } } if (oldVersion < 70) { - if (preferences.enabledLanguages().isSet()) { - preferences.enabledLanguages() += "all" + if (sourcePreferences.enabledLanguages().isSet()) { + sourcePreferences.enabledLanguages() += "all" } } if (oldVersion < 71) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 4cd39dd8ba..fd461988a6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -37,9 +37,6 @@ object PreferenceKeys { const val librarySortingMode = "library_sorting_mode" - const val migrationSortingMode = "pref_migration_sorting" - const val migrationSortingDirection = "pref_migration_direction" - const val hideNotificationContent = "hide_notification_content" const val autoUpdateMetadata = "auto_update_metadata" @@ -54,8 +51,6 @@ object PreferenceKeys { const val skipFiltered = "skip_filtered" - const val searchPinnedSourcesOnly = "search_pinned_sources_only" - const val defaultChapterFilterByRead = "default_chapter_filter_by_read" const val defaultChapterFilterByDownloaded = "default_chapter_filter_by_downloaded" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 5a6faceadb..d375d64311 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -4,7 +4,6 @@ import android.content.Context import android.os.Build import android.os.Environment import androidx.core.net.toUri -import eu.kanade.domain.source.interactor.SetMigrateSorting import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.core.preference.PreferenceStore import eu.kanade.tachiyomi.core.preference.getEnum @@ -16,7 +15,6 @@ import eu.kanade.tachiyomi.ui.library.setting.LibrarySort import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType import eu.kanade.tachiyomi.util.system.DeviceUtil -import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.isDynamicColorAvailable import eu.kanade.tachiyomi.widget.ExtendedNavigationView import java.io.File @@ -166,16 +164,12 @@ class PreferencesHelper( fun autoUpdateTrack() = this.preferenceStore.getBoolean(Keys.autoUpdateTrack, true) - fun lastUsedSource() = this.preferenceStore.getLong("last_catalogue_source", -1) - fun lastUsedCategory() = this.preferenceStore.getInt("last_used_category", 0) fun lastVersionCode() = this.preferenceStore.getInt("last_version_code", 0) fun sourceDisplayMode() = this.preferenceStore.getObject("pref_display_mode_catalogue", LibraryDisplayMode.default, LibraryDisplayMode.Serializer::serialize, LibraryDisplayMode.Serializer::deserialize) - fun enabledLanguages() = this.preferenceStore.getStringSet("source_languages", LocaleHelper.getDefaultEnabledLanguages()) - fun trackUsername(sync: TrackService) = this.preferenceStore.getString(Keys.trackUsername(sync.id), "") fun trackPassword(sync: TrackService) = this.preferenceStore.getString(Keys.trackPassword(sync.id), "") @@ -260,24 +254,11 @@ class PreferencesHelper( fun librarySortingMode() = this.preferenceStore.getObject(Keys.librarySortingMode, LibrarySort.default, LibrarySort.Serializer::serialize, LibrarySort.Serializer::deserialize) - fun migrationSortingMode() = this.preferenceStore.getEnum(Keys.migrationSortingMode, SetMigrateSorting.Mode.ALPHABETICAL) - fun migrationSortingDirection() = this.preferenceStore.getEnum(Keys.migrationSortingDirection, SetMigrateSorting.Direction.ASCENDING) - fun automaticExtUpdates() = this.preferenceStore.getBoolean("automatic_ext_updates", true) - fun showNsfwSource() = this.preferenceStore.getBoolean("show_nsfw_source", true) - - fun extensionUpdatesCount() = this.preferenceStore.getInt("ext_updates_count", 0) - fun lastAppCheck() = this.preferenceStore.getLong("last_app_check", 0) fun lastExtCheck() = this.preferenceStore.getLong("last_ext_check", 0) - fun searchPinnedSourcesOnly() = this.preferenceStore.getBoolean(Keys.searchPinnedSourcesOnly, false) - - fun disabledSources() = this.preferenceStore.getStringSet("hidden_catalogues", emptySet()) - - fun pinnedSources() = this.preferenceStore.getStringSet("pinned_catalogues", emptySet()) - fun downloadNewChapters() = this.preferenceStore.getBoolean("download_new", false) fun downloadNewChapterCategories() = this.preferenceStore.getStringSet("download_new_categories", emptySet()) @@ -295,8 +276,6 @@ class PreferencesHelper( fun migrateFlags() = this.preferenceStore.getInt("migrate_flags", Int.MAX_VALUE) - fun trustedSignatures() = this.preferenceStore.getStringSet("trusted_signatures", emptySet()) - fun filterChapterByRead() = this.preferenceStore.getInt(Keys.defaultChapterFilterByRead, DomainManga.SHOW_ALL.toInt()) fun filterChapterByDownloaded() = this.preferenceStore.getInt(Keys.defaultChapterFilterByDownloaded, DomainManga.SHOW_ALL.toInt()) @@ -320,8 +299,6 @@ class PreferencesHelper( fun autoClearChapterCache() = this.preferenceStore.getBoolean(Keys.autoClearChapterCache, false) - fun duplicatePinnedSources() = this.preferenceStore.getBoolean("duplicate_pinned_sources", false) - fun setChapterSettingsDefault(manga: Manga) { filterChapterByRead().set(manga.readFilter) filterChapterByDownloaded().set(manga.downloadedFilter) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index 53fba35fa5..0c09ec5297 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -4,8 +4,8 @@ import android.content.Context import android.graphics.drawable.Drawable import com.jakewharton.rxrelay.BehaviorRelay import eu.kanade.domain.source.model.SourceData +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.extension.model.AvailableSources import eu.kanade.tachiyomi.extension.model.Extension @@ -42,7 +42,7 @@ import java.util.Locale */ class ExtensionManager( private val context: Context, - private val preferences: PreferencesHelper = Injekt.get(), + private val preferences: SourcePreferences = Injekt.get(), ) { /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt index 6d5f763bcf..5b9d79e0c3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt @@ -6,7 +6,7 @@ import android.content.pm.PackageInfo import android.content.pm.PackageManager import androidx.core.content.pm.PackageInfoCompat import dalvik.system.PathClassLoader -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.LoadResult import eu.kanade.tachiyomi.source.CatalogueSource @@ -26,7 +26,7 @@ import uy.kohesive.injekt.injectLazy @SuppressLint("PackageManagerGetSignatures") internal object ExtensionLoader { - private val preferences: PreferencesHelper by injectLazy() + private val preferences: SourcePreferences by injectLazy() private val loadNsfwSource by lazy { preferences.showNsfwSource().get() } 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 f6bff12f04..748ecb6213 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/SourceExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/SourceExtensions.kt @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.source import android.graphics.drawable.Drawable import eu.kanade.domain.source.model.SourceData -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.extension.ExtensionManager import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -14,7 +14,7 @@ fun Source.getPreferenceKey(): String = "source_$id" fun Source.toSourceData(): SourceData = SourceData(id = id, lang = lang, name = name) fun Source.getNameForMangaInfo(): String { - val preferences = Injekt.get() + val preferences = Injekt.get() val enabledLanguages = preferences.enabledLanguages().get() .filterNot { it in listOf("all", "other") } val hasOneActiveLanguages = enabledLanguages.size == 1 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterPresenter.kt index 63c3156f44..41f132a29d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterPresenter.kt @@ -3,9 +3,9 @@ package eu.kanade.tachiyomi.ui.browse.extension import android.os.Bundle import eu.kanade.domain.extension.interactor.GetExtensionLanguages import eu.kanade.domain.source.interactor.ToggleLanguage +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.presentation.browse.ExtensionFilterState import eu.kanade.presentation.browse.ExtensionFilterStateImpl -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.system.logcat @@ -21,7 +21,7 @@ class ExtensionFilterPresenter( private val state: ExtensionFilterStateImpl = ExtensionFilterState() as ExtensionFilterStateImpl, private val getExtensionLanguages: GetExtensionLanguages = Injekt.get(), private val toggleLanguage: ToggleLanguage = Injekt.get(), - private val preferences: PreferencesHelper = Injekt.get(), + private val preferences: SourcePreferences = Injekt.get(), ) : BasePresenter(), ExtensionFilterState by state { private val _events = Channel(Int.MAX_VALUE) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsPresenter.kt index acc8bb97d5..dfeee1bd31 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsPresenter.kt @@ -3,11 +3,11 @@ package eu.kanade.tachiyomi.ui.browse.extension import android.app.Application import androidx.annotation.StringRes import eu.kanade.domain.extension.interactor.GetExtensionsByType +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.presentation.browse.ExtensionState import eu.kanade.presentation.browse.ExtensionsState import eu.kanade.presentation.browse.ExtensionsStateImpl import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.InstallStep @@ -31,7 +31,7 @@ import uy.kohesive.injekt.api.get class ExtensionsPresenter( private val presenterScope: CoroutineScope, private val state: ExtensionsStateImpl = ExtensionState() as ExtensionsStateImpl, - private val preferences: PreferencesHelper = Injekt.get(), + private val preferences: SourcePreferences = Injekt.get(), private val extensionManager: ExtensionManager = Injekt.get(), private val getExtensions: GetExtensionsByType = Injekt.get(), ) : ExtensionsState by state { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt index 2b52456984..c6263daaaa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt @@ -150,7 +150,7 @@ class SearchController( } override fun onTitleClick(source: CatalogueSource) { - presenter.preferences.lastUsedSource().set(source.id) + presenter.sourcePreferences.lastUsedSource().set(source.id) router.pushController(SourceSearchController(manga, source, presenter.query)) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesPresenter.kt index b543c24fb5..6ae0963b78 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesPresenter.kt @@ -2,9 +2,9 @@ package eu.kanade.tachiyomi.ui.browse.migration.sources import eu.kanade.domain.source.interactor.GetSourcesWithFavoriteCount import eu.kanade.domain.source.interactor.SetMigrateSorting +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.presentation.browse.MigrateSourceState import eu.kanade.presentation.browse.MigrateSourceStateImpl -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.system.logcat import kotlinx.coroutines.CoroutineScope @@ -21,7 +21,7 @@ import uy.kohesive.injekt.api.get class MigrationSourcesPresenter( private val presenterScope: CoroutineScope, private val state: MigrateSourceStateImpl = MigrateSourceState() as MigrateSourceStateImpl, - private val preferences: PreferencesHelper = Injekt.get(), + private val preferences: SourcePreferences = Injekt.get(), private val getSourcesWithFavoriteCount: GetSourcesWithFavoriteCount = Injekt.get(), private val setMigrateSorting: SetMigrateSorting = Injekt.get(), ) : MigrateSourceState by state { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesFilterPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesFilterPresenter.kt index 06afa87dc6..5cf6e4a5a5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesFilterPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesFilterPresenter.kt @@ -5,9 +5,9 @@ import eu.kanade.domain.source.interactor.GetLanguagesWithSources import eu.kanade.domain.source.interactor.ToggleLanguage import eu.kanade.domain.source.interactor.ToggleSource import eu.kanade.domain.source.model.Source +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.presentation.browse.SourcesFilterState import eu.kanade.presentation.browse.SourcesFilterStateImpl -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.system.logcat @@ -24,7 +24,7 @@ class SourcesFilterPresenter( private val getLanguagesWithSources: GetLanguagesWithSources = Injekt.get(), private val toggleSource: ToggleSource = Injekt.get(), private val toggleLanguage: ToggleLanguage = Injekt.get(), - private val preferences: PreferencesHelper = Injekt.get(), + private val preferences: SourcePreferences = Injekt.get(), ) : BasePresenter(), SourcesFilterState by state { private val _events = Channel(Int.MAX_VALUE) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesPresenter.kt index a9e09a15bd..7a0d66e498 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesPresenter.kt @@ -5,6 +5,7 @@ import eu.kanade.domain.source.interactor.ToggleSource import eu.kanade.domain.source.interactor.ToggleSourcePin import eu.kanade.domain.source.model.Pin import eu.kanade.domain.source.model.Source +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.presentation.browse.SourceUiModel import eu.kanade.presentation.browse.SourcesState import eu.kanade.presentation.browse.SourcesStateImpl @@ -25,6 +26,7 @@ class SourcesPresenter( private val presenterScope: CoroutineScope, private val state: SourcesStateImpl = SourcesState() as SourcesStateImpl, private val preferences: PreferencesHelper = Injekt.get(), + private val sourcePreferences: SourcePreferences = Injekt.get(), private val getEnabledSources: GetEnabledSources = Injekt.get(), private val toggleSource: ToggleSource = Injekt.get(), private val toggleSourcePin: ToggleSourcePin = Injekt.get(), @@ -79,7 +81,7 @@ class SourcesPresenter( fun onOpenSource(source: Source) { if (!preferences.incognitoMode().get()) { - preferences.lastUsedSource().set(source.id) + sourcePreferences.lastUsedSource().set(source.id) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt index d400fe072c..2304826d6c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt @@ -11,6 +11,7 @@ import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager import dev.chrisbanes.insetter.applyInsetter import eu.kanade.domain.manga.model.Manga +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.GlobalSearchControllerBinding @@ -34,6 +35,7 @@ open class GlobalSearchController( GlobalSearchAdapter.OnTitleClickListener { private val preferences: PreferencesHelper by injectLazy() + private val sourcePreferences: SourcePreferences by injectLazy() /** * Adapter containing search results grouped by lang. @@ -174,7 +176,7 @@ open class GlobalSearchController( * @param searchResult result of search. */ fun setItems(searchResult: List) { - if (searchResult.isEmpty() && preferences.searchPinnedSourcesOnly().get()) { + if (searchResult.isEmpty() && sourcePreferences.searchPinnedSourcesOnly().get()) { binding.emptyView.show(R.string.no_pinned_sources) } else { binding.emptyView.hide() @@ -205,7 +207,7 @@ open class GlobalSearchController( */ override fun onTitleClick(source: CatalogueSource) { if (!preferences.incognitoMode().get()) { - preferences.lastUsedSource().set(source.id) + sourcePreferences.lastUsedSource().set(source.id) } router.pushController(BrowseSourceController(source, presenter.query)) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt index 7b2ba18a09..ecab326d4b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt @@ -6,6 +6,7 @@ import eu.kanade.domain.manga.interactor.InsertManga import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.model.toDbManga import eu.kanade.domain.manga.model.toMangaUpdate +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.toDomainManga import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -35,6 +36,7 @@ open class GlobalSearchPresenter( private val initialExtensionFilter: String? = null, val sourceManager: SourceManager = Injekt.get(), val preferences: PreferencesHelper = Injekt.get(), + val sourcePreferences: SourcePreferences = Injekt.get(), private val getManga: GetManga = Injekt.get(), private val insertManga: InsertManga = Injekt.get(), private val updateManga: UpdateManga = Injekt.get(), @@ -96,9 +98,9 @@ open class GlobalSearchPresenter( * @return list containing enabled sources. */ protected open fun getEnabledSources(): List { - val languages = preferences.enabledLanguages().get() - val disabledSourceIds = preferences.disabledSources().get() - val pinnedSourceIds = preferences.pinnedSources().get() + val languages = sourcePreferences.enabledLanguages().get() + val disabledSourceIds = sourcePreferences.disabledSources().get() + val pinnedSourceIds = sourcePreferences.pinnedSources().get() return sourceManager.getCatalogueSources() .filter { it.lang in languages } @@ -123,8 +125,8 @@ open class GlobalSearchPresenter( return filteredSources } - val onlyPinnedSources = preferences.searchPinnedSourcesOnly().get() - val pinnedSourceIds = preferences.pinnedSources().get() + val onlyPinnedSources = sourcePreferences.searchPinnedSourcesOnly().get() + val pinnedSourceIds = sourcePreferences.pinnedSources().get() return enabledSources .filter { if (onlyPinnedSources) it.id.toString() in pinnedSourceIds else true } @@ -156,7 +158,7 @@ open class GlobalSearchPresenter( val initialItems = sources.map { createCatalogueSearchItem(it, null) } var items = initialItems - val pinnedSourceIds = preferences.pinnedSources().get() + val pinnedSourceIds = sourcePreferences.pinnedSources().get() fetchSourcesSubscription?.unsubscribe() fetchSourcesSubscription = Observable.from(sources) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index d7909e248e..6f7734a5ec 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -31,6 +31,7 @@ import com.bluelinelabs.conductor.RouterTransaction import com.google.android.material.navigation.NavigationBarView import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback import dev.chrisbanes.insetter.applyInsetter +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R @@ -78,6 +79,8 @@ import uy.kohesive.injekt.injectLazy class MainActivity : BaseActivity() { + private val sourcePreferences: SourcePreferences by injectLazy() + lateinit var binding: MainActivityBinding private lateinit var router: Router @@ -112,6 +115,7 @@ class MainActivity : BaseActivity() { context = applicationContext, preferences = preferences, networkPreferences = Injekt.get(), + sourcePreferences = sourcePreferences, ) } else { false @@ -254,7 +258,7 @@ class MainActivity : BaseActivity() { .onEach { setUnreadUpdatesBadge() } .launchIn(lifecycleScope) - preferences.extensionUpdatesCount() + sourcePreferences.extensionUpdatesCount() .asHotFlow { setExtensionsBadge() } .launchIn(lifecycleScope) @@ -371,7 +375,7 @@ class MainActivity : BaseActivity() { this@MainActivity, fromAvailableExtensionList = true, )?.let { pendingUpdates -> - preferences.extensionUpdatesCount().set(pendingUpdates.size) + sourcePreferences.extensionUpdatesCount().set(pendingUpdates.size) } } catch (e: Exception) { logcat(LogPriority.ERROR, e) @@ -392,7 +396,7 @@ class MainActivity : BaseActivity() { } private fun setExtensionsBadge() { - val updates = preferences.extensionUpdatesCount().get() + val updates = sourcePreferences.extensionUpdatesCount().get() if (updates > 0) { nav.getOrCreateBadge(R.id.nav_browse).apply { number = updates diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt index 5192a588a3..ede9d6f00c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt @@ -2,10 +2,10 @@ package eu.kanade.tachiyomi.ui.setting import androidx.fragment.app.FragmentActivity import androidx.preference.PreferenceScreen +import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.extension.ExtensionUpdateJob import eu.kanade.tachiyomi.util.preference.bindTo -import eu.kanade.tachiyomi.util.preference.defaultValue import eu.kanade.tachiyomi.util.preference.infoPreference import eu.kanade.tachiyomi.util.preference.onChange import eu.kanade.tachiyomi.util.preference.preferenceCategory @@ -14,10 +14,12 @@ import eu.kanade.tachiyomi.util.preference.summaryRes import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported -import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys +import uy.kohesive.injekt.injectLazy class SettingsBrowseController : SettingsController() { + private val sourcePreferences: SourcePreferences by injectLazy() + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.browse @@ -25,7 +27,7 @@ class SettingsBrowseController : SettingsController() { titleRes = R.string.label_sources switchPreference { - bindTo(preferences.duplicatePinnedSources()) + bindTo(sourcePreferences.duplicatePinnedSources()) titleRes = R.string.pref_duplicate_pinned_sources summaryRes = R.string.pref_duplicate_pinned_sources_summary } @@ -50,9 +52,8 @@ class SettingsBrowseController : SettingsController() { titleRes = R.string.action_global_search switchPreference { - key = Keys.searchPinnedSourcesOnly + bindTo(sourcePreferences.searchPinnedSourcesOnly()) titleRes = R.string.pref_search_pinned_sources_only - defaultValue = false } } @@ -60,7 +61,7 @@ class SettingsBrowseController : SettingsController() { titleRes = R.string.pref_category_nsfw_content switchPreference { - bindTo(preferences.showNsfwSource()) + bindTo(sourcePreferences.showNsfwSource()) titleRes = R.string.pref_show_nsfw_source summaryRes = R.string.requires_app_restart