From b57504816e8ebbcc2564dfd3dbcc68495cd752fd Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 19 Apr 2023 21:54:10 +0200 Subject: [PATCH] Added younger than rule condition --- .../java/eu/faircode/email/EntityRule.java | 11 ++++- .../java/eu/faircode/email/FragmentRule.java | 12 +++++ app/src/main/res/layout/fragment_rule.xml | 46 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index 2388d0382d..6ead7e556d 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -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); diff --git a/app/src/main/java/eu/faircode/email/FragmentRule.java b/app/src/main/java/eu/faircode/email/FragmentRule.java index e9ee492c92..d3359d3086 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRule.java +++ b/app/src/main/java/eu/faircode/email/FragmentRule.java @@ -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; } diff --git a/app/src/main/res/layout/fragment_rule.xml b/app/src/main/res/layout/fragment_rule.xml index 2bf4c06d4e..bf4808392f 100644 --- a/app/src/main/res/layout/fragment_rule.xml +++ b/app/src/main/res/layout/fragment_rule.xml @@ -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" /> + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/etYounger" /> Received before Relative time (received) between Every day + Messages younger than (hours) Regex AND Action