mirror of https://github.com/M66B/FairEmail.git
Experiment: keyword buttons
This commit is contained in:
parent
24041b0988
commit
e4152a6d7a
|
@ -467,6 +467,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
private ImageButton ibMore;
|
||||
private ImageButton ibTools;
|
||||
private View vwEmpty;
|
||||
private Flow buttons;
|
||||
private TextView tvReformatted;
|
||||
private TextView tvDecrypt;
|
||||
private TextView tvSignedData;
|
||||
|
@ -885,6 +886,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
ibMore = vsBody.findViewById(R.id.ibMore);
|
||||
ibTools = vsBody.findViewById(R.id.ibTools);
|
||||
vwEmpty = vsBody.findViewById(R.id.vwEmpty);
|
||||
buttons = vsBody.findViewById(R.id.buttons);
|
||||
tvReformatted = vsBody.findViewById(R.id.tvReformatted);
|
||||
tvDecrypt = vsBody.findViewById(R.id.tvDecrypt);
|
||||
tvSignedData = vsBody.findViewById(R.id.tvSignedData);
|
||||
|
@ -1708,6 +1710,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
ibMore.setVisibility(View.GONE);
|
||||
ibTools.setVisibility(View.GONE);
|
||||
vwEmpty.setVisibility(View.GONE);
|
||||
clearButtons();
|
||||
tvReformatted.setVisibility(View.GONE);
|
||||
tvDecrypt.setVisibility(View.GONE);
|
||||
tvSignedData.setVisibility(View.GONE);
|
||||
|
@ -1730,6 +1733,26 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
ibStoreMedia.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void clearButtons() {
|
||||
ConstraintLayout cl = (ConstraintLayout) buttons.getParent();
|
||||
for (int id : buttons.getReferencedIds()) {
|
||||
View v = cl.findViewById(id);
|
||||
cl.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
buttons.removeView(v);
|
||||
cl.removeView(v);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
// https://github.com/androidx/constraintlayout/issues/430
|
||||
// v.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearActions() {
|
||||
ConstraintLayout cl = (ConstraintLayout) flow.getParent();
|
||||
for (int id : flow.getReferencedIds()) {
|
||||
|
@ -1968,6 +1991,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
ibMore.setVisibility(View.GONE);
|
||||
ibTools.setVisibility(View.GONE);
|
||||
vwEmpty.setVisibility(View.GONE);
|
||||
clearButtons();
|
||||
tvReformatted.setVisibility(View.GONE);
|
||||
tvDecrypt.setVisibility(View.GONE);
|
||||
tvSignedData.setVisibility(View.GONE);
|
||||
|
@ -2215,6 +2239,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
ibTools.setVisibility(outbox ? View.GONE : View.VISIBLE);
|
||||
vwEmpty.setVisibility(outbox ? View.GONE : View.VISIBLE);
|
||||
|
||||
if (tools)
|
||||
bindButtons(message);
|
||||
else
|
||||
clearButtons();
|
||||
|
||||
if (bind)
|
||||
bindBody(message, scroll);
|
||||
else
|
||||
|
@ -2228,6 +2257,77 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
}.setLog(false).execute(context, owner, sargs, "message:tools");
|
||||
}
|
||||
|
||||
private void bindButtons(TupleMessageEx message) {
|
||||
String keywords = prefs.getString("global_keywords", null);
|
||||
if (keywords == null)
|
||||
return;
|
||||
|
||||
int dp3 = Helper.dp2pixels(context, 3);
|
||||
Drawable on = ContextCompat.getDrawable(context, R.drawable.twotone_check_12);
|
||||
Drawable off = ContextCompat.getDrawable(context, R.drawable.twotone_close_12);
|
||||
on.setBounds(0, 0, on.getIntrinsicWidth(), on.getIntrinsicHeight());
|
||||
off.setBounds(0, 0, off.getIntrinsicWidth(), off.getIntrinsicHeight());
|
||||
|
||||
List<String> selected = Arrays.asList(message.keywords);
|
||||
for (String keyword : keywords.split(" ")) {
|
||||
boolean set = selected.contains(keyword);
|
||||
String title = prefs.getString("kwtitle." + keyword, keyword);
|
||||
String c = "kwcolor." + keyword;
|
||||
Integer color = (prefs.contains(c) ? prefs.getInt(c, Color.GRAY) : null);
|
||||
|
||||
Button button = new Button(context, null, android.R.attr.buttonStyleSmall);
|
||||
button.setId(View.generateViewId());
|
||||
button.setText(title);
|
||||
button.setCompoundDrawablePadding(dp3);
|
||||
button.setCompoundDrawablesRelative(null, null, set ? off : on, null);
|
||||
if (color != null)
|
||||
button.setBackgroundTintList(ColorStateList.valueOf(color));
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", message.id);
|
||||
args.putString("keyword", keyword);
|
||||
args.putBoolean("set", !set);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
||||
long id = args.getLong("id");
|
||||
String keyword = args.getString("keyword");
|
||||
boolean set = args.getBoolean("set");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
EntityMessage message = db.message().getMessage(id);
|
||||
if (message == null)
|
||||
return null;
|
||||
|
||||
EntityOperation.queue(context, message, EntityOperation.KEYWORD, keyword, set);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
|
||||
}
|
||||
}.execute(context, owner, args, "toggle:keyword");
|
||||
}
|
||||
});
|
||||
|
||||
((ConstraintLayout) buttons.getParent()).addView(button);
|
||||
buttons.addView(button);
|
||||
}
|
||||
}
|
||||
|
||||
private String formatAddresses(Address[] addresses, MessageHelper.AddressFormat format, int max) {
|
||||
List<Address> list = new ArrayList<>();
|
||||
if (addresses != null)
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="12dp"
|
||||
android:height="12dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12 19,6.41z"/>
|
||||
</vector>
|
|
@ -455,6 +455,19 @@
|
|||
app:tint="?attr/colorAccent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.constraintlayout.helper.widget.Flow
|
||||
android:id="@+id/buttons"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:flow_horizontalBias="0"
|
||||
app:flow_horizontalGap="6dp"
|
||||
app:flow_horizontalStyle="packed"
|
||||
app:flow_verticalGap="6dp"
|
||||
app:flow_wrapMode="chain"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/workaround" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvReformatted"
|
||||
android:layout_width="0dp"
|
||||
|
@ -465,7 +478,7 @@
|
|||
android:textStyle="italic"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/workaround" />
|
||||
app:layout_constraintTop_toBottomOf="@id/buttons" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDecrypt"
|
||||
|
|
Loading…
Reference in New Issue