Manage custom colors

This commit is contained in:
Thomas 2025-09-19 08:21:35 +02:00
parent 9ed740a3a2
commit a42cbf8afc
4 changed files with 57 additions and 36 deletions

View file

@ -205,44 +205,28 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean colorizeVisibility = sharedpreferences.getBoolean(context.getString(R.string.SET_COLORIZE_FOR_VISIBILITY), true);
if(colorizeVisibility) {
int color_public = sharedpreferences.getInt(context.getString(R.string.SET_COLOR_VISIBILITY_PUBLIC), -1);
int color_unlisted = sharedpreferences.getInt(context.getString(R.string.SET_COLOR_VISIBILITY_UNLISTED), -1);
int color_private = sharedpreferences.getInt(context.getString(R.string.SET_COLOR_VISIBILITY_PRIVATE), -1);
int color_direct = sharedpreferences.getInt(context.getString(R.string.SET_COLOR_VISIBILITY_DIRECT), -1);
int color_public = sharedpreferences.getInt(context.getString(R.string.SET_COLOR_VISIBILITY_PUBLIC), 0xff388E3C);
int color_unlisted = sharedpreferences.getInt(context.getString(R.string.SET_COLOR_VISIBILITY_UNLISTED), 0xff0288D1);
int color_private = sharedpreferences.getInt(context.getString(R.string.SET_COLOR_VISIBILITY_PRIVATE), 0xffFBC02D);
int color_direct = sharedpreferences.getInt(context.getString(R.string.SET_COLOR_VISIBILITY_DIRECT), 0xffE64A19);
Drawable mdrawable = holder.binding.content.getBackground();
if(visibility.equalsIgnoreCase("public") ) {
if(color_public != -1) {
mdrawable.setColorFilter(color_public, PorterDuff.Mode.SRC_ATOP);
holder.binding.content.setBackgroundDrawable(mdrawable);
holder.binding.buttonVisibility.setBackgroundTintList(ColorStateList.valueOf(color_public));
} else {
}
mdrawable.setColorFilter(color_public, PorterDuff.Mode.SRC_ATOP);
holder.binding.content.setBackgroundDrawable(mdrawable);
holder.binding.buttonVisibility.setBackgroundTintList(ColorStateList.valueOf(color_public));
} else if(visibility.equalsIgnoreCase("unlisted") ) {
if(color_unlisted != -1) {
mdrawable.setColorFilter(color_unlisted, PorterDuff.Mode.SRC_ATOP);
holder.binding.content.setBackgroundDrawable(mdrawable);
holder.binding.buttonVisibility.setBackgroundTintList(ColorStateList.valueOf(color_unlisted));
} else {
}
mdrawable.setColorFilter(color_unlisted, PorterDuff.Mode.SRC_ATOP);
holder.binding.content.setBackgroundDrawable(mdrawable);
holder.binding.buttonVisibility.setBackgroundTintList(ColorStateList.valueOf(color_unlisted));
} else if(visibility.equalsIgnoreCase("private") ) {
if(color_private != -1) {
mdrawable.setColorFilter(color_private, PorterDuff.Mode.SRC_ATOP);
holder.binding.content.setBackgroundDrawable(mdrawable);
holder.binding.buttonVisibility.setBackgroundTintList(ColorStateList.valueOf(color_private));
} else {
}
mdrawable.setColorFilter(color_private, PorterDuff.Mode.SRC_ATOP);
holder.binding.content.setBackgroundDrawable(mdrawable);
holder.binding.buttonVisibility.setBackgroundTintList(ColorStateList.valueOf(color_private));
} else if(visibility.equalsIgnoreCase("direct") ) {
if(color_direct != -1) {
mdrawable.setColorFilter(color_direct, PorterDuff.Mode.SRC_ATOP);
holder.binding.content.setBackgroundDrawable(mdrawable);
holder.binding.buttonVisibility.setBackgroundTintList(ColorStateList.valueOf(color_direct));
} else {
}
mdrawable.setColorFilter(color_direct, PorterDuff.Mode.SRC_ATOP);
holder.binding.content.setBackgroundDrawable(mdrawable);
holder.binding.buttonVisibility.setBackgroundTintList(ColorStateList.valueOf(color_direct));
}
}
}

View file

