From 22778ca685cd32a62d55921f59da27231ff50062 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 22 Mar 2022 11:19:31 +0100 Subject: [PATCH] Show rule target folder name --- .../java/eu/faircode/email/AdapterRule.java | 134 +++++++++++------- app/src/main/res/layout/item_rule.xml | 1 - 2 files changed, 83 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterRule.java b/app/src/main/java/eu/faircode/email/AdapterRule.java index c2cfed1ecf..f17a3cb0ad 100644 --- a/app/src/main/java/eu/faircode/email/AdapterRule.java +++ b/app/src/main/java/eu/faircode/email/AdapterRule.java @@ -164,57 +164,50 @@ public class AdapterRule extends RecyclerView.Adapter { try { JSONObject jaction = new JSONObject(rule.action); int type = jaction.getInt("type"); - switch (type) { - case EntityRule.TYPE_NOOP: - tvAction.setText(R.string.title_rule_noop); - break; - case EntityRule.TYPE_SEEN: - tvAction.setText(R.string.title_rule_seen); - break; - case EntityRule.TYPE_UNSEEN: - tvAction.setText(R.string.title_rule_unseen); - break; - case EntityRule.TYPE_HIDE: - tvAction.setText(R.string.title_rule_hide); - break; - case EntityRule.TYPE_IGNORE: - tvAction.setText(R.string.title_rule_ignore); - break; - case EntityRule.TYPE_SNOOZE: - tvAction.setText(R.string.title_rule_snooze); - break; - case EntityRule.TYPE_FLAG: - tvAction.setText(R.string.title_rule_flag); - break; - case EntityRule.TYPE_IMPORTANCE: - tvAction.setText(R.string.title_rule_importance); - break; - case EntityRule.TYPE_KEYWORD: - tvAction.setText(R.string.title_rule_keyword); - break; - case EntityRule.TYPE_MOVE: - tvAction.setText(R.string.title_rule_move); - break; - case EntityRule.TYPE_COPY: - tvAction.setText(R.string.title_rule_copy); - break; - case EntityRule.TYPE_ANSWER: - tvAction.setText(R.string.title_rule_answer); - break; - case EntityRule.TYPE_TTS: - tvAction.setText(R.string.title_rule_tts); - break; - case EntityRule.TYPE_AUTOMATION: - tvAction.setText(R.string.title_rule_automation); - break; - case EntityRule.TYPE_DELETE: - tvAction.setText(R.string.title_rule_delete); - break; - case EntityRule.TYPE_SOUND: - tvAction.setText(R.string.title_rule_sound); - break; - default: - throw new IllegalArgumentException("Unknown action type=" + type); + tvAction.setText(getActionTitle(type)); + + if (type == EntityRule.TYPE_MOVE || type == EntityRule.TYPE_COPY) { + Bundle args = new Bundle(); + args.putLong("id", rule.id); + args.putInt("type", type); + args.putLong("target", jaction.optLong("target", -1)); + + new SimpleTask() { + @Override + protected EntityFolder onExecute(Context context, Bundle args) throws Throwable { + long target = args.getLong("target"); + + DB db = DB.getInstance(context); + return db.folder().getFolder(target); + } + + @Override + protected void onExecuted(Bundle args, EntityFolder folder) { + int pos = getAdapterPosition(); + if (pos == RecyclerView.NO_POSITION) + return; + + long id = args.getLong("id"); + if (id != AdapterRule.this.getItemId(pos)) + return; + + int type = args.getInt("type"); + SpannableStringBuilder ssb = new SpannableStringBuilderEx(); + ssb.append(context.getString(getActionTitle(type))); + ssb.append(" \""); + int start = ssb.length(); + ssb.append(folder == null ? "???" : folder.name); + ssb.setSpan(new StyleSpan(Typeface.ITALIC), start, ssb.length(), 0); + ssb.append("\""); + + tvAction.setText(ssb); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + // Ignored + } + }.execute(context, owner, args, "rule:folder"); } } catch (Throwable ex) { tvAction.setText(ex.getMessage()); @@ -431,6 +424,45 @@ public class AdapterRule extends RecyclerView.Adapter { return true; } + + private int getActionTitle(int type) { + switch (type) { + case EntityRule.TYPE_NOOP: + return R.string.title_rule_noop; + case EntityRule.TYPE_SEEN: + return R.string.title_rule_seen; + case EntityRule.TYPE_UNSEEN: + return R.string.title_rule_unseen; + case EntityRule.TYPE_HIDE: + return R.string.title_rule_hide; + case EntityRule.TYPE_IGNORE: + return R.string.title_rule_ignore; + case EntityRule.TYPE_SNOOZE: + return R.string.title_rule_snooze; + case EntityRule.TYPE_FLAG: + return R.string.title_rule_flag; + case EntityRule.TYPE_IMPORTANCE: + return R.string.title_rule_importance; + case EntityRule.TYPE_KEYWORD: + return R.string.title_rule_keyword; + case EntityRule.TYPE_MOVE: + return R.string.title_rule_move; + case EntityRule.TYPE_COPY: + return R.string.title_rule_copy; + case EntityRule.TYPE_ANSWER: + return R.string.title_rule_answer; + case EntityRule.TYPE_TTS: + return R.string.title_rule_tts; + case EntityRule.TYPE_AUTOMATION: + return R.string.title_rule_automation; + case EntityRule.TYPE_DELETE: + return R.string.title_rule_delete; + case EntityRule.TYPE_SOUND: + return R.string.title_rule_sound; + default: + throw new IllegalArgumentException("Unknown action type=" + type); + } + } } AdapterRule(Fragment parentFragment) { diff --git a/app/src/main/res/layout/item_rule.xml b/app/src/main/res/layout/item_rule.xml index c1136acd53..e227aa4ab0 100644 --- a/app/src/main/res/layout/item_rule.xml +++ b/app/src/main/res/layout/item_rule.xml @@ -67,7 +67,6 @@ android:layout_height="wrap_content" android:text="Action" android:textAppearance="@style/TextAppearance.AppCompat.Small" - android:textStyle="bold" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvCondition" />