diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index 31b352ebd5..9e18a0964e 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -177,21 +177,19 @@ public class EntityRule { // Schedule JSONObject jschedule = jcondition.optJSONObject("schedule"); if (jschedule != null) { - int day = jschedule.optInt("day", -1) + 1; int start = jschedule.optInt("start", 0); int end = jschedule.optInt("end", 0); + if (end <= start) - end += 24 * 60; + end += 7 * 24 * 60; Calendar cal = Calendar.getInstance(); cal.setTime(new Date(message.received)); - int mday = cal.get(Calendar.DAY_OF_WEEK); + int mday = cal.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY; int mhour = cal.get(Calendar.HOUR_OF_DAY); int mminute = cal.get(Calendar.MINUTE); - int minutes = mhour * 60 + mminute; + int minutes = mday * 24 * 60 + mhour * 60 + mminute; - if (day > 0 && mday != day) - return false; if (minutes < start || minutes > end) return false; } @@ -359,14 +357,13 @@ public class EntityRule { 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 day = end / (24 * 60); + int hour = end / 60 % 24; int minute = end % 60; + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY + day); cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, 0); diff --git a/app/src/main/java/eu/faircode/email/FragmentRule.java b/app/src/main/java/eu/faircode/email/FragmentRule.java index 875c1b4bed..3cf994fef5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRule.java +++ b/app/src/main/java/eu/faircode/email/FragmentRule.java @@ -99,9 +99,10 @@ public class FragmentRule extends FragmentBase { private EditText etHeader; private CheckBox cbHeader; - private Spinner spScheduleDay; - private TextView tvScheduleStart; - private TextView tvScheduleEnd; + private Spinner spScheduleDayStart; + private Spinner spScheduleDayEnd; + private TextView tvScheduleHourStart; + private TextView tvScheduleHourEnd; private Spinner spAction; private TextView tvActionRemark; @@ -201,9 +202,10 @@ public class FragmentRule extends FragmentBase { etHeader = view.findViewById(R.id.etHeader); cbHeader = view.findViewById(R.id.cbHeader); - spScheduleDay = view.findViewById(R.id.spScheduleDay); - tvScheduleStart = view.findViewById(R.id.tvScheduleStart); - tvScheduleEnd = view.findViewById(R.id.tvScheduleEnd); + spScheduleDayStart = view.findViewById(R.id.spScheduleDayStart); + spScheduleDayEnd = view.findViewById(R.id.spScheduleDayEnd); + tvScheduleHourStart = view.findViewById(R.id.tvScheduleHourStart); + tvScheduleHourEnd = view.findViewById(R.id.tvScheduleHourEnd); spAction = view.findViewById(R.id.spAction); tvActionRemark = view.findViewById(R.id.tvActionRemark); @@ -262,7 +264,8 @@ public class FragmentRule extends FragmentBase { adapterDay = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList()); adapterDay.setDropDownViewResource(R.layout.spinner_item1_dropdown); - spScheduleDay.setAdapter(adapterDay); + spScheduleDayStart.setAdapter(adapterDay); + spScheduleDayEnd.setAdapter(adapterDay); adapterAction = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList()); adapterAction.setDropDownViewResource(R.layout.spinner_item1_dropdown); @@ -280,12 +283,11 @@ public class FragmentRule extends FragmentBase { adapterAnswer.setDropDownViewResource(R.layout.spinner_item1_dropdown); spAnswer.setAdapter(adapterAnswer); - adapterDay.add(getString(R.string.title_any)); String[] dayNames = DateFormatSymbols.getInstance().getWeekdays(); for (int day = Calendar.SUNDAY; day <= Calendar.SATURDAY; day++) adapterDay.add(dayNames[day]); - tvScheduleStart.setOnClickListener(new View.OnClickListener() { + tvScheduleHourStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Object time = v.getTag(); @@ -298,7 +300,7 @@ public class FragmentRule extends FragmentBase { } }); - tvScheduleEnd.setOnClickListener(new View.OnClickListener() { + tvScheduleHourEnd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Object time = v.getTag(); @@ -580,15 +582,15 @@ public class FragmentRule extends FragmentBase { private void onScheduleStart(Intent data) { int minutes = data.getIntExtra("minutes", 0); - tvScheduleStart.setTag(minutes); - tvScheduleStart.setText(formatHour(getContext(), minutes)); + tvScheduleHourStart.setTag(minutes); + tvScheduleHourStart.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)); + tvScheduleHourEnd.setTag(minutes); + tvScheduleHourEnd.setText(formatHour(getContext(), minutes)); cbScheduleEnd.setChecked(true); } @@ -635,14 +637,17 @@ public class FragmentRule extends FragmentBase { etHeader.setText(jheader == null ? null : jheader.getString("value")); cbHeader.setChecked(jheader != null && jheader.getBoolean("regex")); - if (jschedule != null && jschedule.has("day")) - spScheduleDay.setSelection(jschedule.getInt("day") + 1); int start = (jschedule != null && jschedule.has("start") ? jschedule.getInt("start") : 0); - tvScheduleStart.setTag(start); - tvScheduleStart.setText(formatHour(getContext(), start)); int end = (jschedule != null && jschedule.has("end") ? jschedule.getInt("end") : 0); - tvScheduleEnd.setTag(end); - tvScheduleEnd.setText(formatHour(getContext(), end)); + + spScheduleDayStart.setSelection(start / (24 * 60)); + spScheduleDayEnd.setSelection(end / (24 * 60)); + + tvScheduleHourStart.setTag(start % (24 * 60)); + tvScheduleHourStart.setText(formatHour(getContext(), start % (24 * 60))); + + tvScheduleHourEnd.setTag(end % (24 * 60)); + tvScheduleHourEnd.setText(formatHour(getContext(), end % (24 * 60))); if (rule == null) { for (int pos = 0; pos < adapterIdentity.getCount(); pos++) @@ -899,18 +904,22 @@ public class FragmentRule extends FragmentBase { jcondition.put("header", jheader); } - int day = spScheduleDay.getSelectedItemPosition(); - Object start = tvScheduleStart.getTag(); - Object end = tvScheduleEnd.getTag(); - if (start == null) - start = 0; - if (end == null) - end = 0; - if (!(day == 0 && start.equals(end))) { + int dstart = spScheduleDayStart.getSelectedItemPosition(); + int dend = spScheduleDayEnd.getSelectedItemPosition(); + Object hstart = tvScheduleHourStart.getTag(); + Object hend = tvScheduleHourEnd.getTag(); + if (hstart == null) + hstart = 0; + if (hend == null) + hend = 0; + + int start = dstart * 24 * 60 + (int) hstart; + int end = dend * 24 * 60 + (int) hend; + + if (start != end) { JSONObject jschedule = new JSONObject(); - jschedule.put("day", spScheduleDay.getSelectedItemPosition() - 1); - jschedule.put("start", (int) start); - jschedule.put("end", (int) end); + jschedule.put("start", start); + jschedule.put("end", end); jcondition.put("schedule", jschedule); } diff --git a/app/src/main/res/layout/fragment_rule.xml b/app/src/main/res/layout/fragment_rule.xml index e95a0b40c7..4898233b5d 100644 --- a/app/src/main/res/layout/fragment_rule.xml +++ b/app/src/main/res/layout/fragment_rule.xml @@ -360,45 +360,44 @@ app:layout_constraintTop_toBottomOf="@id/vSeparatorSchedule" /> + app:layout_constraintTop_toTopOf="@+id/tvScheduleHourStart" /> - + app:layout_constraintTop_toTopOf="@+id/tvScheduleHourEnd" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toBottomOf="@id/tvSchedule" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toBottomOf="@id/tvScheduleHourStart" /> + app:layout_constraintTop_toBottomOf="@id/tvScheduleHourEnd" /> Report Fix Enable - Any Executing Completed Ask what to do