@ -18,8 +18,12 @@ package app.fedilab.android.mastodon.ui.fragment.settings;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import app.fedilab.android.R;
public class FragmentCustomVisibilityColorsSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -31,6 +35,27 @@ public class FragmentCustomVisibilityColorsSettings extends PreferenceFragmentCo
}
private void createPref() {
Preference SET_RESET_CUSTOM_COLOR_VISIBILITY = findPreference(getString(R.string.SET_RESET_CUSTOM_COLOR_VISIBILITY));
if (SET_RESET_CUSTOM_COLOR_VISIBILITY != null) {
SET_RESET_CUSTOM_COLOR_VISIBILITY.setOnPreferenceClickListener(preference -> {
AlertDialog.Builder resetConfirm = new MaterialAlertDialogBuilder(requireActivity());
resetConfirm.setMessage(getString(R.string.reset_color));
resetConfirm.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss());
resetConfirm.setPositiveButton(R.string.reset, (dialog, which) -> {
SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
if (sharedPreferences != null) {
sharedPreferences.edit().remove(getString(R.string.SET_COLOR_VISIBILITY_PUBLIC)).apply();
sharedPreferences.edit().remove(getString(R.string.SET_COLOR_VISIBILITY_UNLISTED)).apply();
sharedPreferences.edit().remove(getString(R.string.SET_COLOR_VISIBILITY_PRIVATE)).apply();
sharedPreferences.edit().remove(getString(R.string.SET_COLOR_VISIBILITY_DIRECT)).apply();
}
dialog.dismiss();
});
resetConfirm.show();
return true;
});
}
}
@Override

View file

@ -1220,10 +1220,11 @@
<string name="SET_LIGHT_LINK" translatable="false">SET_LIGHT_LINK</string>
<string name="SET_LIGHT_ICON" translatable="false">SET_LIGHT_ICON</string>
<string name="SET_COLOR_VISIBILITY_PUBLIC">SET_COLOR_VISIBILITY_PUBLIC</string>
<string name="SET_COLOR_VISIBILITY_UNLISTED">SET_COLOR_VISIBILITY_UNLISTED</string>
<string name="SET_COLOR_VISIBILITY_PRIVATE">SET_COLOR_VISIBILITY_PRIVATE</string>
<string name="SET_COLOR_VISIBILITY_DIRECT">SET_COLOR_VISIBILITY_DIRECT</string>
<string name="SET_COLOR_VISIBILITY_PUBLIC" translatable="false">SET_COLOR_VISIBILITY_PUBLIC</string>
<string name="SET_COLOR_VISIBILITY_UNLISTED" translatable="false">SET_COLOR_VISIBILITY_UNLISTED</string>
<string name="SET_COLOR_VISIBILITY_PRIVATE" translatable="false">SET_COLOR_VISIBILITY_PRIVATE</string>
<string name="SET_COLOR_VISIBILITY_DIRECT" translatable="false">SET_COLOR_VISIBILITY_DIRECT</string>
<string name="SET_RESET_CUSTOM_COLOR_VISIBILITY" translatable="false">SET_RESET_CUSTOM_COLOR_VISIBILITY</string>
<string name="SET_DEFAULT_THEME" translatable="false">SYSTEM</string>
<string name="SET_AUTO_PLAY_GIG_MEDIA" translatable="false">SET_AUTO_PLAY_GIG_MEDIA</string>

View file

@ -5,27 +5,38 @@
android:layout_height="match_parent">
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat
android:defaultValue="0xff388E3C"
android:key="@string/SET_COLOR_VISIBILITY_PUBLIC"
app:iconSpaceReserved="false"
app:summary="@string/visibility_color_public"
app:title="@string/v_public" />
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat
android:defaultValue="0xff0288D1"
android:key="@string/SET_COLOR_VISIBILITY_UNLISTED"
app:iconSpaceReserved="false"
app:summary="@string/visibility_color_unlisted"
app:title="@string/v_unlisted" />
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat
android:defaultValue="0xffFBC02D"
android:key="@string/SET_COLOR_VISIBILITY_PRIVATE"
app:iconSpaceReserved="false"
app:summary="@string/visibility_color_private"
app:title="@string/v_private" />
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat
android:defaultValue="0xffE64A19"
android:key="@string/SET_COLOR_VISIBILITY_DIRECT"
app:iconSpaceReserved="false"
app:summary="@string/visibility_color_direct"
app:title="@string/v_direct" />
<Preference
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:title="@string/reset_color"
app:iconSpaceReserved="false"
app:key="@string/SET_RESET_CUSTOM_COLOR_VISIBILITY" />
</androidx.preference.PreferenceScreen>