Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Proper implementation of the color picker #124

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ff21541
Adding mastodon original colors toggle. Partially fixing #90
LucasGGamerM Nov 28, 2022
bc2ac4e
Fixed a few bugs from the earlier commit.
LucasGGamerM Nov 28, 2022
f2c47a1
Fixing another bug I found.
LucasGGamerM Nov 29, 2022
d096bef
Fixing the fix of the bug I found.
LucasGGamerM Nov 29, 2022
9179d21
Fully fixed now, it should be ready to release.
LucasGGamerM Nov 29, 2022
dad3b8c
Proper implementation on the color picker.
LucasGGamerM Dec 1, 2022
6a674d7
Polishes
LucasGGamerM Dec 1, 2022
8fa5824
Disabling the icons for the color picker menu
LucasGGamerM Dec 2, 2022
1747ff9
Adding a green theme
LucasGGamerM Dec 2, 2022
19238c3
Making the green theme more readable
LucasGGamerM Dec 3, 2022
77669ce
More polishes over the green theme
LucasGGamerM Dec 3, 2022
bad44b1
Adding blue theme and refactoring styles.xml
LucasGGamerM Dec 3, 2022
b1fda17
Make badged settings icon follow accent colors
LucasGGamerM Dec 3, 2022
e63b9d0
Adding an icon to the color picker setting
LucasGGamerM Dec 4, 2022
8d63be5
Fix readability issue on the light blue theme
LucasGGamerM Dec 4, 2022
29abf70
Adding orange theme, tweaking the blue and green theme
LucasGGamerM Dec 4, 2022
b617868
Adding yellow theme
LucasGGamerM Dec 4, 2022
4e39bb3
Making it so that the fab follows the theme
LucasGGamerM Dec 4, 2022
3ebc972
Fixing the TrueBlack themes for everything
LucasGGamerM Dec 4, 2022
606cd74
Make it so that the publish button also follows the theme
LucasGGamerM Dec 4, 2022
de5a911
Fixing weird bug with the buttons
LucasGGamerM Dec 5, 2022
c8e38b1
Fixing weird bug with the buttons for the second time
LucasGGamerM Dec 5, 2022
004c414
Editing some drawable files to make them also follow the theme
LucasGGamerM Dec 5, 2022
27afba1
Making it so that the boost icon is also following the theme when cli…
LucasGGamerM Dec 5, 2022
1077971
Make follow requests icon badge follow the color scheme and also make…
LucasGGamerM Dec 5, 2022
48e7536
Merge branch 'main' into color-themes
sk22 Dec 7, 2022
4d5cbd1
use fluent icon
sk22 Dec 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -35,6 +36,7 @@ public static void load(){
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(){
Expand All @@ -50,12 +52,23 @@ public static void save(){
.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
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void onCreate(Bundle savedInstanceState){
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->{
Expand Down Expand Up @@ -235,6 +236,12 @@ private void onThemePreferenceClick(GlobalUserPreferences.ThemePreference theme)
restartActivityToApplyNewTheme();
}

private void onColorPreferenceClick(GlobalUserPreferences.ColorPreference color){
GlobalUserPreferences.color=color;
GlobalUserPreferences.save();
restartActivityToApplyNewTheme();
}

private void onTrueBlackThemeChanged(SwitchItem item){
GlobalUserPreferences.trueBlackTheme=item.checked;
GlobalUserPreferences.save();
Expand Down Expand Up @@ -438,6 +445,13 @@ public int getViewType(){
}
}

public class ColorPicker extends Item{
@Override
public int getViewType(){
return 8;
}
}

private static class ThemeItem extends Item{

@Override
Expand Down Expand Up @@ -522,6 +536,7 @@ public BindableViewHolder<Item> onCreateViewHolder(@NonNull ViewGroup parent, in
case 5 -> new HeaderViewHolder(true);
case 6 -> new FooterViewHolder();
case 7 -> new UpdateViewHolder();
case 8 -> new ColorPickerViewHolder();
default -> throw new IllegalStateException("Unexpected value: "+viewType);
};
}
Expand Down Expand Up @@ -650,6 +665,68 @@ public void setChecked(boolean checked){
}
}
}
private class ColorPickerViewHolder extends BindableViewHolder<ColorPicker>{
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<NotificationPolicyItem>{
private final Button button;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -655,13 +656,71 @@ public static void enablePopupMenuIcons(Context context, PopupMenu menu){
}

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;
Expand Down
2 changes: 1 addition & 1 deletion mastodon/src/main/res/color/boost_icon.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/boost_selected" android:state_selected="true"/>
<item android:color="?android:colorAccent" android:state_selected="true"/>
<item android:color="?android:textColorSecondary" android:state_enabled="true"/>
<item android:color="?android:textColorSecondary" android:alpha="0.3"/>
</selector>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/gray_800" android:state_enabled="true"/>
<item android:color="@color/gray_300"/>
<item android:color="?android:colorPrimary" android:state_enabled="true"/>
<item android:color="?colorPollVoted"/>
</selector>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/gray_100" android:state_enabled="true"/>
<item android:color="@color/gray_500"/>
<item android:color="?colorSecondary" android:state_enabled="true"/>
<item android:color="?colorPollVoted"/>
</selector>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/gray_600" android:state_enabled="true"/>
<item android:color="@color/gray_300"/>
<item android:color="?colorPollVoted" android:state_enabled="true"/>
<item android:color="?colorSearchHint"/>
</selector>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/gray_50" android:state_enabled="true"/>
<item android:color="@color/gray_400"/>
<item android:color="?colorSecondary" android:state_enabled="true"/>
<item android:color="?colorTabInactive"/>
</selector>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/gray_800" android:state_enabled="true"/>
<item android:color="@color/gray_400"/>
<item android:color="?colorButtonText" android:state_enabled="true"/>
<item android:color="?colorTabInactive"/>
</selector>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/gray_800" android:state_enabled="true"/>
<item android:color="@color/gray_400"/>
<item android:color="?android:colorPrimary" android:state_enabled="true"/>
<item android:color="?colorTabInactive"/>
</selector>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/gray_50"/>
<item android:color="?colorSecondary"/>
</selector>
2 changes: 1 addition & 1 deletion mastodon/src/main/res/drawable/bg_upload_progress.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/highlight_over_dark">
<item>
<shape android:shape="oval">
<solid android:color="@color/gray_600"/>
<solid android:color="?colorSearchHint"/>
</shape>
</item>
</ripple>
3 changes: 3 additions & 0 deletions mastodon/src/main/res/drawable/ic_fluent_color_24_regular.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
<path android:pathData="M3.839 5.858c2.94-3.916 9.03-5.055 13.364-2.36 4.28 2.66 5.854 7.777 4.1 12.577-1.655 4.533-6.016 6.328-9.159 4.048-1.177-0.854-1.634-1.925-1.854-3.664l-0.106-0.987-0.045-0.398c-0.123-0.934-0.311-1.352-0.705-1.572C8.9 13.204 8.542 13.197 7.84 13.47l-0.351 0.146-0.179 0.078c-1.014 0.44-1.688 0.595-2.541 0.416l-0.2-0.047-0.164-0.047c-2.79-0.865-3.203-4.648-0.565-8.158zm0.984 6.716l0.123 0.037 0.134 0.03c0.439 0.087 0.814 0.015 1.437-0.242l0.602-0.257c1.202-0.493 1.985-0.54 3.046 0.05 0.917 0.512 1.275 1.298 1.457 2.66l0.053 0.459 0.055 0.532 0.047 0.422c0.172 1.361 0.485 2.09 1.248 2.644 2.275 1.65 5.534 0.309 6.87-3.349 1.516-4.152 0.174-8.514-3.484-10.789-3.675-2.284-8.899-1.306-11.373 1.987-2.075 2.763-1.82 5.28-0.215 5.816zm11.225-1.994c-0.18-0.667 0.217-1.353 0.883-1.531 0.667-0.179 1.353 0.217 1.531 0.884 0.18 0.667-0.217 1.352-0.884 1.53-0.666 0.18-1.352-0.216-1.53-0.883zm0.494 3.488c-0.179-0.666 0.217-1.352 0.884-1.53 0.667-0.18 1.352 0.216 1.531 0.883 0.179 0.667-0.217 1.353-0.884 1.531-0.667 0.179-1.352-0.217-1.53-0.884zM14.07 7.577c-0.179-0.667 0.217-1.352 0.884-1.53 0.667-0.18 1.352 0.216 1.53 0.883 0.18 0.667-0.216 1.352-0.883 1.53-0.667 0.18-1.352-0.216-1.53-0.883zm-0.028 8.998c-0.18-0.666 0.217-1.352 0.883-1.53 0.667-0.18 1.353 0.216 1.531 0.883 0.18 0.667-0.217 1.353-0.883 1.531-0.667 0.179-1.353-0.217-1.531-0.884zm-3.497-9.97c-0.179-0.666 0.217-1.352 0.883-1.53 0.667-0.18 1.353 0.217 1.532 0.883 0.178 0.667-0.218 1.353-0.884 1.531-0.667 0.179-1.353-0.217-1.531-0.884z" android:fillColor="@color/fluent_default_icon_tint"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<item android:width="14dp" android:height="14dp" android:gravity="top|right">
<shape android:shape="oval">
<stroke android:color="?android:colorPrimary" android:width="2dp"/>
<solid android:color="@color/primary_600"/>
<solid android:color="?android:colorAccent"/>
</shape>
</item>
</layer-list>
2 changes: 1 addition & 1 deletion mastodon/src/main/res/drawable/ic_settings_24_badged.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<item android:width="14dp" android:height="14dp" android:gravity="top|right">
<shape android:shape="oval">
<stroke android:color="?android:colorPrimary" android:width="2dp"/>
<solid android:color="@color/primary_600"/>
<solid android:color="?android:colorAccent"/>
</shape>
</item>
</layer-list>
2 changes: 1 addition & 1 deletion mastodon/src/main/res/drawable/play_button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:color="@color/gray_50" android:width="4dp"/>
<stroke android:color="?colorSecondary" android:width="4dp"/>
<solid android:color="#80000000"/>
<size android:width="52dp" android:height="52dp"/>
</shape>
Expand Down
Loading