From 72b95988e55b07b64914c75329b79694100f6f82 Mon Sep 17 00:00:00 2001 From: Katharine Chui Date: Thu, 3 Feb 2022 19:36:24 +0800 Subject: [PATCH] hide catima theme when dynamic color is not available --- .../preferences/SettingsActivity.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java b/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java index 2a3cd54c3..fa9f83a36 100644 --- a/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java +++ b/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java @@ -19,6 +19,8 @@ import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import com.google.android.material.color.DynamicColors; + import nl.invissvenska.numberpickerpreference.NumberDialogPreference; import nl.invissvenska.numberpickerpreference.NumberPickerPreferenceDialogFragment; import protect.card_locker.CatimaAppCompatActivity; @@ -141,12 +143,28 @@ public class SettingsActivity extends CatimaAppCompatActivity { return true; }); - Preference colorPreference = findPreference(getResources().getString(R.string.setting_key_theme_color)); + ListPreference colorPreference = findPreference(getResources().getString(R.string.setting_key_theme_color)); assert colorPreference != null; colorPreference.setOnPreferenceChangeListener((preference, o) -> { refreshActivity(true); return true; }); + if (!DynamicColors.isDynamicColorAvailable()) { + // remove catima from list + CharSequence[] colorValues = colorPreference.getEntryValues(); + CharSequence[] colorEntries = colorPreference.getEntries(); + CharSequence[] newColorValues = new CharSequence[colorValues.length - 1]; + CharSequence[] newColorEntries = new CharSequence[colorEntries.length - 1]; + for (int i = 0, j = 0; i < colorValues.length; i++) { + if (!colorValues[i].equals(getResources().getString(R.string.settings_key_catima_theme))) { + newColorValues[j] = colorValues[i]; + newColorEntries[j] = colorEntries[i]; + j++; + } + } + colorPreference.setEntries(newColorEntries); + colorPreference.setEntryValues(newColorValues); + } } private void refreshActivity(boolean reloadMain) {