Added message age rule condition

This commit is contained in:
M66B
2022-12-23 16:06:40 +01:00
parent 49c5167e10
commit d718c7a6a6
5 changed files with 76 additions and 7 deletions

View File

@@ -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) {