diff --git a/app/src/main/java/eu/faircode/email/AdapterRule.java b/app/src/main/java/eu/faircode/email/AdapterRule.java index eaf3dcb34a..b932764b31 100644 --- a/app/src/main/java/eu/faircode/email/AdapterRule.java +++ b/app/src/main/java/eu/faircode/email/AdapterRule.java @@ -114,6 +114,9 @@ public class AdapterRule extends RecyclerView.Adapter { case EntityRule.TYPE_UNSEEN: tvAction.setText(R.string.title_rule_unseen); break; + case EntityRule.TYPE_SNOOZE: + tvAction.setText(R.string.title_rule_snooze); + break; case EntityRule.TYPE_FLAG: tvAction.setText(R.string.title_rule_flag); break; diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index c811fd0065..c06dd53e4f 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -85,6 +85,7 @@ public class EntityRule { static final int TYPE_AUTOMATION = 5; static final int TYPE_FLAG = 6; static final int TYPE_COPY = 7; + static final int TYPE_SNOOZE = 8; static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION"; static final String EXTRA_RULE = "rule"; @@ -208,6 +209,9 @@ public class EntityRule { case TYPE_UNSEEN: onActionSeen(context, message, false); break; + case TYPE_SNOOZE: + onActionSnooze(context, message, jaction); + break; case TYPE_FLAG: onActionFlag(context, message, jaction); break; @@ -318,6 +322,16 @@ public class EntityRule { } } + private void onActionSnooze(Context context, EntityMessage message, JSONObject jargs) throws JSONException { + int duration = jargs.getInt("duration"); + long wakeup = new Date().getTime() + duration * 3600 * 1000L; + + DB db = DB.getInstance(context); + db.message().setMessageSnoozed(message.id, wakeup); + EntityMessage.snooze(context, message.id, wakeup); + onActionSeen(context, message, true); + } + private void onActionFlag(Context context, EntityMessage message, JSONObject jargs) throws JSONException { Integer color = (jargs.has("color") && !jargs.isNull("color") ? jargs.getInt("color") : null); diff --git a/app/src/main/java/eu/faircode/email/FragmentRule.java b/app/src/main/java/eu/faircode/email/FragmentRule.java index b8e0081fd1..8187a9ac80 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRule.java +++ b/app/src/main/java/eu/faircode/email/FragmentRule.java @@ -40,6 +40,7 @@ import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageView; +import android.widget.NumberPicker; import android.widget.ScrollView; import android.widget.Spinner; import android.widget.TextView; @@ -94,6 +95,8 @@ public class FragmentRule extends FragmentBase { private Spinner spAction; private TextView tvActionRemark; + private NumberPicker npDuration; + private Button btnColor; private View vwColor; private ImageView ibColorDefault; @@ -111,6 +114,7 @@ public class FragmentRule extends FragmentBase { private ContentLoadingProgressBar pbWait; private Group grpReady; + private Group grpSnooze; private Group grpFlag; private Group grpMove; private Group grpAnswer; @@ -173,6 +177,10 @@ public class FragmentRule extends FragmentBase { spAction = view.findViewById(R.id.spAction); tvActionRemark = view.findViewById(R.id.tvActionRemark); + npDuration = view.findViewById(R.id.npDuration); + npDuration.setMinValue(1); + npDuration.setMaxValue(99); + btnColor = view.findViewById(R.id.btnColor); vwColor = view.findViewById(R.id.vwColor); ibColorDefault = view.findViewById(R.id.ibColorDefault); @@ -190,6 +198,7 @@ public class FragmentRule extends FragmentBase { pbWait = view.findViewById(R.id.pbWait); grpReady = view.findViewById(R.id.grpReady); + grpSnooze = view.findViewById(R.id.grpSnooze); grpFlag = view.findViewById(R.id.grpFlag); grpMove = view.findViewById(R.id.grpMove); grpAnswer = view.findViewById(R.id.grpAnswer); @@ -236,6 +245,7 @@ public class FragmentRule extends FragmentBase { List actions = new ArrayList<>(); actions.add(new Action(EntityRule.TYPE_SEEN, getString(R.string.title_rule_seen))); actions.add(new Action(EntityRule.TYPE_UNSEEN, getString(R.string.title_rule_unseen))); + 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_MOVE, getString(R.string.title_rule_move))); actions.add(new Action(EntityRule.TYPE_COPY, getString(R.string.title_rule_copy))); @@ -329,6 +339,7 @@ public class FragmentRule extends FragmentBase { tvFolder.setText(null); bottom_navigation.setVisibility(View.GONE); grpReady.setVisibility(View.GONE); + grpSnooze.setVisibility(View.GONE); grpFlag.setVisibility(View.GONE); grpMove.setVisibility(View.GONE); grpAnswer.setVisibility(View.GONE); @@ -478,6 +489,10 @@ public class FragmentRule extends FragmentBase { } else { int type = jaction.getInt("type"); switch (type) { + case EntityRule.TYPE_SNOOZE: + npDuration.setValue(jaction.getInt("duration")); + break; + case EntityRule.TYPE_FLAG: setColor(jaction.isNull("color") ? null : jaction.getInt("color")); break; @@ -763,6 +778,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); grpMove.setVisibility(type == EntityRule.TYPE_MOVE || type == EntityRule.TYPE_COPY ? View.VISIBLE : View.GONE); grpAnswer.setVisibility(type == EntityRule.TYPE_ANSWER ? View.VISIBLE : View.GONE); @@ -826,6 +842,10 @@ public class FragmentRule extends FragmentBase { if (action != null) { jaction.put("type", action.type); switch (action.type) { + case EntityRule.TYPE_SNOOZE: + jaction.put("duration", npDuration.getValue()); + break; + case EntityRule.TYPE_FLAG: jaction.put("color", color); break; diff --git a/app/src/main/res/layout/fragment_rule.xml b/app/src/main/res/layout/fragment_rule.xml index 9907219508..d464ad8d72 100644 --- a/app/src/main/res/layout/fragment_rule.xml +++ b/app/src/main/res/layout/fragment_rule.xml @@ -369,6 +369,23 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvActionRemark" /> + + + +