Adding mastodon original colors toggle. Partially fixing #90

This commit is contained in:
LucasGGamerM
2022-11-28 15:40:29 -03:00
parent e6bb319d8b
commit ff215412c8
6 changed files with 59 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
public class GlobalUserPreferences{ public class GlobalUserPreferences{
public static boolean originalColors;
public static boolean playGifs; public static boolean playGifs;
public static boolean useCustomTabs; public static boolean useCustomTabs;
public static boolean trueBlackTheme; public static boolean trueBlackTheme;
@@ -21,6 +22,7 @@ public class GlobalUserPreferences{
public static void load(){ public static void load(){
SharedPreferences prefs=getPrefs(); SharedPreferences prefs=getPrefs();
originalColors=prefs.getBoolean("originalColors", false);
playGifs=prefs.getBoolean("playGifs", true); playGifs=prefs.getBoolean("playGifs", true);
useCustomTabs=prefs.getBoolean("useCustomTabs", true); useCustomTabs=prefs.getBoolean("useCustomTabs", true);
trueBlackTheme=prefs.getBoolean("trueBlackTheme", false); trueBlackTheme=prefs.getBoolean("trueBlackTheme", false);
@@ -35,6 +37,7 @@ public class GlobalUserPreferences{
public static void save(){ public static void save(){
getPrefs().edit() getPrefs().edit()
.putBoolean("originalColors", originalColors)
.putBoolean("playGifs", playGifs) .putBoolean("playGifs", playGifs)
.putBoolean("useCustomTabs", useCustomTabs) .putBoolean("useCustomTabs", useCustomTabs)
.putBoolean("showReplies", showReplies) .putBoolean("showReplies", showReplies)
@@ -54,3 +57,4 @@ public class GlobalUserPreferences{
DARK DARK
} }
} }

View File

@@ -99,6 +99,8 @@ public class SettingsFragment extends MastodonToolbarFragment{
GlobalUserPreferences.disableMarquee=i.checked; GlobalUserPreferences.disableMarquee=i.checked;
GlobalUserPreferences.save(); GlobalUserPreferences.save();
})); }));
items.add(new SwitchItem(R.string.enable_mastodon_original_colors, R.drawable.bg_button_green, GlobalUserPreferences.originalColors, this::onOriginalColorChanged));
items.add(new HeaderItem(R.string.settings_behavior)); 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->{ items.add(new SwitchItem(R.string.settings_gif, R.drawable.ic_fluent_gif_24_regular, GlobalUserPreferences.playGifs, i->{
@@ -240,6 +242,12 @@ public class SettingsFragment extends MastodonToolbarFragment{
} }
} }
private void onOriginalColorChanged(SwitchItem item){
GlobalUserPreferences.originalColors=item.checked;
GlobalUserPreferences.save();
restartActivityToApplyNewTheme();
}
private void restartActivityToApplyNewTheme(){ private void restartActivityToApplyNewTheme(){
// Calling activity.recreate() causes a black screen for like half a second. // Calling activity.recreate() causes a black screen for like half a second.
// So, let's take a screenshot and overlay it on top to create the illusion of a smoother transition. // So, let's take a screenshot and overlay it on top to create the illusion of a smoother transition.

View File

@@ -655,13 +655,16 @@ public class UiUtils{
} }
public static void setUserPreferredTheme(Context context){ public static void setUserPreferredTheme(Context context){
boolean isDarkTheme = isDarkTheme();
context.setTheme(switch(GlobalUserPreferences.theme){ context.setTheme(switch(GlobalUserPreferences.theme){
case AUTO -> GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack : R.style.Theme_Mastodon_AutoLightDark; case AUTO ->
case LIGHT -> R.style.Theme_Mastodon_Light; GlobalUserPreferences.originalColors ? (GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack_Original : (isDarkTheme ? R.style.Theme_Mastodon_Dark_Original : R.style.Theme_Mastodon_AutoLightDark_Original)) : (GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack : R.style.Theme_Mastodon_AutoLightDark);
case DARK -> GlobalUserPreferences.trueBlackTheme ? R.style.Theme_Mastodon_Dark_TrueBlack : R.style.Theme_Mastodon_Dark; case LIGHT ->
GlobalUserPreferences.originalColors ? R.style.Theme_Mastodon_Light_Original : R.style.Theme_Mastodon_Light;
case DARK ->
GlobalUserPreferences.trueBlackTheme ? (GlobalUserPreferences.originalColors ? R.style.Theme_Mastodon_AutoLightDark_TrueBlack_Original : R.style.Theme_Mastodon_Dark_TrueBlack) : (GlobalUserPreferences.originalColors ? R.style.Theme_Mastodon_Dark_Original : R.style.Theme_Mastodon_Dark);
}); });
} }
public static boolean isDarkTheme(){ public static boolean isDarkTheme(){
if(GlobalUserPreferences.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 (MastodonApp.context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)==Configuration.UI_MODE_NIGHT_YES;

View File

@@ -30,6 +30,19 @@
<color name="primary_700">#d92aad</color> <color name="primary_700">#d92aad</color>
<color name="primary_800">#ae218a</color> <color name="primary_800">#ae218a</color>
<color name="primary_900">#6d1556</color> <color name="primary_900">#6d1556</color>
<color name="original_primary_25">#fafaff</color>
<color name="original_primary_50">#f4f3ff</color>
<color name="original_primary_100">#ebebff</color>
<color name="original_primary_200">#d7d7ff</color>
<color name="original_primary_300">#c2c2ff</color>
<color name="original_primary_400">#9999ff</color>
<color name="original_primary_500">#6364ff</color>
<color name="original_primary_600">#562cfc</color>
<color name="original_primary_700">#431cbb</color>
<color name="original_primary_800">#2f0c7a</color>
<color name="original_primary_900">#17063b</color>
<color name="error_25">#FFFBFA</color> <color name="error_25">#FFFBFA</color>
<color name="error_50">#FEF3F2</color> <color name="error_50">#FEF3F2</color>
<color name="error_100">#FEE4E2</color> <color name="error_100">#FEE4E2</color>

View File

@@ -427,5 +427,6 @@
<string name="your_favorites">Your Favorites</string> <string name="your_favorites">Your Favorites</string>
<string name="settings_always_reveal_content_warnings">Always reveal content warnings</string> <string name="settings_always_reveal_content_warnings">Always reveal content warnings</string>
<string name="disable_marquee">Disable scrolling text in title bars</string> <string name="disable_marquee">Disable scrolling text in title bars</string>
<string name="enable_mastodon_original_colors">Enable mastodon original colors</string>
<string name="settings_contribute_fork">Contribute to Megalodon</string> <string name="settings_contribute_fork">Contribute to Megalodon</string>
</resources> </resources>

View File

@@ -113,6 +113,31 @@
<style name="Theme.Mastodon.AutoLightDark" parent="Theme.Mastodon.Light"/> <style name="Theme.Mastodon.AutoLightDark" parent="Theme.Mastodon.Light"/>
<style name="Theme.Mastodon.AutoLightDark.TrueBlack" parent="Theme.Mastodon.Light"/> <style name="Theme.Mastodon.AutoLightDark.TrueBlack" parent="Theme.Mastodon.Light"/>
<style name="Theme.Mastodon.Dark.Original" parent="Theme.Mastodon.Dark">
<item name="android:colorAccent">@color/original_primary_400</item>
<item name="colorPollMostVoted">@color/original_primary_700</item>
<item name="colorAccentLight">@color/original_primary_600</item>
<item name="colorAccentLightest">@color/original_primary_800</item>
</style>
<style name="Theme.Mastodon.Dark.TrueBlack.Original" parent="Theme.Mastodon.Dark.TrueBlack">
<item name="android:colorAccent">@color/original_primary_400</item>
<item name="colorPollMostVoted">@color/original_primary_700</item>
<item name="colorAccentLight">@color/original_primary_600</item>
<item name="colorAccentLightest">@color/original_primary_800</item>
</style>
<style name="Theme.Mastodon.Light.Original" parent="Theme.Mastodon.Light">
<item name="android:colorAccent">@color/original_primary_400</item>
<item name="colorPollMostVoted">@color/original_primary_700</item>
<item name="colorAccentLight">@color/original_primary_600</item>
<item name="colorAccentLightest">@color/original_primary_800</item>
</style>
<style name="Theme.Mastodon.AutoLightDark.Original" parent="Theme.Mastodon.Light.Original"/>
<style name="Theme.Mastodon.AutoLightDark.TrueBlack.Original" parent="Theme.Mastodon.Dark.TrueBlack.Original"/>
<style name="Theme.Mastodon.Toolbar" parent="android:ThemeOverlay.Material.ActionBar"> <style name="Theme.Mastodon.Toolbar" parent="android:ThemeOverlay.Material.ActionBar">
<item name="android:colorPrimary">@color/gray_50</item> <item name="android:colorPrimary">@color/gray_50</item>
<item name="android:textColorPrimary">@color/gray_800</item> <item name="android:textColorPrimary">@color/gray_800</item>