mirror of https://github.com/M66B/FairEmail.git
Added message age rule condition
This commit is contained in:
parent
49c5167e10
commit
d718c7a6a6
|
@ -158,6 +158,21 @@ public class EntityRule {
|
|||
try {
|
||||
JSONObject jcondition = new JSONObject(condition);
|
||||
|
||||
// general
|
||||
if (this.daily) {
|
||||
JSONObject jgeneral = jcondition.optJSONObject("general");
|
||||
if (jgeneral != null) {
|
||||
int age = jgeneral.optInt("age");
|
||||
if (age > 0) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(message.received);
|
||||
cal.add(Calendar.DAY_OF_MONTH, age);
|
||||
if (cal.getTimeInMillis() > new Date().getTime())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sender
|
||||
JSONObject jsender = jcondition.optJSONObject("sender");
|
||||
if (jsender != null) {
|
||||
|
|
|
@ -89,6 +89,7 @@ public class FragmentRule extends FragmentBase {
|
|||
private EditText etOrder;
|
||||
private CheckBox cbEnabled;
|
||||
private CheckBox cbDaily;
|
||||
private EditText etAge;
|
||||
private CheckBox cbStop;
|
||||
|
||||
private EditText etSender;
|
||||
|
@ -166,6 +167,7 @@ public class FragmentRule extends FragmentBase {
|
|||
private ContentLoadingProgressBar pbWait;
|
||||
|
||||
private Group grpReady;
|
||||
private Group grpAge;
|
||||
private Group grpSnooze;
|
||||
private Group grpFlag;
|
||||
private Group grpImportance;
|
||||
|
@ -246,6 +248,7 @@ public class FragmentRule extends FragmentBase {
|
|||
etOrder = view.findViewById(R.id.etOrder);
|
||||
cbEnabled = view.findViewById(R.id.cbEnabled);
|
||||
cbDaily = view.findViewById(R.id.cbDaily);
|
||||
etAge = view.findViewById(R.id.etAge);
|
||||
cbStop = view.findViewById(R.id.cbStop);
|
||||
|
||||
etSender = view.findViewById(R.id.etSender);
|
||||
|
@ -324,6 +327,7 @@ public class FragmentRule extends FragmentBase {
|
|||
pbWait = view.findViewById(R.id.pbWait);
|
||||
|
||||
grpReady = view.findViewById(R.id.grpReady);
|
||||
grpAge = view.findViewById(R.id.grpAge);
|
||||
grpSnooze = view.findViewById(R.id.grpSnooze);
|
||||
grpFlag = view.findViewById(R.id.grpFlag);
|
||||
grpImportance = view.findViewById(R.id.grpImportance);
|
||||
|
@ -337,6 +341,13 @@ public class FragmentRule extends FragmentBase {
|
|||
grpDelete = view.findViewById(R.id.grpDelete);
|
||||
grpLocalOnly = view.findViewById(R.id.grpLocalOnly);
|
||||
|
||||
cbDaily.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
grpAge.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
ibSender.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -734,6 +745,7 @@ public class FragmentRule extends FragmentBase {
|
|||
tvFolder.setText(null);
|
||||
bottom_navigation.setVisibility(View.GONE);
|
||||
grpReady.setVisibility(View.GONE);
|
||||
grpAge.setVisibility(View.GONE);
|
||||
grpSnooze.setVisibility(View.GONE);
|
||||
grpFlag.setVisibility(View.GONE);
|
||||
grpImportance.setVisibility(View.GONE);
|
||||
|
@ -1089,6 +1101,7 @@ public class FragmentRule extends FragmentBase {
|
|||
JSONObject jcondition = (rule == null ? new JSONObject() : new JSONObject(rule.condition));
|
||||
JSONObject jaction = (rule == null ? new JSONObject() : new JSONObject(rule.action));
|
||||
|
||||
JSONObject jgeneral = jcondition.optJSONObject("general");
|
||||
JSONObject jsender = jcondition.optJSONObject("sender");
|
||||
JSONObject jrecipient = jcondition.optJSONObject("recipient");
|
||||
JSONObject jsubject = jcondition.optJSONObject("subject");
|
||||
|
@ -1101,6 +1114,7 @@ public class FragmentRule extends FragmentBase {
|
|||
etOrder.setText(rule == null ? null : Integer.toString(rule.order));
|
||||
cbEnabled.setChecked(rule == null || rule.enabled);
|
||||
cbDaily.setChecked(rule != null && rule.daily);
|
||||
etAge.setText(jgeneral == null ? null : Integer.toString(jgeneral.optInt("age")));
|
||||
cbStop.setChecked(rule != null && rule.stop);
|
||||
|
||||
etSender.setText(jsender == null ? args.getString("sender") : jsender.getString("value"));
|
||||
|
@ -1252,6 +1266,7 @@ public class FragmentRule extends FragmentBase {
|
|||
Log.e(ex);
|
||||
} finally {
|
||||
grpReady.setVisibility(View.VISIBLE);
|
||||
grpAge.setVisibility(cbDaily.isChecked() ? View.VISIBLE : View.GONE);
|
||||
if (id < 0)
|
||||
bottom_navigation.getMenu().removeItem(R.id.action_delete);
|
||||
bottom_navigation.setVisibility(View.VISIBLE);
|
||||
|
@ -1428,6 +1443,18 @@ public class FragmentRule extends FragmentBase {
|
|||
private JSONObject getCondition() throws JSONException {
|
||||
JSONObject jcondition = new JSONObject();
|
||||
|
||||
JSONObject jgeneral = new JSONObject();
|
||||
|
||||
String age = etAge.getText().toString().trim();
|
||||
if (!TextUtils.isEmpty(age) && TextUtils.isDigitsOnly(age))
|
||||
try {
|
||||
jgeneral.put("age", Integer.parseInt(age));
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
jcondition.put("general", jgeneral);
|
||||
|
||||
String sender = etSender.getText().toString();
|
||||
boolean known = cbKnownSender.isChecked();
|
||||
if (!TextUtils.isEmpty(sender) || known) {
|
||||
|
|
|
@ -26,21 +26,16 @@ import android.content.SharedPreferences;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.work.Constraints;
|
||||
import androidx.work.ExistingPeriodicWorkPolicy;
|
||||
import androidx.work.NetworkType;
|
||||
import androidx.work.PeriodicWorkRequest;
|
||||
import androidx.work.WorkManager;
|
||||
import androidx.work.Worker;
|
||||
import androidx.work.WorkerParameters;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.mail.Header;
|
||||
|
||||
public class WorkerDailyRules extends Worker {
|
||||
public WorkerDailyRules(@NonNull Context context, @NonNull WorkerParameters workerParams) {
|
||||
super(context, workerParams);
|
||||
|
|
|
@ -110,6 +110,31 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbEnabled" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAge"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
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" />
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etAge"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
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/tvAge" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbStop"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -117,7 +142,7 @@
|
|||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_rule_stop"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbDaily" />
|
||||
app:layout_constraintTop_toBottomOf="@id/etAge" />
|
||||
|
||||
<!-- condition -->
|
||||
|
||||
|
@ -1102,7 +1127,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="
|
||||
tvTitle,tvFolder,tvName,etName,tvOrder,etOrder,cbEnabled,cbStop,
|
||||
tvTitle,tvFolder,tvName,etName,tvOrder,etOrder,cbEnabled,cbDaily,cbStop,
|
||||
tvCondition,
|
||||
vSeparatorSender,tvSender,cbSender,etSender,ibSender,cbKnownSender,tvAndSender,
|
||||
vSeparatorRecipient,tvRecipient,cbRecipient,etRecipient,ibRecipient,tvAndRecipient,
|
||||
|
@ -1115,6 +1140,12 @@
|
|||
vSeparatorAction,tvAction,spAction,tvActionRemark,
|
||||
vSeparatorParameters" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpAge"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="tvAge,etAge" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpSnooze"
|
||||
android:layout_width="0dp"
|
||||
|
|
|
@ -1745,6 +1745,7 @@
|
|||
<string name="title_rule_order">Order</string>
|
||||
<string name="title_rule_enabled">Enabled</string>
|
||||
<string name="title_rule_daily">Run daily (only)</string>
|
||||
<string name="title_rule_age">Messages older than (days)</string>
|
||||
<string name="title_rule_stop">Stop processing rules after executing this rule</string>
|
||||
<string name="title_rule_sender">Sender contains</string>
|
||||
<string name="title_rule_sender_known">Sender is a contact</string>
|
||||
|
|
Loading…
Reference in New Issue