Skip to content

Commit

Permalink
Fix dynamic color not applied on some devices #429
Browse files Browse the repository at this point in the history
  • Loading branch information
cemrich committed Apr 4, 2024
1 parent ace4d05 commit 0c6045b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/raw/changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 0c6045b

Please sign in to comment.