Added rule action to add keyword

pull/162/head
M66B 6 years ago
parent 39cf294a9a
commit c179613a5d

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

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

@ -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();

@ -509,6 +509,26 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvColor" />
<TextView
android:id="@+id/tvKeyword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_rule_keyword"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnColor" />
<EditText
android:id="@+id/etKeyword"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="text"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvKeyword" />
<TextView
android:id="@+id/tvMoveTarget"
android:layout_width="wrap_content"
@ -517,7 +537,7 @@
android:text="@string/title_rule_folder"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnColor" />
app:layout_constraintTop_toBottomOf="@+id/etKeyword" />
<Spinner
android:id="@+id/spTarget"
@ -525,7 +545,7 @@
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMoveTarget" />
app:layout_constraintTop_toBottomOf="@id/etKeyword" />
<CheckBox
android:id="@+id/cbMoveSeen"
@ -627,6 +647,12 @@
android:layout_height="0dp"
app:constraint_referenced_ids="tvColor,btnColor" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpKeyword"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvKeyword,etKeyword" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpMove"
android:layout_width="0dp"

@ -687,6 +687,7 @@
<string name="title_rule_ignore">Suppress notification</string>
<string name="title_rule_snooze">Snooze</string>
<string name="title_rule_flag">Add star</string>
<string name="title_rule_keyword">Add keyword</string>
<string name="title_rule_move">Move</string>
<string name="title_rule_copy">Copy (label)</string>
<string name="title_rule_answer">Reply</string>

Loading…
Cancel
Save