Fix dynamic colors setting

This commit is contained in:
Grishka 2024-11-01 10:45:41 +03:00
parent 62602839db
commit b28c095226
2 changed files with 12 additions and 8 deletions

View File

@ -40,8 +40,13 @@ public class SettingsDisplayFragment extends BaseSettingsFragment<Void>{
AccountLocalPreferences lp=s.getLocalPreferences(); AccountLocalPreferences lp=s.getLocalPreferences();
List<ListItem<Void>> items=new ArrayList<>(); List<ListItem<Void>> items=new ArrayList<>();
items.add(themeItem=new ListItem<>(R.string.settings_theme, getAppearanceValue(), R.drawable.ic_dark_mode_24px, this::onAppearanceClick)); items.add(themeItem=new ListItem<>(R.string.settings_theme, getAppearanceValue(), R.drawable.ic_dark_mode_24px, this::onAppearanceClick));
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.S) if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.S){
items.add(dynamicColorsItem=new CheckableListItem<>(R.string.settings_use_dynamic_colors, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.useDynamicColors, R.drawable.ic_palette_24px, this::onDynamicColorsClick)); items.add(dynamicColorsItem=new CheckableListItem<>(R.string.settings_use_dynamic_colors, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.useDynamicColors, R.drawable.ic_palette_24px, item->{
toggleCheckableItem(item);
setUseDynamicColors(item.checked);
}));
dynamicColorsItem.checkedChangeListener=this::setUseDynamicColors;
}
items.add(showCWsItem=new CheckableListItem<>(R.string.settings_show_cws, 0, CheckableListItem.Style.SWITCH, lp.showCWs, R.drawable.ic_warning_24px, this::toggleCheckableItem)); items.add(showCWsItem=new CheckableListItem<>(R.string.settings_show_cws, 0, CheckableListItem.Style.SWITCH, lp.showCWs, R.drawable.ic_warning_24px, this::toggleCheckableItem));
items.add(hideSensitiveMediaItem=new CheckableListItem<>(R.string.settings_hide_sensitive_media, 0, CheckableListItem.Style.SWITCH, lp.hideSensitiveMedia, R.drawable.ic_no_adult_content_24px, this::toggleCheckableItem)); items.add(hideSensitiveMediaItem=new CheckableListItem<>(R.string.settings_hide_sensitive_media, 0, CheckableListItem.Style.SWITCH, lp.hideSensitiveMedia, R.drawable.ic_no_adult_content_24px, this::toggleCheckableItem));
items.add(interactionCountsItem=new CheckableListItem<>(R.string.settings_show_interaction_counts, 0, CheckableListItem.Style.SWITCH, lp.showInteractionCounts, R.drawable.ic_social_leaderboard_24px, this::toggleCheckableItem)); items.add(interactionCountsItem=new CheckableListItem<>(R.string.settings_show_interaction_counts, 0, CheckableListItem.Style.SWITCH, lp.showInteractionCounts, R.drawable.ic_social_leaderboard_24px, this::toggleCheckableItem));
@ -112,10 +117,9 @@ public class SettingsDisplayFragment extends BaseSettingsFragment<Void>{
.show(); .show();
} }
private void onDynamicColorsClick(CheckableListItem<?> item){ private void setUseDynamicColors(boolean useDynamicColors){
item.toggle(); dynamicColorsItem.checked=useDynamicColors;
rebindItem(item); GlobalUserPreferences.useDynamicColors=useDynamicColors;
GlobalUserPreferences.useDynamicColors=item.checked;
GlobalUserPreferences.save(); GlobalUserPreferences.save();
restartActivityToApplyNewTheme(); restartActivityToApplyNewTheme();
} }

View File

@ -5,7 +5,7 @@
<item name="android:enforceNavigationBarContrast" tools:ignore="NewApi">false</item> <item name="android:enforceNavigationBarContrast" tools:ignore="NewApi">false</item>
<item name="android:enforceStatusBarContrast" tools:ignore="NewApi">false</item> <item name="android:enforceStatusBarContrast" tools:ignore="NewApi">false</item>
<item name="android:splitMotionEvents">false</item> <item name="android:splitMotionEvents">false</item>
<item name="android:windowBackground">@color/m3_sys_light_surface</item> <item name="android:windowBackground">?colorM3Surface</item>
<item name="android:editTextStyle">@style/Widget.Mastodon.EditText</item> <item name="android:editTextStyle">@style/Widget.Mastodon.EditText</item>
<item name="android:spinnerStyle">@style/Widget.Mastodon.Spinner</item> <item name="android:spinnerStyle">@style/Widget.Mastodon.Spinner</item>
<item name="android:actionModeCloseButtonStyle">@style/action_mode_close</item> <item name="android:actionModeCloseButtonStyle">@style/action_mode_close</item>
@ -90,7 +90,7 @@
<item name="android:enforceNavigationBarContrast" tools:ignore="NewApi">false</item> <item name="android:enforceNavigationBarContrast" tools:ignore="NewApi">false</item>
<item name="android:enforceStatusBarContrast" tools:ignore="NewApi">false</item> <item name="android:enforceStatusBarContrast" tools:ignore="NewApi">false</item>
<item name="android:splitMotionEvents">false</item> <item name="android:splitMotionEvents">false</item>
<item name="android:windowBackground">@color/m3_sys_dark_surface</item> <item name="android:windowBackground">?colorM3Surface</item>
<item name="android:editTextStyle">@style/Widget.Mastodon.EditText</item> <item name="android:editTextStyle">@style/Widget.Mastodon.EditText</item>
<item name="android:spinnerStyle">@style/Widget.Mastodon.Spinner</item> <item name="android:spinnerStyle">@style/Widget.Mastodon.Spinner</item>
<item name="android:actionModeCloseButtonStyle">@style/action_mode_close</item> <item name="android:actionModeCloseButtonStyle">@style/action_mode_close</item>