From afb1ee2200053f3ea0603f7db2283043792fb974 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 30 Sep 2023 14:36:06 -0400 Subject: [PATCH] Rename new method in ConfigurableSource to get preferences Maybe fixes #9969 --- .../eu/kanade/tachiyomi/data/track/kavita/Kavita.kt | 3 ++- .../eu/kanade/tachiyomi/source/SourceExtensions.kt | 2 -- .../extension/details/SourcePreferencesScreen.kt | 9 +++------ .../eu/kanade/tachiyomi/source/ConfigurableSource.kt | 10 ++++++++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt index f90038161..cb6e52e68 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt @@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.data.track.Tracker import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.Source +import eu.kanade.tachiyomi.source.sourcePreferences import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.source.service.SourceManager import uy.kohesive.injekt.injectLazy @@ -121,7 +122,7 @@ class Kavita(id: Long) : Tracker(id, "Kavita"), EnhancedTracker { (0..7).map { bytes[it].toLong() and 0xff shl 8 * (7 - it) } .reduce(Long::or) and Long.MAX_VALUE } - val preferences = (sourceManager.get(sourceId) as ConfigurableSource).getPreferences() + val preferences = (sourceManager.get(sourceId) as ConfigurableSource).sourcePreferences() val prefApiUrl = preferences.getString("APIURL", "") val prefApiKey = preferences.getString("APIKEY", "") 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 8f4faaaa9..7be9c4d20 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/SourceExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/SourceExtensions.kt @@ -10,8 +10,6 @@ import uy.kohesive.injekt.api.get fun Source.icon(): Drawable? = Injekt.get().getAppIconForSource(this.id) -fun Source.getPreferenceKey(): String = "source_$id" - fun Source.toStubSource(): StubSource = StubSource(id = id, lang = lang, name = name) fun Source.getNameForMangaInfo(): String { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesScreen.kt index 78aa37109..4e391cb3e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesScreen.kt @@ -39,7 +39,7 @@ import eu.kanade.presentation.util.Screen import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.SharedPreferencesDataStore import eu.kanade.tachiyomi.source.ConfigurableSource -import eu.kanade.tachiyomi.source.getPreferenceKey +import eu.kanade.tachiyomi.source.sourcePreferences import eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText.Companion.setIncognito import tachiyomi.domain.source.service.SourceManager import tachiyomi.presentation.core.components.material.Scaffold @@ -134,12 +134,9 @@ class SourcePreferencesFragment : PreferenceFragmentCompat() { private fun populateScreen(): PreferenceScreen { val sourceId = requireArguments().getLong(SOURCE_ID) - val source = Injekt.get().get(sourceId)!! + val source = Injekt.get().get(sourceId)!! as ConfigurableSource - check(source is ConfigurableSource) - - val sharedPreferences = requireContext().getSharedPreferences(source.getPreferenceKey(), Context.MODE_PRIVATE) - val dataStore = SharedPreferencesDataStore(sharedPreferences) + val dataStore = SharedPreferencesDataStore(source.sourcePreferences()) preferenceManager.preferenceDataStore = dataStore val sourceScreen = preferenceManager.createPreferenceScreen(requireContext()) diff --git a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/ConfigurableSource.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/ConfigurableSource.kt index 4be411e3b..ea5eb848e 100644 --- a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/ConfigurableSource.kt +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/ConfigurableSource.kt @@ -13,8 +13,14 @@ interface ConfigurableSource : Source { * * @since extensions-lib 1.5 */ - fun getPreferences(): SharedPreferences = - Injekt.get().getSharedPreferences("source_$id", Context.MODE_PRIVATE) + fun getSourcePreferences(): SharedPreferences = + Injekt.get().getSharedPreferences(preferenceKey(), Context.MODE_PRIVATE) fun setupPreferenceScreen(screen: PreferenceScreen) } + +private fun ConfigurableSource.preferenceKey(): String = "source_$id" + +// TODO: use getSourcePreferences once all extensions are on ext-lib 1.5 +fun ConfigurableSource.sourcePreferences(): SharedPreferences = + Injekt.get().getSharedPreferences(preferenceKey(), Context.MODE_PRIVATE)