mirror of https://github.com/M66B/FairEmail.git
Added color to answers
This commit is contained in:
parent
bcfa1c37a2
commit
84f56a589d
File diff suppressed because it is too large
Load Diff
|
@ -21,6 +21,7 @@ package eu.faircode.email;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableString;
|
||||
|
@ -70,6 +71,7 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
|
|||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
private View view;
|
||||
private View vwColor;
|
||||
private TextView tvName;
|
||||
private TextView tvGroup;
|
||||
private ImageView ivExternal;
|
||||
|
@ -85,6 +87,7 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
|
|||
super(itemView);
|
||||
|
||||
view = itemView.findViewById(R.id.clItem);
|
||||
vwColor = itemView.findViewById(R.id.vwColor);
|
||||
tvName = itemView.findViewById(R.id.tvName);
|
||||
tvGroup = itemView.findViewById(R.id.tvGroup);
|
||||
ivExternal = itemView.findViewById(R.id.ivExternal);
|
||||
|
@ -107,6 +110,7 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
|
|||
|
||||
private void bindTo(EntityAnswer answer) {
|
||||
view.setAlpha(answer.hide ? Helper.LOW_LIGHT : 1.0f);
|
||||
vwColor.setBackgroundColor(answer.color == null ? Color.TRANSPARENT : answer.color);
|
||||
tvName.setText(answer.name);
|
||||
tvGroup.setText(answer.group);
|
||||
tvGroup.setVisibility(TextUtils.isEmpty(answer.group) ? View.GONE : View.VISIBLE);
|
||||
|
|
|
@ -71,7 +71,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
|
|||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 221,
|
||||
version = 222,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
|
@ -2245,6 +2245,12 @@ public abstract class DB extends RoomDatabase {
|
|||
logMigration(startVersion, endVersion);
|
||||
db.execSQL("ALTER TABLE `message` ADD COLUMN `sensitivity` INTEGER");
|
||||
}
|
||||
}).addMigrations(new Migration(221, 222) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
logMigration(startVersion, endVersion);
|
||||
db.execSQL("ALTER TABLE `answer` ADD COLUMN `color` INTEGER");
|
||||
}
|
||||
}).addMigrations(new Migration(998, 999) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.content.ClipboardManager;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
@ -64,6 +65,7 @@ public class FragmentAnswer extends FragmentBase {
|
|||
private CheckBox cbFavorite;
|
||||
private CheckBox cbHide;
|
||||
private CheckBox cbExternal;
|
||||
private ViewButtonColor btnColor;
|
||||
private EditTextCompose etText;
|
||||
private BottomNavigationView style_bar;
|
||||
private BottomNavigationView bottom_navigation;
|
||||
|
@ -73,9 +75,10 @@ public class FragmentAnswer extends FragmentBase {
|
|||
private long id = -1;
|
||||
private long copy = -1;
|
||||
|
||||
private static final int REQUEST_IMAGE = 1;
|
||||
private static final int REQUEST_LINK = 2;
|
||||
private final static int REQUEST_DELETE = 3;
|
||||
private static final int REQUEST_COLOR = 1;
|
||||
private static final int REQUEST_IMAGE = 2;
|
||||
private static final int REQUEST_LINK = 3;
|
||||
private final static int REQUEST_DELETE = 5;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -114,6 +117,7 @@ public class FragmentAnswer extends FragmentBase {
|
|||
cbFavorite = view.findViewById(R.id.cbFavorite);
|
||||
cbHide = view.findViewById(R.id.cbHide);
|
||||
cbExternal = view.findViewById(R.id.cbExternal);
|
||||
btnColor = view.findViewById(R.id.btnColor);
|
||||
etText = view.findViewById(R.id.etText);
|
||||
|
||||
style_bar = view.findViewById(R.id.style_bar);
|
||||
|
@ -122,6 +126,21 @@ public class FragmentAnswer extends FragmentBase {
|
|||
pbWait = view.findViewById(R.id.pbWait);
|
||||
grpReady = view.findViewById(R.id.grpReady);
|
||||
|
||||
btnColor.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("color", btnColor.getColor());
|
||||
args.putString("title", getString(R.string.title_color));
|
||||
args.putBoolean("reset", true);
|
||||
|
||||
FragmentDialogColor fragment = new FragmentDialogColor();
|
||||
fragment.setArguments(args);
|
||||
fragment.setTargetFragment(FragmentAnswer.this, REQUEST_COLOR);
|
||||
fragment.show(getParentFragmentManager(), "account:color");
|
||||
}
|
||||
});
|
||||
|
||||
etText.setTypeface(StyleHelper.getTypeface(compose_font, context));
|
||||
|
||||
float textSize = Helper.getTextSize(context, zoom);
|
||||
|
@ -218,6 +237,7 @@ public class FragmentAnswer extends FragmentBase {
|
|||
cbFavorite.setChecked(answer == null ? false : answer.favorite);
|
||||
cbHide.setChecked(answer == null ? false : answer.hide);
|
||||
cbExternal.setChecked(answer == null ? false : answer.external);
|
||||
btnColor.setColor(answer == null ? null : answer.color);
|
||||
|
||||
String html = (answer == null ? a.getString("html") : answer.text);
|
||||
if (html == null)
|
||||
|
@ -342,6 +362,7 @@ public class FragmentAnswer extends FragmentBase {
|
|||
args.putBoolean("favorite", cbFavorite.isChecked());
|
||||
args.putBoolean("hide", cbHide.isChecked());
|
||||
args.putBoolean("external", cbExternal.isChecked());
|
||||
args.putInt("color", btnColor.getColor());
|
||||
args.putString("html", HtmlHelper.toHtml(etText.getText(), getContext()));
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
|
@ -365,12 +386,15 @@ public class FragmentAnswer extends FragmentBase {
|
|||
boolean favorite = args.getBoolean("favorite");
|
||||
boolean hide = args.getBoolean("hide");
|
||||
boolean external = args.getBoolean("external");
|
||||
Integer color = args.getInt("color");
|
||||
String html = args.getString("html");
|
||||
|
||||
if (TextUtils.isEmpty(name))
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_no_name));
|
||||
if (TextUtils.isEmpty(group))
|
||||
group = null;
|
||||
if (color == Color.TRANSPARENT)
|
||||
color = null;
|
||||
|
||||
Document document = JsoupEx.parse(html);
|
||||
|
||||
|
@ -396,6 +420,7 @@ public class FragmentAnswer extends FragmentBase {
|
|||
answer.favorite = favorite;
|
||||
answer.hide = hide;
|
||||
answer.external = external;
|
||||
answer.color = color;
|
||||
answer.text = document.body().html();
|
||||
|
||||
if (id < 0)
|
||||
|
@ -433,6 +458,12 @@ public class FragmentAnswer extends FragmentBase {
|
|||
|
||||
try {
|
||||
switch (requestCode) {
|
||||
case REQUEST_COLOR:
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
Bundle args = data.getBundleExtra("args");
|
||||
btnColor.setColor(args.getInt("color"));
|
||||
}
|
||||
break;
|
||||
case REQUEST_IMAGE:
|
||||
if (resultCode == RESULT_OK && data != null)
|
||||
onImageSelected(data.getData());
|
||||
|
|
|
@ -102,6 +102,18 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/cbHide" />
|
||||
|
||||
<eu.faircode.email.ViewButtonColor
|
||||
android:id="@+id/btnColor"
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:paddingHorizontal="6dp"
|
||||
android:text="@string/title_select"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbExternal" />
|
||||
|
||||
<View
|
||||
android:id="@+id/vSeparator"
|
||||
android:layout_width="0dp"
|
||||
|
@ -110,7 +122,7 @@
|
|||
android:background="?attr/colorSeparator"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/cbExternal" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/btnColor" />
|
||||
|
||||
<eu.faircode.email.EditTextCompose
|
||||
android:id="@+id/etText"
|
||||
|
@ -133,7 +145,7 @@
|
|||
android:id="@+id/grpReady"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="etName,etGroup,cbStandard,cbReceipt,cbFavorite,cbHide,vSeparator,etText" />
|
||||
app:constraint_referenced_ids="etName,etGroup,cbStandard,cbReceipt,cbFavorite,cbHide,cbExternal,btnColor,vSeparator,etText" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</eu.faircode.email.ScrollViewEx>
|
||||
|
||||
|
|
|
@ -14,42 +14,54 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:background="?attr/activatableItemBackground"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
android:padding="6dp">
|
||||
android:paddingEnd="6dp">
|
||||
|
||||
<eu.faircode.email.ViewStripe
|
||||
android:id="@+id/vwColor"
|
||||
android:layout_width="6dp"
|
||||
android:layout_height="0dp"
|
||||
android:background="?attr/colorAccent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:minHeight="24dp"
|
||||
android:text="Name"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toStartOf="@+id/ivExternal"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/vwColor"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvGroup"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="Group"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toStartOf="@+id/ivExternal"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/vwColor"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvName" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvLastApplied"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:text="Jan 1, 12:34"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toStartOf="@id/tvApplied"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/vwColor"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvGroup" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
|
|
Loading…
Reference in New Issue