0
0
mirror of https://github.com/mediathekview/zapp.git synced 2024-09-20 04:12:14 +02:00

Fix dynamic colors not being applied in release build

This commit is contained in:
Christine Coenen 2023-01-08 18:28:58 +01:00
parent fd803f2b6d
commit 3513ceeeb5
2 changed files with 14 additions and 2 deletions

View File

@ -43,8 +43,17 @@ class SettingsRepository(context: Context) {
val downloadToSdCard: Boolean
get() = preferences.getBoolean(context.getString(R.string.pref_key_download_to_sd_card), true)
val dynamicColors: Boolean
var 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() {

View File

@ -72,7 +72,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
// only show the preference for dynamic colors when available (Android 12 and up)
dynamicColorsPreference.isVisible = DynamicColors.isDynamicColorAvailable()
dynamicColorsPreference.setOnPreferenceChangeListener { _, _ ->
dynamicColorsPreference.setOnPreferenceChangeListener { _, useDynamicColors ->
// save explicitly to persist before app restart
settingsRepository.dynamicColors = useDynamicColors as Boolean
// app restart
ProcessPhoenix.triggerRebirth(context)
true
}