Added younger than rule condition

This commit is contained in:
M66B 2023-04-19 21:54:10 +02:00
parent 06e646c29a
commit b57504816e
4 changed files with 67 additions and 3 deletions

View File

@ -499,6 +499,14 @@ public class EntityRule {
return false;
}
if (jcondition.has("younger")) {
int younger = jcondition.getInt("younger");
Calendar y = Calendar.getInstance();
y.add(Calendar.HOUR_OF_DAY, -younger);
if (message.received < y.getTimeInMillis())
return false;
}
// Safeguard
if (jsender == null &&
jrecipient == null &&
@ -507,7 +515,8 @@ public class EntityRule {
jheader == null &&
jbody == null &&
jdate == null &&
jschedule == null)
jschedule == null &&
!jcondition.has("younger"))
return false;
} catch (JSONException ex) {
Log.e(ex);

View File

@ -127,6 +127,7 @@ public class FragmentRule extends FragmentBase {
private TextView tvScheduleHourStart;
private TextView tvScheduleHourEnd;
private CheckBox cbEveryDay;
private EditText etYounger;
private Spinner spAction;
private TextView tvActionRemark;
@ -311,6 +312,7 @@ public class FragmentRule extends FragmentBase {
tvScheduleHourStart = view.findViewById(R.id.tvScheduleHourStart);
tvScheduleHourEnd = view.findViewById(R.id.tvScheduleHourEnd);
cbEveryDay = view.findViewById(R.id.cbEveryDay);
etYounger = view.findViewById(R.id.etYounger);
spAction = view.findViewById(R.id.spAction);
tvActionRemark = view.findViewById(R.id.tvActionRemark);
@ -1224,6 +1226,8 @@ public class FragmentRule extends FragmentBase {
int end = (jschedule != null && jschedule.has("end") ? jschedule.getInt("end") : 0);
cbEveryDay.setChecked(jschedule != null && jschedule.optBoolean("all"));
etYounger.setText(jcondition.has("younger")
? Integer.toString(jcondition.optInt("younger")) : null);
spScheduleDayStart.setSelection(start / (24 * 60));
spScheduleDayEnd.setSelection(end / (24 * 60));
@ -1625,6 +1629,14 @@ public class FragmentRule extends FragmentBase {
jcondition.put("schedule", jschedule);
}
String younger = etYounger.getText().toString().trim();
if (!TextUtils.isEmpty(younger) && TextUtils.isDigitsOnly(younger))
try {
jcondition.put("younger", Integer.parseInt(younger));
} catch (Throwable ex) {
Log.e(ex);
}
return jcondition;
}

View File

@ -139,7 +139,6 @@
android:layout_marginTop="12dp"
android:text="@string/title_rule_age"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cbDaily" />
@ -715,6 +714,49 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvScheduleHourEnd" />
<TextView
android:id="@+id/tvAndYounger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_rule_and"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cbEveryDay" />
<View
android:id="@+id/vSeparatorYounger"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAndYounger" />
<TextView
android:id="@+id/tvYounger"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_rule_younger"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorYounger" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etYounger"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/title_optional"
android:importantForAutofill="no"
android:inputType="text|number"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvYounger" />
<TextView
android:id="@+id/tvAction"
android:layout_width="wrap_content"
@ -725,7 +767,7 @@
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cbEveryDay" />
app:layout_constraintTop_toBottomOf="@+id/etYounger" />
<View
android:id="@+id/vSeparatorAction"

View File

@ -1885,6 +1885,7 @@
<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_younger">Messages younger than (hours)</string>
<string name="title_rule_regex">Regex</string>
<string name="title_rule_and">AND</string>
<string name="title_rule_action">Action</string>