From d9f6ef69fe9a31bec3815c9ecbc275b8197489b6 Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Thu, 22 Dec 2022 09:01:30 -0300 Subject: [PATCH] Revert "Whatever the fuck this is. Hopefully it compiles on the first try" This reverts commit bdac1d5bb4c0a799ade3ba1563e75c56c1663ec8. --- .../android/GlobalUserPreferences.java | 20 +- .../android/fragments/SettingsFragment.java | 2 +- .../android/ui/utils/ColorPalette.java | 68 -- .../android/ui/utils/UiUtils.java | 102 ++- .../src/main/res/values-night/palettes.xml | 4 - mastodon/src/main/res/values-night/styles.xml | 21 + .../src/main/res/values-notnight/palettes.xml | 3 - mastodon/src/main/res/values/attrs.xml | 26 - mastodon/src/main/res/values/colors.xml | 190 ++++- mastodon/src/main/res/values/palettes.xml | 228 ----- mastodon/src/main/res/values/strings_sk.xml | 1 - mastodon/src/main/res/values/styles.xml | 802 ++++++++++++++++-- 12 files changed, 1006 insertions(+), 461 deletions(-) delete mode 100644 mastodon/src/main/java/org/joinmastodon/android/ui/utils/ColorPalette.java delete mode 100644 mastodon/src/main/res/values-night/palettes.xml delete mode 100644 mastodon/src/main/res/values-notnight/palettes.xml delete mode 100644 mastodon/src/main/res/values/palettes.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index 8f51efebd..285b619c9 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -4,8 +4,7 @@ import static org.joinmastodon.android.api.MastodonAPIController.gson; import android.content.Context; import android.content.SharedPreferences; - -import androidx.annotation.NonNull; +import android.os.Build; import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; @@ -33,6 +32,7 @@ public class GlobalUserPreferences{ private final static Type recentLanguagesType = new TypeToken>>() {}.getType(); public static Map> recentLanguages; + public static Map defaultLanguages; private static SharedPreferences getPrefs(){ return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE); @@ -59,13 +59,12 @@ public class GlobalUserPreferences{ voteButtonForSingleChoice=prefs.getBoolean("voteButtonForSingleChoice", true); theme=ThemePreference.values()[prefs.getInt("theme", 0)]; recentLanguages=fromJson(prefs.getString("recentLanguages", "{}"), recentLanguagesType, new HashMap<>()); - - try { - color=ColorPreference.valueOf(prefs.getString("color", ColorPreference.PINK.name())); - } catch (IllegalArgumentException|ClassCastException ignored) { - // invalid color name or color was previously saved as integer - color=ColorPreference.PINK; + if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){ + color=ColorPreference.values()[prefs.getInt("color", 0)]; + }else{ + color=ColorPreference.values()[prefs.getInt("color", 1)]; } + } public static void save(){ @@ -82,15 +81,15 @@ public class GlobalUserPreferences{ .putBoolean("disableMarquee", disableMarquee) .putBoolean("disableSwipe", disableSwipe) .putInt("theme", theme.ordinal()) - .putString("color", color.name()) .putString("recentLanguages", gson.toJson(recentLanguages)) + .putInt("color", color.ordinal()) .apply(); } public enum ColorPreference{ MATERIAL3, - PINK, PURPLE, + PINK, GREEN, BLUE, ORANGE, @@ -104,4 +103,3 @@ public class GlobalUserPreferences{ 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 9b29c6468..3a8abb764 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java @@ -726,7 +726,7 @@ public class SettingsFragment extends MastodonToolbarFragment{ pref = GlobalUserPreferences.ColorPreference.MATERIAL3; onColorPreferenceClick(pref); }else{ - Toast.makeText(getActivity(), R.string.sk_not_support, + Toast.makeText(getActivity(), R.string.sk_not_supported, Toast.LENGTH_LONG).show(); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/ColorPalette.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/ColorPalette.java deleted file mode 100644 index e4edf2796..000000000 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/ColorPalette.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.joinmastodon.android.ui.utils; - -import static org.joinmastodon.android.GlobalUserPreferences.ColorPreference; -import static org.joinmastodon.android.GlobalUserPreferences.ThemePreference; -import static org.joinmastodon.android.GlobalUserPreferences.theme; -import static org.joinmastodon.android.GlobalUserPreferences.trueBlackTheme; - -import android.content.Context; -import android.content.res.Resources; - -import androidx.annotation.StyleRes; - -import org.joinmastodon.android.GlobalUserPreferences; -import org.joinmastodon.android.R; - -import java.util.Map; - -public class ColorPalette { - public static final Map palettes = Map.of( - ColorPreference.MATERIAL3, new ColorPalette(R.style.ColorPalette_Material3) - .dark(R.style.ColorPalette_Material3_Dark, R.style.ColorPalette_Material3_AutoLightDark), - ColorPreference.PINK, new ColorPalette(R.style.ColorPalette_Pink), - ColorPreference.PURPLE, new ColorPalette(R.style.ColorPalette_Purple), - ColorPreference.GREEN, new ColorPalette(R.style.ColorPalette_Green), - ColorPreference.BLUE, new ColorPalette(R.style.ColorPalette_Blue), - ColorPreference.BROWN, new ColorPalette(R.style.ColorPalette_Brown), - ColorPreference.RED, new ColorPalette(R.style.ColorPalette_Red), - ColorPreference.YELLOW, new ColorPalette(R.style.ColorPalette_Yellow) - ); - - private @StyleRes int base; - private @StyleRes int autoDark; - private @StyleRes int light; - private @StyleRes int dark; - private @StyleRes int black; - private @StyleRes int autoBlack; - - public ColorPalette(@StyleRes int baseRes) { base = baseRes; } - - public ColorPalette(@StyleRes int lightRes, @StyleRes int darkRes, @StyleRes int autoDarkRes, @StyleRes int blackRes, @StyleRes int autoBlackRes) { - light = lightRes; - dark = darkRes; - autoDark = autoDarkRes; - black = blackRes; - autoBlack = autoBlackRes; - } - - public ColorPalette light(@StyleRes int res) { light = res; return this; } - public ColorPalette dark(@StyleRes int res, @StyleRes int auto) { dark = res; autoDark = auto; return this; } - public ColorPalette black(@StyleRes int res, @StyleRes int auto) { dark = res; autoBlack = auto; return this; } - - public void apply(Context context) { - if (!((dark != 0 && autoDark != 0) || (black != 0 && autoBlack != 0) || light != 0 || base != 0)) { - throw new IllegalStateException("Invalid color scheme definition"); - } - - Resources.Theme t = context.getTheme(); - if (base != 0) t.applyStyle(base, true); - if (light != 0 && theme.equals(ThemePreference.LIGHT)) t.applyStyle(light, true); - else if (theme.equals(ThemePreference.DARK)) { - if (dark != 0 && !trueBlackTheme) t.applyStyle(dark, true); - else if (black != 0 && trueBlackTheme) t.applyStyle(black, true); - } else if (theme.equals(ThemePreference.AUTO)) { - if (autoDark != 0 && !trueBlackTheme) t.applyStyle(autoDark, true); - else if (autoBlack != 0 && trueBlackTheme) t.applyStyle(autoBlack, true); - } - } -} 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 bea5dacc9..a56b94830 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 @@ -1,8 +1,5 @@ package org.joinmastodon.android.ui.utils; -import static org.joinmastodon.android.GlobalUserPreferences.theme; -import static org.joinmastodon.android.GlobalUserPreferences.trueBlackTheme; - import android.annotation.SuppressLint; import android.app.Activity; import android.content.ActivityNotFoundException; @@ -27,6 +24,7 @@ import android.os.Looper; import android.os.VibrationEffect; import android.os.Vibrator; import android.provider.OpenableColumns; +import android.provider.Settings; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; @@ -59,6 +57,8 @@ import org.joinmastodon.android.events.NotificationDeletedEvent; import org.joinmastodon.android.events.RemoveAccountPostsEvent; import org.joinmastodon.android.events.StatusDeletedEvent; import org.joinmastodon.android.events.StatusUnpinnedEvent; +import org.joinmastodon.android.fragments.BaseStatusListFragment; +import org.joinmastodon.android.fragments.ComposeFragment; import org.joinmastodon.android.fragments.HashtagTimelineFragment; import org.joinmastodon.android.fragments.ListTimelineFragment; import org.joinmastodon.android.fragments.ProfileFragment; @@ -661,19 +661,95 @@ public class UiUtils{ } public static void setUserPreferredTheme(Context context){ - context.setTheme(switch (theme) { - case LIGHT -> R.style.Theme_Mastodon_Light; - case DARK -> trueBlackTheme ? R.style.Theme_Mastodon_Dark_TrueBlack : R.style.Theme_Mastodon_Dark; - default -> trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack : R.style.Theme_Mastodon_AutoLightDark; - }); +// 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 ORANGE: + context.setTheme(switch(GlobalUserPreferences.theme){ + case AUTO -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack_Orange : R.style.Theme_Mastodon_AutoLightDark_Orange; + case LIGHT -> + R.style.Theme_Mastodon_Light_Orange; + case DARK -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_Dark_TrueBlack_Orange : R.style.Theme_Mastodon_Dark_Orange; + }); + 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; + case RED: + context.setTheme(switch(GlobalUserPreferences.theme){ + case AUTO -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack_Red : R.style.Theme_Mastodon_AutoLightDark_Red; + case LIGHT -> + R.style.Theme_Mastodon_Light_Red; + case DARK -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_Dark_TrueBlack_Red : R.style.Theme_Mastodon_Dark_Red; + }); + break; + case MATERIAL3: + context.setTheme(switch(GlobalUserPreferences.theme){ + case AUTO -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack_Material3 : R.style.Theme_Mastodon_AutoLightDark_Material3; + case LIGHT -> + R.style.Theme_Mastodon_Light_Material3; + case DARK -> + GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_Dark_TrueBlack_Material3 : R.style.Theme_Mastodon_Dark_Material3; + }); + break; + } - ColorPalette palette = ColorPalette.palettes.get(GlobalUserPreferences.color); - if (palette != null) palette.apply(context); } public static boolean isDarkTheme(){ - if(theme==GlobalUserPreferences.ThemePreference.AUTO) + if(GlobalUserPreferences.theme==GlobalUserPreferences.ThemePreference.AUTO) return (MastodonApp.context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)==Configuration.UI_MODE_NIGHT_YES; - return theme==GlobalUserPreferences.ThemePreference.DARK; + return GlobalUserPreferences.theme==GlobalUserPreferences.ThemePreference.DARK; } public static void openURL(Context context, @Nullable String accountID, String url){ @@ -715,7 +791,7 @@ public class UiUtils{ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) vibrator.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE)); else vibrator.vibrate(50); } - + private static String getSystemProperty(String key){ try{ Class props=Class.forName("android.os.SystemProperties"); diff --git a/mastodon/src/main/res/values-night/palettes.xml b/mastodon/src/main/res/values-night/palettes.xml deleted file mode 100644 index 95b8f137e..000000000 --- a/mastodon/src/main/res/values-night/palettes.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mastodon/src/main/res/values/strings_sk.xml b/mastodon/src/main/res/values/strings_sk.xml index a449a31a7..1bdb2145b 100644 --- a/mastodon/src/main/res/values/strings_sk.xml +++ b/mastodon/src/main/res/values/strings_sk.xml @@ -63,5 +63,4 @@ example.social \@megalodon Disable swiping between tabs - Not supported on your device diff --git a/mastodon/src/main/res/values/styles.xml b/mastodon/src/main/res/values/styles.xml index c03f83788..1a659be15 100644 --- a/mastodon/src/main/res/values/styles.xml +++ b/mastodon/src/main/res/values/styles.xml @@ -13,30 +13,30 @@ @style/Widget.Mastodon.Button.Secondary_DarkOnLight @style/Widget.Mastodon.Button.Large.Primary_DarkOnLight @style/Widget.Mastodon.Button.Large.Secondary_DarkOnLight - ?colorPrimary700 - ?colorGray800 - ?colorGray100 - ?colorGray800 - ?colorGray500 - ?colorGray50 + @color/primary_700 + @color/custom_gray_800 + @color/gray_100 + @color/custom_gray_800 + @color/custom_gray_500 + @color/gray_50 #E9EDF2 - ?colorGray50 - ?colorGray25 + @color/gray_50 + @color/gray_25 ?colorBackgroundLightest - ?colorGray900 + @color/custom_gray_900 @color/white - ?colorGray50 - ?android:statusBarColor + @color/gray_50 + @color/navigation_bar_bg @style/Theme.Mastodon.Toolbar @style/Theme.Mastodon.Dialog.Alert - ?colorPrimary500 - ?colorGray300 - ?colorPrimary600 - ?colorGray200 - ?colorGray600 - ?colorGray400 - ?colorPrimary100 - ?colorGray500 + @color/primary_500 + @color/gray_300 + @color/primary_600 + @color/gray_200 + @color/custom_gray_600 + @color/gray_400 + @color/primary_100 + @color/custom_gray_500 @drawable/bg_button_primary_dark_on_light @drawable/bg_edittext_light @@ -45,7 +45,7 @@ true @style/Widget.Mastodon.PopupMenu @style/Widget.Mastodon.PopupMenu - + @color/m3_sys_light_primary @color/m3_sys_light_on_primary @@ -74,7 +74,6 @@ #410E0B - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +