diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index 22c776e1b..ecbea0fa9 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -14,10 +14,11 @@ public class GlobalUserPreferences{ public static boolean showInteractionCounts; public static boolean alwaysExpandContentWarnings; public static boolean disableMarquee; - public static ThemePreference theme; public static boolean voteButtonForSingleChoice; + public static ThemePreference theme; + public static ColorPreference color; - private static SharedPreferences getPrefs(){ + private static SharedPreferences getPrefs(){ return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE); } @@ -35,6 +36,7 @@ public class GlobalUserPreferences{ disableMarquee=prefs.getBoolean("disableMarquee", false); voteButtonForSingleChoice=prefs.getBoolean("voteButtonForSingleChoice", true); theme=ThemePreference.values()[prefs.getInt("theme", 0)]; + color=ColorPreference.values()[prefs.getInt("color", 0)]; } public static void save(){ @@ -50,12 +52,23 @@ public class GlobalUserPreferences{ .putBoolean("alwaysExpandContentWarnings", alwaysExpandContentWarnings) .putBoolean("disableMarquee", disableMarquee) .putInt("theme", theme.ordinal()) + .putInt("color", color.ordinal()) .apply(); } + public enum ColorPreference{ + PINK, + PURPLE, + GREEN, + BLUE, + BROWN, + YELLOW + } + public enum ThemePreference{ AUTO, LIGHT, DARK } } + diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java index a6cd0ae49..898b45100 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java @@ -99,6 +99,7 @@ public class SettingsFragment extends MastodonToolbarFragment{ GlobalUserPreferences.disableMarquee=i.checked; GlobalUserPreferences.save(); })); + items.add(new ColorPicker()); items.add(new HeaderItem(R.string.settings_behavior)); items.add(new SwitchItem(R.string.settings_gif, R.drawable.ic_fluent_gif_24_regular, GlobalUserPreferences.playGifs, i->{ @@ -235,6 +236,12 @@ public class SettingsFragment extends MastodonToolbarFragment{ restartActivityToApplyNewTheme(); } + private void onColorPreferenceClick(GlobalUserPreferences.ColorPreference color){ + GlobalUserPreferences.color=color; + GlobalUserPreferences.save(); + restartActivityToApplyNewTheme(); + } + private void onTrueBlackThemeChanged(SwitchItem item){ GlobalUserPreferences.trueBlackTheme=item.checked; GlobalUserPreferences.save(); @@ -438,6 +445,13 @@ public class SettingsFragment extends MastodonToolbarFragment{ } } + public class ColorPicker extends Item{ + @Override + public int getViewType(){ + return 8; + } + } + private static class ThemeItem extends Item{ @Override @@ -522,6 +536,7 @@ public class SettingsFragment extends MastodonToolbarFragment{ case 5 -> new HeaderViewHolder(true); case 6 -> new FooterViewHolder(); case 7 -> new UpdateViewHolder(); + case 8 -> new ColorPickerViewHolder(); default -> throw new IllegalStateException("Unexpected value: "+viewType); }; } @@ -650,6 +665,68 @@ public class SettingsFragment extends MastodonToolbarFragment{ } } } + private class ColorPickerViewHolder extends BindableViewHolder{ + private final Button button; + private final PopupMenu popupMenu; + private final ImageView icon; + + @SuppressLint("ClickableViewAccessibility") + public ColorPickerViewHolder(){ + super(getActivity(), R.layout.item_settings_color_picker, list); + icon=findViewById(R.id.icon); + button=findViewById(R.id.color_picker_button); + popupMenu=new PopupMenu(getActivity(), button, Gravity.CENTER_HORIZONTAL); + popupMenu.inflate(R.menu.color_picker); + popupMenu.setOnMenuItemClickListener(item->{ + GlobalUserPreferences.ColorPreference pref; + int id=item.getItemId(); + if(id==R.id.pink_color) { + pref = GlobalUserPreferences.ColorPreference.PINK; + onColorPreferenceClick(pref); + } + else if(id==R.id.purple_color) { + pref = GlobalUserPreferences.ColorPreference.PURPLE; + onColorPreferenceClick(pref); + } + else if(id==R.id.green_color) { + pref = GlobalUserPreferences.ColorPreference.GREEN; + onColorPreferenceClick(pref); + } + else if(id==R.id.blue_color) { + pref = GlobalUserPreferences.ColorPreference.BLUE; + onColorPreferenceClick(pref); + } + else if(id==R.id.brown_color) { + pref = GlobalUserPreferences.ColorPreference.BROWN; + onColorPreferenceClick(pref); + } + else if(id==R.id.yellow_color) { + pref = GlobalUserPreferences.ColorPreference.YELLOW; + onColorPreferenceClick(pref); + } + else + return false; + return true; + }); +// UiUtils.enablePopupMenuIcons(getActivity(), popupMenu); + button.setOnTouchListener(popupMenu.getDragToOpenListener()); + button.setOnClickListener(v->popupMenu.show()); + } + + @Override + public void onBind(ColorPicker item){ + icon.setImageResource(R.drawable.ic_fluent_color_24_regular); + button.setText(switch(GlobalUserPreferences.color){ + case PINK -> R.string.sk_color_theme_pink; + case PURPLE -> R.string.sk_color_theme_purple; + case GREEN -> R.string.sk_color_theme_green; + case BLUE -> R.string.sk_color_theme_blue; + case BROWN -> R.string.sk_color_theme_brown; + case YELLOW -> R.string.sk_color_theme_yellow; + }); + } + } + private class NotificationPolicyViewHolder extends BindableViewHolder{ private final Button button; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java index 3a18275a7..7caf71663 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java @@ -20,6 +20,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.provider.OpenableColumns; +import android.provider.Settings; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.view.Menu; @@ -655,13 +656,71 @@ public class UiUtils{ } public static void setUserPreferredTheme(Context context){ - context.setTheme(switch(GlobalUserPreferences.theme){ - case AUTO -> GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack : R.style.Theme_Mastodon_AutoLightDark; - case LIGHT -> R.style.Theme_Mastodon_Light; - case DARK -> GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_Dark_TrueBlack : R.style.Theme_Mastodon_Dark; - }); - } +// boolean isDarkTheme = isDarkTheme(); + switch(GlobalUserPreferences.color){ + case PINK: + context.setTheme(switch(GlobalUserPreferences.theme){ + case AUTO -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack : R.style.Theme_Mastodon_AutoLightDark; + case LIGHT -> + R.style.Theme_Mastodon_Light; + case DARK -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_Dark_TrueBlack : R.style.Theme_Mastodon_Dark; + }); + break; + case PURPLE: + context.setTheme(switch(GlobalUserPreferences.theme){ + case AUTO -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack_Original : R.style.Theme_Mastodon_AutoLightDark_Original; + case LIGHT -> + R.style.Theme_Mastodon_Light_Original; + case DARK -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_Dark_TrueBlack_Original : R.style.Theme_Mastodon_Dark_Original; + }); + break; + case GREEN: + context.setTheme(switch(GlobalUserPreferences.theme){ + case AUTO -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack_Green : R.style.Theme_Mastodon_AutoLightDark_Green; + case LIGHT -> + R.style.Theme_Mastodon_Light_Green; + case DARK -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_Dark_TrueBlack_Green : R.style.Theme_Mastodon_Dark_Green; + }); + break; + case BLUE: + context.setTheme(switch(GlobalUserPreferences.theme){ + case AUTO -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack_Blue : R.style.Theme_Mastodon_AutoLightDark_Blue; + case LIGHT -> + R.style.Theme_Mastodon_Light_Blue; + case DARK -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_Dark_TrueBlack_Blue : R.style.Theme_Mastodon_Dark_Blue; + }); + break; + case BROWN: + context.setTheme(switch(GlobalUserPreferences.theme){ + case AUTO -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack_Brown : R.style.Theme_Mastodon_AutoLightDark_Brown; + case LIGHT -> + R.style.Theme_Mastodon_Light_Brown; + case DARK -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_Dark_TrueBlack_Brown : R.style.Theme_Mastodon_Dark_Brown; + }); + break; + case YELLOW: + context.setTheme(switch(GlobalUserPreferences.theme){ + case AUTO -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack_Yellow : R.style.Theme_Mastodon_AutoLightDark_Yellow; + case LIGHT -> + R.style.Theme_Mastodon_Light_Yellow; + case DARK -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_Dark_TrueBlack_Yellow : R.style.Theme_Mastodon_Dark_Yellow; + }); + break; + } + } public static boolean isDarkTheme(){ if(GlobalUserPreferences.theme==GlobalUserPreferences.ThemePreference.AUTO) return (MastodonApp.context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)==Configuration.UI_MODE_NIGHT_YES; diff --git a/mastodon/src/main/res/color/boost_icon.xml b/mastodon/src/main/res/color/boost_icon.xml index 4ce090d84..e50a9554a 100644 --- a/mastodon/src/main/res/color/boost_icon.xml +++ b/mastodon/src/main/res/color/boost_icon.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/mastodon/src/main/res/color/button_bg_primary_dark_on_light.xml b/mastodon/src/main/res/color/button_bg_primary_dark_on_light.xml index ac32e4cf1..a7b7babb4 100644 --- a/mastodon/src/main/res/color/button_bg_primary_dark_on_light.xml +++ b/mastodon/src/main/res/color/button_bg_primary_dark_on_light.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/mastodon/src/main/res/color/button_bg_primary_light_on_dark.xml b/mastodon/src/main/res/color/button_bg_primary_light_on_dark.xml index b79d382f0..df4f68ca9 100644 --- a/mastodon/src/main/res/color/button_bg_primary_light_on_dark.xml +++ b/mastodon/src/main/res/color/button_bg_primary_light_on_dark.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/mastodon/src/main/res/color/button_bg_secondary_light_on_dark.xml b/mastodon/src/main/res/color/button_bg_secondary_light_on_dark.xml index 0f3e8a025..57093c355 100644 --- a/mastodon/src/main/res/color/button_bg_secondary_light_on_dark.xml +++ b/mastodon/src/main/res/color/button_bg_secondary_light_on_dark.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/mastodon/src/main/res/color/button_text_primary_dark_on_light.xml b/mastodon/src/main/res/color/button_text_primary_dark_on_light.xml index d9f2cb44b..373da7995 100644 --- a/mastodon/src/main/res/color/button_text_primary_dark_on_light.xml +++ b/mastodon/src/main/res/color/button_text_primary_dark_on_light.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/mastodon/src/main/res/color/button_text_primary_light_on_dark.xml b/mastodon/src/main/res/color/button_text_primary_light_on_dark.xml index a62f5c520..d8f4d9034 100644 --- a/mastodon/src/main/res/color/button_text_primary_light_on_dark.xml +++ b/mastodon/src/main/res/color/button_text_primary_light_on_dark.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/mastodon/src/main/res/color/button_text_secondary_dark_on_light.xml b/mastodon/src/main/res/color/button_text_secondary_dark_on_light.xml index a62f5c520..131384b06 100644 --- a/mastodon/src/main/res/color/button_text_secondary_dark_on_light.xml +++ b/mastodon/src/main/res/color/button_text_secondary_dark_on_light.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/mastodon/src/main/res/color/button_text_secondary_light_on_dark.xml b/mastodon/src/main/res/color/button_text_secondary_light_on_dark.xml index 4a6b1e796..6393e4041 100644 --- a/mastodon/src/main/res/color/button_text_secondary_light_on_dark.xml +++ b/mastodon/src/main/res/color/button_text_secondary_light_on_dark.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/mastodon/src/main/res/drawable/bg_upload_progress.xml b/mastodon/src/main/res/drawable/bg_upload_progress.xml index d1fa18cd1..969aad66a 100644 --- a/mastodon/src/main/res/drawable/bg_upload_progress.xml +++ b/mastodon/src/main/res/drawable/bg_upload_progress.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/mastodon/src/main/res/drawable/ic_fluent_color_24_regular.xml b/mastodon/src/main/res/drawable/ic_fluent_color_24_regular.xml new file mode 100644 index 000000000..29aafe1e9 --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_color_24_regular.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/drawable/ic_follow_requests_24_badged.xml b/mastodon/src/main/res/drawable/ic_follow_requests_24_badged.xml index dfead8a2c..7f9048281 100644 --- a/mastodon/src/main/res/drawable/ic_follow_requests_24_badged.xml +++ b/mastodon/src/main/res/drawable/ic_follow_requests_24_badged.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/mastodon/src/main/res/drawable/ic_settings_24_badged.xml b/mastodon/src/main/res/drawable/ic_settings_24_badged.xml index de24a3c06..98a6358e3 100644 --- a/mastodon/src/main/res/drawable/ic_settings_24_badged.xml +++ b/mastodon/src/main/res/drawable/ic_settings_24_badged.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/mastodon/src/main/res/drawable/play_button.xml b/mastodon/src/main/res/drawable/play_button.xml index 23b3b5f3b..69bbfbf49 100644 --- a/mastodon/src/main/res/drawable/play_button.xml +++ b/mastodon/src/main/res/drawable/play_button.xml @@ -2,7 +2,7 @@ - + diff --git a/mastodon/src/main/res/layout/item_settings_color_picker.xml b/mastodon/src/main/res/layout/item_settings_color_picker.xml new file mode 100644 index 000000000..6026d5887 --- /dev/null +++ b/mastodon/src/main/res/layout/item_settings_color_picker.xml @@ -0,0 +1,46 @@ + + + + + + + + +