Use folder color for favorite button text color

pull/213/head
M66B 2 years ago
parent 265fd1c4ab
commit 408bf0713c

@ -27,10 +27,14 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -404,12 +408,28 @@ public class FragmentDialogSelectFolder extends FragmentDialogBase {
tvNoFolder.setVisibility(View.VISIBLE); tvNoFolder.setVisibility(View.VISIBLE);
else { else {
if (data.favorites != null && data.favorites.size() > 0) { if (data.favorites != null && data.favorites.size() > 0) {
Integer textColor = null;
try {
TypedValue tv = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(android.R.attr.textAppearanceButton, tv, true);
int[] attr = new int[]{android.R.attr.textColor};
TypedArray ta = theme.obtainStyledAttributes(tv.resourceId, attr);
textColor = ta.getColor(0, Color.BLACK);
} catch (Throwable ex) {
Log.e(ex);
}
Button[] btn = new Button[]{btnFavorite1, btnFavorite2, btnFavorite3}; Button[] btn = new Button[]{btnFavorite1, btnFavorite2, btnFavorite3};
for (int i = 0; i < btn.length; i++) for (int i = 0; i < btn.length; i++)
if (i < data.favorites.size()) { if (i < data.favorites.size()) {
EntityFolder favorite = data.favorites.get(i); EntityFolder favorite = data.favorites.get(i);
btn[i].setTag(favorite.id); btn[i].setTag(favorite.id);
btn[i].setText(favorite.getDisplayName(context)); btn[i].setText(favorite.getDisplayName(context));
if (textColor != null)
btn[i].setTextColor(
favorite.color == null || !HtmlHelper.hasColor(favorite.color)
? textColor : favorite.color);
btn[i].setVisibility(View.VISIBLE); btn[i].setVisibility(View.VISIBLE);
} else } else
btn[i].setVisibility(View.INVISIBLE); btn[i].setVisibility(View.INVISIBLE);

@ -2134,7 +2134,7 @@ public class HtmlHelper {
return color; return color;
} }
private static boolean hasColor(int color) { static boolean hasColor(int color) {
int r = Color.red(color); int r = Color.red(color);
int g = Color.green(color); int g = Color.green(color);
int b = Color.blue(color); int b = Color.blue(color);

Loading…
Cancel
Save