mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-29 13:24:52 +02:00
Every day
This commit is contained in:
@@ -433,14 +433,18 @@ public class EntityRule {
|
||||
// Schedule
|
||||
JSONObject jschedule = jcondition.optJSONObject("schedule");
|
||||
if (jschedule != null) {
|
||||
boolean all = jschedule.optBoolean("all", false);
|
||||
int start = jschedule.optInt("start", 0);
|
||||
int end = jschedule.optInt("end", 0);
|
||||
|
||||
Calendar cal_start = getRelativeCalendar(start, message.received);
|
||||
Calendar cal_end = getRelativeCalendar(end, message.received);
|
||||
Calendar cal_start = getRelativeCalendar(all, start, message.received);
|
||||
Calendar cal_end = getRelativeCalendar(all, end, message.received);
|
||||
|
||||
if (cal_start.getTimeInMillis() > cal_end.getTimeInMillis())
|
||||
cal_start.add(Calendar.HOUR_OF_DAY, -7 * 24);
|
||||
if (all)
|
||||
cal_end.add(Calendar.DATE, 1);
|
||||
else
|
||||
cal_start.add(Calendar.HOUR_OF_DAY, -7 * 24);
|
||||
|
||||
if (message.received < cal_start.getTimeInMillis() ||
|
||||
message.received > cal_end.getTimeInMillis())
|
||||
@@ -1141,7 +1145,7 @@ public class EntityRule {
|
||||
JSONObject jschedule = jcondition.optJSONObject("schedule");
|
||||
|
||||
int end = (jschedule == null ? 0 : jschedule.optInt("end", 0));
|
||||
Calendar cal = getRelativeCalendar(end, message.received);
|
||||
Calendar cal = getRelativeCalendar(false, end, message.received);
|
||||
wakeup = cal.getTimeInMillis() + duration * 3600 * 1000L;
|
||||
} else
|
||||
wakeup = message.received + duration * 3600 * 1000L;
|
||||
@@ -1240,19 +1244,24 @@ public class EntityRule {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Calendar getRelativeCalendar(int minutes, long reference) {
|
||||
private static Calendar getRelativeCalendar(boolean all, int minutes, long reference) {
|
||||
int d = minutes / (24 * 60);
|
||||
int h = minutes / 60 % 24;
|
||||
int m = minutes % 60;
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
if (reference > cal.getTimeInMillis() - 7 * 24 * 3600 * 1000L)
|
||||
cal.setTimeInMillis(reference);
|
||||
long time = cal.getTimeInMillis();
|
||||
|
||||
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY + d);
|
||||
if (cal.getTimeInMillis() < time)
|
||||
cal.add(Calendar.HOUR_OF_DAY, 7 * 24);
|
||||
if (all)
|
||||
cal.setTimeInMillis(reference);
|
||||
else {
|
||||
if (reference > cal.getTimeInMillis() - 7 * 24 * 3600 * 1000L)
|
||||
cal.setTimeInMillis(reference);
|
||||
long time = cal.getTimeInMillis();
|
||||
|
||||
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY + d);
|
||||
if (cal.getTimeInMillis() < time)
|
||||
cal.add(Calendar.HOUR_OF_DAY, 7 * 24);
|
||||
}
|
||||
|
||||
cal.set(Calendar.HOUR_OF_DAY, h);
|
||||
cal.set(Calendar.MINUTE, m);
|
||||
|
||||
@@ -126,6 +126,7 @@ public class FragmentRule extends FragmentBase {
|
||||
private Spinner spScheduleDayEnd;
|
||||
private TextView tvScheduleHourStart;
|
||||
private TextView tvScheduleHourEnd;
|
||||
private CheckBox cbEveryDay;
|
||||
|
||||
private Spinner spAction;
|
||||
private TextView tvActionRemark;
|
||||
@@ -307,6 +308,7 @@ public class FragmentRule extends FragmentBase {
|
||||
spScheduleDayEnd = view.findViewById(R.id.spScheduleDayEnd);
|
||||
tvScheduleHourStart = view.findViewById(R.id.tvScheduleHourStart);
|
||||
tvScheduleHourEnd = view.findViewById(R.id.tvScheduleHourEnd);
|
||||
cbEveryDay = view.findViewById(R.id.cbEveryDay);
|
||||
|
||||
spAction = view.findViewById(R.id.spAction);
|
||||
tvActionRemark = view.findViewById(R.id.tvActionRemark);
|
||||
@@ -471,6 +473,14 @@ public class FragmentRule extends FragmentBase {
|
||||
spScheduleDayStart.setAdapter(adapterDay);
|
||||
spScheduleDayEnd.setAdapter(adapterDay);
|
||||
|
||||
cbEveryDay.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
spScheduleDayStart.setEnabled(!isChecked);
|
||||
spScheduleDayEnd.setEnabled(!isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
adapterAction = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList<Action>());
|
||||
adapterAction.setDropDownViewResource(R.layout.spinner_item1_dropdown);
|
||||
spAction.setAdapter(adapterAction);
|
||||
@@ -1198,6 +1208,8 @@ public class FragmentRule extends FragmentBase {
|
||||
int start = (jschedule != null && jschedule.has("start") ? jschedule.getInt("start") : 0);
|
||||
int end = (jschedule != null && jschedule.has("end") ? jschedule.getInt("end") : 0);
|
||||
|
||||
cbEveryDay.setChecked(jschedule != null && jschedule.optBoolean("all"));
|
||||
|
||||
spScheduleDayStart.setSelection(start / (24 * 60));
|
||||
spScheduleDayEnd.setSelection(end / (24 * 60));
|
||||
|
||||
@@ -1564,6 +1576,7 @@ public class FragmentRule extends FragmentBase {
|
||||
|
||||
int dstart = spScheduleDayStart.getSelectedItemPosition();
|
||||
int dend = spScheduleDayEnd.getSelectedItemPosition();
|
||||
|
||||
Object hstart = tvScheduleHourStart.getTag();
|
||||
Object hend = tvScheduleHourEnd.getTag();
|
||||
if (hstart == null)
|
||||
@@ -1571,13 +1584,15 @@ public class FragmentRule extends FragmentBase {
|
||||
if (hend == null)
|
||||
hend = 0;
|
||||
|
||||
int start = dstart * 24 * 60 + (int) hstart;
|
||||
int end = dend * 24 * 60 + (int) hend;
|
||||
boolean all = cbEveryDay.isChecked();
|
||||
int start = (all ? 0 : dstart) * 24 * 60 + (int) hstart;
|
||||
int end = (all ? 0 : dend) * 24 * 60 + (int) hend;
|
||||
|
||||
if (start != end) {
|
||||
JSONObject jschedule = new JSONObject();
|
||||
jschedule.put("start", start);
|
||||
jschedule.put("end", end);
|
||||
jschedule.put("all", all);
|
||||
jcondition.put("schedule", jschedule);
|
||||
}
|
||||
|
||||
|
||||
@@ -675,6 +675,15 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvScheduleHourStart" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbEveryDay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="@string/title_rule_time_every_day"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvScheduleHourEnd" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAction"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -685,7 +694,7 @@
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvScheduleHourEnd" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/cbEveryDay" />
|
||||
|
||||
<View
|
||||
android:id="@+id/vSeparatorAction"
|
||||
|
||||
@@ -1831,6 +1831,7 @@
|
||||
<string name="title_rule_time_after">Received after</string>
|
||||
<string name="title_rule_time_before">Received before</string>
|
||||
<string name="title_rule_time_rel">Relative time (received) between</string>
|
||||
<string name="title_rule_time_every_day">Every day</string>
|
||||
<string name="title_rule_regex">Regex</string>
|
||||
<string name="title_rule_and">AND</string>
|
||||
<string name="title_rule_action">Action</string>
|
||||
|
||||
Reference in New Issue
Block a user