From 5700c7a0c7bf532faadf50e261a03b84f36c6fe1 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 8 May 2021 19:52:31 -0400 Subject: [PATCH] Instantiate extension preferences with proper datastore earlier --- .../data/preference/EmptyPreferenceDataStore.kt | 2 +- .../extension/details/SourcePreferencesController.kt | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/EmptyPreferenceDataStore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/EmptyPreferenceDataStore.kt index 3562b2748a..2f2081a27b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/EmptyPreferenceDataStore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/EmptyPreferenceDataStore.kt @@ -40,7 +40,7 @@ class EmptyPreferenceDataStore : PreferenceDataStore() { } override fun getStringSet(key: String?, defValues: Set?): Set? { - return emptySet() + return null } override fun putStringSet(key: String?, values: Set?) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesController.kt index bb85a97215..d68f09e887 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesController.kt @@ -21,7 +21,6 @@ import androidx.preference.PreferenceManager import androidx.preference.PreferenceScreen import androidx.recyclerview.widget.LinearLayoutManager import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.EmptyPreferenceDataStore import eu.kanade.tachiyomi.data.preference.SharedPreferencesDataStore import eu.kanade.tachiyomi.databinding.SourcePreferencesControllerBinding import eu.kanade.tachiyomi.source.ConfigurableSource @@ -66,7 +65,10 @@ class SourcePreferencesController(bundle: Bundle? = null) : val themedContext by lazy { getPreferenceThemeContext() } val manager = PreferenceManager(themedContext) - manager.preferenceDataStore = EmptyPreferenceDataStore() + val dataStore = SharedPreferencesDataStore( + context.getSharedPreferences(source.getPreferenceKey(), Context.MODE_PRIVATE) + ) + manager.preferenceDataStore = dataStore manager.onDisplayPreferenceDialogListener = this val screen = manager.createPreferenceScreen(themedContext) preferenceScreen = screen @@ -101,10 +103,6 @@ class SourcePreferencesController(bundle: Bundle? = null) : private fun addPreferencesForSource(screen: PreferenceScreen, source: Source) { val context = screen.context - val dataStore = SharedPreferencesDataStore( - context.getSharedPreferences(source.getPreferenceKey(), Context.MODE_PRIVATE) - ) - if (source is ConfigurableSource) { val newScreen = screen.preferenceManager.createPreferenceScreen(context) source.setupPreferenceScreen(newScreen) @@ -113,7 +111,6 @@ class SourcePreferencesController(bundle: Bundle? = null) : while (newScreen.preferenceCount != 0) { val pref = newScreen.getPreference(0) pref.isIconSpaceReserved = false - pref.preferenceDataStore = dataStore pref.order = Int.MAX_VALUE // reset to default order newScreen.removePreference(pref)