Experiment: rule to set notifications local only

This commit is contained in:
M66B
2022-11-23 08:32:02 +01:00
parent 69d2b4f434
commit 3e37f11996
12 changed files with 2883 additions and 1 deletions

View File

@@ -119,6 +119,7 @@ public class EntityRule {
static final int TYPE_TTS = 14;
static final int TYPE_DELETE = 15;
static final int TYPE_SOUND = 16;
static final int TYPE_LOCAL_ONLY = 17;
static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION";
static final String EXTRA_RULE = "rule";
@@ -510,6 +511,8 @@ public class EntityRule {
return onActionDelete(context, message, jaction);
case TYPE_SOUND:
return onActionSound(context, message, jaction);
case TYPE_LOCAL_ONLY:
return onActionLocalOnly(context, message, jaction);
default:
throw new IllegalArgumentException("Unknown rule type=" + type + " name=" + name);
}
@@ -589,6 +592,8 @@ public class EntityRule {
if (TextUtils.isEmpty(uri))
throw new IllegalArgumentException(context.getString(R.string.title_rule_select_sound));
return;
case TYPE_LOCAL_ONLY:
return;
default:
throw new IllegalArgumentException("Unknown rule type=" + type);
}
@@ -1127,6 +1132,18 @@ public class EntityRule {
return true;
}
private boolean onActionLocalOnly(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
if (message.ui_seen)
return false;
DB db = DB.getInstance(context);
message.ui_local_only = true;
db.message().setMessageUiLocalOnly(message.id, message.ui_local_only);
return true;
}
private static Calendar getRelativeCalendar(int minutes, long reference) {
int d = minutes / (24 * 60);
int h = minutes / 60 % 24;