From 13f3181d08044e07c83ed1795d6bd586ceedfcda Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 9 Jun 2019 21:25:56 +0200 Subject: [PATCH] Added seen and thread options to move rule --- .../java/eu/faircode/email/EntityRule.java | 11 +++++++- .../java/eu/faircode/email/FragmentRule.java | 22 ++++++++++++--- app/src/main/res/layout/fragment_rule.xml | 27 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index b4f0267525..1b55a586f1 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -240,13 +240,22 @@ public class EntityRule { private void onActionMove(Context context, EntityMessage message, JSONObject jargs) throws JSONException { long target = jargs.getLong("target"); + boolean seen = jargs.optBoolean("seen"); + boolean thread = jargs.optBoolean("thread"); DB db = DB.getInstance(context); EntityFolder folder = db.folder().getFolder(target); if (folder == null) throw new IllegalArgumentException("Rule move to folder not found"); - EntityOperation.queue(context, message, EntityOperation.MOVE, target, false); + List messages = db.message().getMessageByThread( + message.account, message.thread, thread ? null : message.id, message.folder); + for (EntityMessage threaded : messages) { + if (seen) + onActionSeen(context, threaded, true); + + EntityOperation.queue(context, threaded, EntityOperation.MOVE, target, false); + } } private void onActionCopy(Context context, EntityMessage message, JSONObject jargs) throws JSONException { diff --git a/app/src/main/java/eu/faircode/email/FragmentRule.java b/app/src/main/java/eu/faircode/email/FragmentRule.java index 8187a9ac80..116547c3f7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRule.java +++ b/app/src/main/java/eu/faircode/email/FragmentRule.java @@ -102,6 +102,8 @@ public class FragmentRule extends FragmentBase { private ImageView ibColorDefault; private Spinner spTarget; + private CheckBox cbMoveSeen; + private CheckBox cbMoveThread; private Spinner spIdent; @@ -117,6 +119,7 @@ public class FragmentRule extends FragmentBase { private Group grpSnooze; private Group grpFlag; private Group grpMove; + private Group grpMoveProp; private Group grpAnswer; private Group grpAutomation; @@ -186,6 +189,8 @@ public class FragmentRule extends FragmentBase { ibColorDefault = view.findViewById(R.id.ibColorDefault); spTarget = view.findViewById(R.id.spTarget); + cbMoveSeen = view.findViewById(R.id.cbMoveSeen); + cbMoveThread = view.findViewById(R.id.cbMoveThread); spIdent = view.findViewById(R.id.spIdent); @@ -201,6 +206,7 @@ public class FragmentRule extends FragmentBase { grpSnooze = view.findViewById(R.id.grpSnooze); grpFlag = view.findViewById(R.id.grpFlag); grpMove = view.findViewById(R.id.grpMove); + grpMoveProp = view.findViewById(R.id.grpMoveProp); grpAnswer = view.findViewById(R.id.grpAnswer); grpAutomation = view.findViewById(R.id.grpAutomation); @@ -342,6 +348,7 @@ public class FragmentRule extends FragmentBase { grpSnooze.setVisibility(View.GONE); grpFlag.setVisibility(View.GONE); grpMove.setVisibility(View.GONE); + grpMoveProp.setVisibility(View.GONE); grpAnswer.setVisibility(View.GONE); grpAutomation.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE); @@ -505,6 +512,10 @@ public class FragmentRule extends FragmentBase { spTarget.setSelection(pos); break; } + if (type == EntityRule.TYPE_MOVE) { + cbMoveSeen.setChecked(jaction.optBoolean("seen")); + cbMoveThread.setChecked(jaction.optBoolean("thread")); + } break; case EntityRule.TYPE_ANSWER: @@ -522,8 +533,7 @@ public class FragmentRule extends FragmentBase { break; } - boolean cc = (jaction.has("cc") && jaction.getBoolean("cc")); - cbCc.setChecked(cc); + cbCc.setChecked(jaction.optBoolean("cc")); break; } @@ -781,6 +791,7 @@ public class FragmentRule extends FragmentBase { grpSnooze.setVisibility(type == EntityRule.TYPE_SNOOZE ? View.VISIBLE : View.GONE); grpFlag.setVisibility(type == EntityRule.TYPE_FLAG ? View.VISIBLE : View.GONE); grpMove.setVisibility(type == EntityRule.TYPE_MOVE || type == EntityRule.TYPE_COPY ? View.VISIBLE : View.GONE); + grpMoveProp.setVisibility(type == EntityRule.TYPE_MOVE ? View.VISIBLE : View.GONE); grpAnswer.setVisibility(type == EntityRule.TYPE_ANSWER ? View.VISIBLE : View.GONE); grpAutomation.setVisibility(type == EntityRule.TYPE_AUTOMATION ? View.VISIBLE : View.GONE); } @@ -854,15 +865,18 @@ public class FragmentRule extends FragmentBase { case EntityRule.TYPE_COPY: EntityFolder target = (EntityFolder) spTarget.getSelectedItem(); jaction.put("target", target == null ? -1 : target.id); + if (action.type == EntityRule.TYPE_MOVE) { + jaction.put("seen", cbMoveSeen.isChecked()); + jaction.put("thread", cbMoveThread.isChecked()); + } break; case EntityRule.TYPE_ANSWER: EntityIdentity identity = (EntityIdentity) spIdent.getSelectedItem(); EntityAnswer answer = (EntityAnswer) spAnswer.getSelectedItem(); - boolean cc = cbCc.isChecked(); jaction.put("identity", identity == null ? -1 : identity.id); jaction.put("answer", answer == null ? -1 : answer.id); - jaction.put("cc", cc); + jaction.put("cc", cbCc.isChecked()); break; } } diff --git a/app/src/main/res/layout/fragment_rule.xml b/app/src/main/res/layout/fragment_rule.xml index d464ad8d72..798522a9ca 100644 --- a/app/src/main/res/layout/fragment_rule.xml +++ b/app/src/main/res/layout/fragment_rule.xml @@ -438,6 +438,24 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvMoveTarget" /> + + + + + app:layout_constraintTop_toBottomOf="@+id/cbMoveThread" /> + + This action will be applied to new messages arriving in the folder %1$s Hours Folder + All messages in same conversation and folder Identity Reply template Reply to CC addresses