Added rule action to add keyword

This commit is contained in:
M66B
2019-10-09 11:09:00 +02:00
parent 39cf294a9a
commit c179613a5d
5 changed files with 65 additions and 2 deletions

View File

@@ -139,6 +139,9 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
case EntityRule.TYPE_FLAG:
tvAction.setText(R.string.title_rule_flag);
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;

View File

@@ -26,6 +26,7 @@ import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
@@ -95,6 +96,7 @@ public class EntityRule {
static final int TYPE_SNOOZE = 8;
static final int TYPE_IGNORE = 9;
static final int TYPE_NOOP = 10;
static final int TYPE_KEYWORD = 11;
static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION";
static final String EXTRA_RULE = "rule";
@@ -278,6 +280,8 @@ public class EntityRule {
return onActionSnooze(context, message, jaction);
case TYPE_FLAG:
return onActionFlag(context, message, jaction);
case TYPE_KEYWORD:
return onActionKeyword(context, message, jaction);
case TYPE_MOVE:
return onActionMove(context, message, jaction);
case TYPE_COPY:
@@ -451,6 +455,18 @@ public class EntityRule {
return true;
}
private boolean onActionKeyword(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
String keyword = jargs.getString("keyword");
if (TextUtils.isEmpty(keyword)) {
Log.w("Keyword empty");
return false;
}
EntityOperation.queue(context, message, EntityOperation.KEYWORD, keyword, true);
return true;
}
private static Calendar getRelativeCalendar(int minutes, long reference) {
int d = minutes / (24 * 60);
int h = minutes / 60 % 24;

View File

@@ -112,6 +112,8 @@ public class FragmentRule extends FragmentBase {
private ViewButtonColor btnColor;
private EditText etKeyword;
private Spinner spTarget;
private CheckBox cbMoveSeen;
private CheckBox cbMoveThread;
@@ -129,6 +131,7 @@ public class FragmentRule extends FragmentBase {
private Group grpReady;
private Group grpSnooze;
private Group grpFlag;
private Group grpKeyword;
private Group grpMove;
private Group grpMoveProp;
private Group grpAnswer;
@@ -213,6 +216,8 @@ public class FragmentRule extends FragmentBase {
btnColor = view.findViewById(R.id.btnColor);
etKeyword = view.findViewById(R.id.etKeyword);
spTarget = view.findViewById(R.id.spTarget);
cbMoveSeen = view.findViewById(R.id.cbMoveSeen);
cbMoveThread = view.findViewById(R.id.cbMoveThread);
@@ -231,6 +236,7 @@ public class FragmentRule extends FragmentBase {
grpReady = view.findViewById(R.id.grpReady);
grpSnooze = view.findViewById(R.id.grpSnooze);
grpFlag = view.findViewById(R.id.grpFlag);
grpKeyword = view.findViewById(R.id.grpKeyword);
grpMove = view.findViewById(R.id.grpMove);
grpMoveProp = view.findViewById(R.id.grpMoveProp);
grpAnswer = view.findViewById(R.id.grpAnswer);
@@ -325,6 +331,7 @@ public class FragmentRule extends FragmentBase {
actions.add(new Action(EntityRule.TYPE_IGNORE, getString(R.string.title_rule_ignore)));
actions.add(new Action(EntityRule.TYPE_SNOOZE, getString(R.string.title_rule_snooze)));
actions.add(new Action(EntityRule.TYPE_FLAG, getString(R.string.title_rule_flag)));
actions.add(new Action(EntityRule.TYPE_KEYWORD, getString(R.string.title_rule_keyword)));
actions.add(new Action(EntityRule.TYPE_MOVE, getString(R.string.title_rule_move)));
actions.add(new Action(EntityRule.TYPE_COPY, getString(R.string.title_rule_copy)));
actions.add(new Action(EntityRule.TYPE_ANSWER, getString(R.string.title_rule_answer)));
@@ -411,6 +418,7 @@ public class FragmentRule extends FragmentBase {
grpReady.setVisibility(View.GONE);
grpSnooze.setVisibility(View.GONE);
grpFlag.setVisibility(View.GONE);
grpKeyword.setVisibility(View.GONE);
grpMove.setVisibility(View.GONE);
grpMoveProp.setVisibility(View.GONE);
grpAnswer.setVisibility(View.GONE);
@@ -668,6 +676,10 @@ public class FragmentRule extends FragmentBase {
? null : jaction.getInt("color"));
break;
case EntityRule.TYPE_KEYWORD:
etKeyword.setText(jaction.getString("keyword"));
break;
case EntityRule.TYPE_MOVE:
case EntityRule.TYPE_COPY:
long target = jaction.optLong("target", -1);
@@ -730,6 +742,7 @@ public class FragmentRule extends FragmentBase {
private void showActionParameters(int type) {
grpSnooze.setVisibility(type == EntityRule.TYPE_SNOOZE ? View.VISIBLE : View.GONE);
grpFlag.setVisibility(type == EntityRule.TYPE_FLAG ? View.VISIBLE : View.GONE);
grpKeyword.setVisibility(type == EntityRule.TYPE_KEYWORD ? 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);
@@ -947,6 +960,10 @@ public class FragmentRule extends FragmentBase {
jaction.put("color", btnColor.getColor());
break;
case EntityRule.TYPE_KEYWORD:
jaction.put("keyword", etKeyword.getText().toString().trim());
break;
case EntityRule.TYPE_MOVE:
case EntityRule.TYPE_COPY:
EntityFolder target = (EntityFolder) spTarget.getSelectedItem();