From 0c6045b24f683fcaafdcc14da4fd540e7fd8b6db Mon Sep 17 00:00:00 2001 From: Christine Coenen Date: Fri, 29 Mar 2024 18:56:19 +0100 Subject: [PATCH] Fix dynamic color not applied on some devices #429 --- .../app/settings/repository/SettingsRepository.kt | 13 ++----------- .../zapp/utils/system/PreferenceFragmentHelper.kt | 8 +++++++- app/src/main/res/raw/changelog.md | 3 +++ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/de/christinecoenen/code/zapp/app/settings/repository/SettingsRepository.kt b/app/src/main/java/de/christinecoenen/code/zapp/app/settings/repository/SettingsRepository.kt index 0a2dac8f..ae27eac4 100644 --- a/app/src/main/java/de/christinecoenen/code/zapp/app/settings/repository/SettingsRepository.kt +++ b/app/src/main/java/de/christinecoenen/code/zapp/app/settings/repository/SettingsRepository.kt @@ -7,7 +7,7 @@ import android.os.Build import androidx.appcompat.app.AppCompatDelegate import androidx.preference.PreferenceManager import de.christinecoenen.code.zapp.R -import java.util.* +import java.util.Locale import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.minutes @@ -61,17 +61,8 @@ class SettingsRepository(context: Context) { val downloadToSdCard: Boolean get() = preferences.getBoolean(context.getString(R.string.pref_key_download_to_sd_card), true) - var dynamicColors: Boolean + val dynamicColors: Boolean get() = preferences.getBoolean(context.getString(R.string.pref_key_dynamic_colors), false) - @SuppressLint("ApplySharedPref") - set(enabled) { - // "commit" instead of "apply" is fine here, because we need to restart the app - // after setting this preference. Doing it synchroniously is the only way to save - // the setting across the app restart. - preferences.edit() - .putBoolean(context.getString(R.string.pref_key_dynamic_colors), enabled) - .commit() - } val uiMode: Int get() { diff --git a/app/src/main/java/de/christinecoenen/code/zapp/utils/system/PreferenceFragmentHelper.kt b/app/src/main/java/de/christinecoenen/code/zapp/utils/system/PreferenceFragmentHelper.kt index 70b630e9..9d1c96c8 100644 --- a/app/src/main/java/de/christinecoenen/code/zapp/utils/system/PreferenceFragmentHelper.kt +++ b/app/src/main/java/de/christinecoenen/code/zapp/utils/system/PreferenceFragmentHelper.kt @@ -13,6 +13,8 @@ import com.google.android.material.color.DynamicColors import com.jakewharton.processphoenix.ProcessPhoenix import de.christinecoenen.code.zapp.app.settings.helper.ShortcutPreference import de.christinecoenen.code.zapp.app.settings.repository.SettingsRepository +import java.util.Timer +import kotlin.concurrent.schedule class PreferenceFragmentHelper( private val preferenceFragment: PreferenceFragmentCompat, @@ -38,7 +40,11 @@ class PreferenceFragmentHelper( private var channelSelectionClickListener: OnPreferenceClickListener? = null private val dynamicColorChangeListener = Preference.OnPreferenceChangeListener { _, _ -> - ProcessPhoenix.triggerRebirth(preferenceFragment.requireContext()) + // Delay to wait for pereferences to be persisted (on very fast devices) + // before killing the app - there is no listener that fires *after* persisting. + Timer().schedule(200) { + ProcessPhoenix.triggerRebirth(preferenceFragment.requireContext()) + } true } diff --git a/app/src/main/res/raw/changelog.md b/app/src/main/res/raw/changelog.md index 77dcd389..710a383b 100644 --- a/app/src/main/res/raw/changelog.md +++ b/app/src/main/res/raw/changelog.md @@ -1,3 +1,6 @@ +# v-next +* Dynamische Farben wurden auf manchen Geräten nicht übernommen + # 8.5.0 * Einstellungen zu Android-TV-version hinzugefügt * Angeschnittener Text im Vorspulen-Button gefixt