Added rule option to delete keywords

pull/212/head
M66B 2 years ago
parent 60bbea131a
commit 4136a5b3e6

@ -199,7 +199,8 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
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)) {

@ -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;
}

@ -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:

@ -819,6 +819,29 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvKeyword" />
<RadioGroup
android:id="@+id/rgKeyword"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etKeyword">
<RadioButton
android:id="@+id/keyword_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_rule_keyword_add" />
<RadioButton
android:id="@+id/keyword_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_rule_keyword_delete" />
</RadioGroup>
<TextView
android:id="@+id/tvMoveTarget"
android:layout_width="wrap_content"
@ -827,7 +850,7 @@
android:text="@string/title_rule_folder"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etKeyword" />
app:layout_constraintTop_toBottomOf="@+id/rgKeyword" />
<Button
android:id="@+id/btnFolder"
@ -1188,7 +1211,7 @@
android:id="@+id/grpKeyword"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvKeyword,etKeyword" />
app:constraint_referenced_ids="tvKeyword,etKeyword,rgKeyword" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpMove"

@ -1837,6 +1837,8 @@
<string name="title_rule_flag">Add star</string>
<string name="title_rule_importance">Set importance</string>
<string name="title_rule_keyword">Add keyword</string>
<string name="title_rule_keyword_add">Add</string>
<string name="title_rule_keyword_delete">Delete</string>
<string name="title_rule_move">Move</string>
<string name="title_rule_copy">Copy (label)</string>
<string name="title_rule_answer">Reply/forward</string>

Loading…
Cancel
Save