diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java
index 6485dcf0fc..1138daaab2 100644
--- a/app/src/main/java/eu/faircode/email/EntityRule.java
+++ b/app/src/main/java/eu/faircode/email/EntityRule.java
@@ -349,7 +349,30 @@ public class EntityRule {
private boolean onActionSnooze(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
int duration = jargs.getInt("duration");
- long wakeup = message.received + duration * 3600 * 1000L;
+ boolean schedule_end = jargs.optBoolean("schedule_end", false);
+
+ long wakeup;
+ if (schedule_end) {
+ JSONObject jcondition = new JSONObject(condition);
+ JSONObject jschedule = jcondition.optJSONObject("schedule");
+
+ if (jschedule == null)
+ throw new IllegalArgumentException("Rule snooze schedule not found");
+
+ int start = jschedule.optInt("start", 0);
+ int end = jschedule.optInt("end", 0);
+ if (end <= start)
+ end += 24 * 60;
+
+ int hour = end / 60;
+ int minute = end % 60;
+ Calendar cal = Calendar.getInstance();
+ cal.set(Calendar.HOUR_OF_DAY, hour);
+ cal.set(Calendar.MINUTE, minute);
+ cal.set(Calendar.SECOND, 0);
+ wakeup = cal.getTimeInMillis();
+ } else
+ wakeup = message.received + duration * 3600 * 1000L;
if (wakeup < new Date().getTime())
return false;
diff --git a/app/src/main/java/eu/faircode/email/FragmentRule.java b/app/src/main/java/eu/faircode/email/FragmentRule.java
index cac61ec538..3cbb1c50fb 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.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
+import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
@@ -108,6 +109,7 @@ public class FragmentRule extends FragmentBase {
private TextView tvActionRemark;
private NumberPicker npDuration;
+ private CheckBox cbScheduleEnd;
private Button btnColor;
private View vwColor;
@@ -205,6 +207,7 @@ public class FragmentRule extends FragmentBase {
tvActionRemark = view.findViewById(R.id.tvActionRemark);
npDuration = view.findViewById(R.id.npDuration);
+ cbScheduleEnd = view.findViewById(R.id.cbScheduleEnd);
btnColor = view.findViewById(R.id.btnColor);
vwColor = view.findViewById(R.id.vwColor);
@@ -348,6 +351,13 @@ public class FragmentRule extends FragmentBase {
npDuration.setMinValue(1);
npDuration.setMaxValue(99);
+ cbScheduleEnd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
+ npDuration.setEnabled(!checked);
+ }
+ });
+
tvActionRemark.setVisibility(View.GONE);
onSelectColor(color);
@@ -578,12 +588,14 @@ public class FragmentRule extends FragmentBase {
int minutes = data.getIntExtra("minutes", 0);
tvScheduleStart.setTag(minutes);
tvScheduleStart.setText(formatHour(getContext(), minutes));
+ cbScheduleEnd.setChecked(true);
}
private void onScheduleEnd(Intent data) {
int minutes = data.getIntExtra("minutes", 0);
tvScheduleEnd.setTag(minutes);
tvScheduleEnd.setText(formatHour(getContext(), minutes));
+ cbScheduleEnd.setChecked(true);
}
private void loadRule() {
@@ -649,6 +661,7 @@ public class FragmentRule extends FragmentBase {
switch (type) {
case EntityRule.TYPE_SNOOZE:
npDuration.setValue(jaction.getInt("duration"));
+ cbScheduleEnd.setChecked(jaction.optBoolean("schedule_end", false));
break;
case EntityRule.TYPE_FLAG:
@@ -919,6 +932,7 @@ public class FragmentRule extends FragmentBase {
switch (action.type) {
case EntityRule.TYPE_SNOOZE:
jaction.put("duration", npDuration.getValue());
+ jaction.put("schedule_end", cbScheduleEnd.isChecked());
break;
case EntityRule.TYPE_FLAG:
diff --git a/app/src/main/res/layout/fragment_rule.xml b/app/src/main/res/layout/fragment_rule.xml
index d3ba2b8c3b..e95a0b40c7 100644
--- a/app/src/main/res/layout/fragment_rule.xml
+++ b/app/src/main/res/layout/fragment_rule.xml
@@ -463,6 +463,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvHours" />
+
+
+ app:layout_constraintTop_toBottomOf="@id/cbScheduleEnd" />
+ tvHours,npDuration,cbScheduleEnd" />
Action
This action will be applied to new messages arriving in the folder %1$s
Hours
+ Until the end of the time condition
Folder
All messages in same conversation and folder
Identity