mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-27 19:35:10 +01:00
Added color to answers
This commit is contained in:
@@ -22,6 +22,7 @@ package eu.faircode.email;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableStringBuilder;
|
||||
@@ -84,6 +85,7 @@ public class EntityAnswer implements Serializable {
|
||||
public Boolean hide;
|
||||
@NonNull
|
||||
public Boolean external;
|
||||
public Integer color;
|
||||
@NonNull
|
||||
public String text;
|
||||
@NonNull
|
||||
@@ -164,6 +166,8 @@ public class EntityAnswer implements Serializable {
|
||||
static void fillMenu(Menu main, boolean compose, List<EntityAnswer> answers, Context context) {
|
||||
boolean grouped = BuildConfig.DEBUG;
|
||||
|
||||
int iconSize = context.getResources().getDimensionPixelSize(R.dimen.menu_item_icon_size);
|
||||
|
||||
List<EntityAnswer> favorites = new ArrayList<>();
|
||||
List<String> groups = new ArrayList<>();
|
||||
for (EntityAnswer answer : answers)
|
||||
@@ -206,6 +210,16 @@ public class EntityAnswer implements Serializable {
|
||||
order++;
|
||||
|
||||
SpannableStringBuilder name = new SpannableStringBuilder(answer.name);
|
||||
|
||||
if (answer.color != null) {
|
||||
Drawable d = new ColorDrawable(answer.color);
|
||||
d.setBounds(0, 0, iconSize / 4, iconSize);
|
||||
|
||||
ImageSpan imageSpan = new CenteredImageSpan(d);
|
||||
name.insert(0, "\uFFFC\u2002"); // object replacement character, en space
|
||||
name.setSpan(imageSpan, 0, 1, 0);
|
||||
}
|
||||
|
||||
if (grouped && answer.applied > 0) {
|
||||
name.append(" (").append(NF.format(answer.applied)).append(")");
|
||||
name.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL),
|
||||
@@ -282,6 +296,7 @@ public class EntityAnswer implements Serializable {
|
||||
}
|
||||
|
||||
Drawable icon = context.getResources().getDrawable(R.drawable.twotone_star_24);
|
||||
icon.setBounds(0, 0, iconSize, iconSize);
|
||||
icon = icon.getConstantState().newDrawable().mutate();
|
||||
int color = Helper.resolveColor(context, R.attr.colorAccent);
|
||||
icon.setTint(color);
|
||||
@@ -289,8 +304,6 @@ public class EntityAnswer implements Serializable {
|
||||
for (EntityAnswer answer : favorites) {
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(answer.name);
|
||||
|
||||
int iconSize = context.getResources().getDimensionPixelSize(R.dimen.menu_item_icon_size);
|
||||
icon.setBounds(0, 0, iconSize, iconSize);
|
||||
ImageSpan imageSpan = new CenteredImageSpan(icon);
|
||||
ssb.insert(0, "\uFFFC\u2002"); // object replacement character, en space
|
||||
ssb.setSpan(imageSpan, 0, 1, 0);
|
||||
@@ -313,6 +326,7 @@ public class EntityAnswer implements Serializable {
|
||||
json.put("favorite", favorite);
|
||||
json.put("hide", hide);
|
||||
json.put("external", external);
|
||||
json.put("color", color);
|
||||
json.put("text", text);
|
||||
json.put("applied", applied);
|
||||
json.put("last_applied", last_applied);
|
||||
@@ -331,6 +345,8 @@ public class EntityAnswer implements Serializable {
|
||||
answer.favorite = json.optBoolean("favorite");
|
||||
answer.hide = json.optBoolean("hide");
|
||||
answer.external = json.optBoolean("external");
|
||||
if (json.has("color") && !json.isNull("color"))
|
||||
answer.color = json.getInt("color");
|
||||
answer.text = json.getString("text");
|
||||
answer.applied = json.optInt("applied", 0);
|
||||
if (json.has("last_applied") && !json.isNull("last_applied"))
|
||||
@@ -350,6 +366,7 @@ public class EntityAnswer implements Serializable {
|
||||
this.hide.equals(other.hide) &&
|
||||
this.external.equals(other.external) &&
|
||||
this.text.equals(other.text) &&
|
||||
Objects.equals(this.color, other.color) &&
|
||||
this.applied.equals(other.applied) &&
|
||||
Objects.equals(this.last_applied, other.last_applied));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user