diff --git a/app/src/main/java/eu/faircode/email/AdapterRule.java b/app/src/main/java/eu/faircode/email/AdapterRule.java index 9d644d79e8..d9844c166a 100644 --- a/app/src/main/java/eu/faircode/email/AdapterRule.java +++ b/app/src/main/java/eu/faircode/email/AdapterRule.java @@ -199,7 +199,8 @@ public class AdapterRule extends RecyclerView.Adapter { setAction(getAction(type), value); } else if (type == EntityRule.TYPE_KEYWORD) { - setAction(getAction(type), jaction.optString("keyword")); + boolean set = jaction.optBoolean("set", true); + setAction(getAction(type), (set ? "+" : "-") + jaction.optString("keyword")); } else if (type == EntityRule.TYPE_ANSWER) { to = jaction.optString("to"); if (!TextUtils.isEmpty(to)) { diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index d21fe0d781..170b3dcbf1 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -1220,10 +1220,11 @@ public class EntityRule { private boolean onActionKeyword(Context context, EntityMessage message, JSONObject jargs) throws JSONException { String keyword = jargs.getString("keyword"); + boolean set = jargs.optBoolean("set", true); if (TextUtils.isEmpty(keyword)) throw new IllegalArgumentException("Keyword missing rule=" + name); - EntityOperation.queue(context, message, EntityOperation.KEYWORD, keyword, true); + EntityOperation.queue(context, message, EntityOperation.KEYWORD, keyword, set); return true; } diff --git a/app/src/main/java/eu/faircode/email/FragmentRule.java b/app/src/main/java/eu/faircode/email/FragmentRule.java index 7d440b8fd5..4c99de39b9 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRule.java +++ b/app/src/main/java/eu/faircode/email/FragmentRule.java @@ -49,6 +49,7 @@ import android.widget.CompoundButton; import android.widget.EditText; import android.widget.ImageButton; import android.widget.NumberPicker; +import android.widget.RadioGroup; import android.widget.ScrollView; import android.widget.Spinner; import android.widget.TextView; @@ -140,6 +141,7 @@ public class FragmentRule extends FragmentBase { private Spinner spImportance; private EditText etKeyword; + private RadioGroup rgKeyword; private Button btnFolder; private EditText etMoveCreate; @@ -322,6 +324,7 @@ public class FragmentRule extends FragmentBase { spImportance = view.findViewById(R.id.spImportance); etKeyword = view.findViewById(R.id.etKeyword); + rgKeyword = view.findViewById(R.id.rgKeyword); btnFolder = view.findViewById(R.id.btnFolder); etMoveCreate = view.findViewById(R.id.etMoveCreate); @@ -1246,6 +1249,9 @@ public class FragmentRule extends FragmentBase { case EntityRule.TYPE_KEYWORD: etKeyword.setText(jaction.getString("keyword")); + rgKeyword.check(jaction.optBoolean("set", true) + ? R.id.keyword_add : R.id.keyword_delete); + break; case EntityRule.TYPE_MOVE: @@ -1624,6 +1630,7 @@ public class FragmentRule extends FragmentBase { case EntityRule.TYPE_KEYWORD: jaction.put("keyword", MessageHelper.sanitizeKeyword(etKeyword.getText().toString())); + jaction.put("set", rgKeyword.getCheckedRadioButtonId() == R.id.keyword_add); break; case EntityRule.TYPE_MOVE: diff --git a/app/src/main/res/layout/fragment_rule.xml b/app/src/main/res/layout/fragment_rule.xml index f042376e81..9719ca32d7 100644 --- a/app/src/main/res/layout/fragment_rule.xml +++ b/app/src/main/res/layout/fragment_rule.xml @@ -819,6 +819,29 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvKeyword" /> + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/rgKeyword" />