Added rule action local notes

This commit is contained in:
M66B
2023-08-14 09:39:53 +02:00
parent f0a0c46b44
commit ba7b2302b4
9 changed files with 138 additions and 1 deletions

View File

@@ -126,6 +126,7 @@ public class EntityRule {
static final int TYPE_DELETE = 15;
static final int TYPE_SOUND = 16;
static final int TYPE_LOCAL_ONLY = 17;
static final int TYPE_NOTES = 18;
static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION";
static final String EXTRA_RULE = "rule";
@@ -603,6 +604,8 @@ public class EntityRule {
return onActionSound(context, message, jaction);
case TYPE_LOCAL_ONLY:
return onActionLocalOnly(context, message, jaction);
case TYPE_NOTES:
return onActionNotes(context, message, jaction);
default:
throw new IllegalArgumentException("Unknown rule type=" + type + " name=" + name);
}
@@ -681,6 +684,11 @@ public class EntityRule {
return;
case TYPE_LOCAL_ONLY:
return;
case TYPE_NOTES:
String notes = jargs.optString("notes");
if (TextUtils.isEmpty(notes))
throw new IllegalArgumentException(context.getString(R.string.title_rule_notes_missing));
return;
default:
throw new IllegalArgumentException("Unknown rule type=" + type);
}
@@ -1317,6 +1325,16 @@ public class EntityRule {
return true;
}
private boolean onActionNotes(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
String notes = jargs.getString("notes");
Integer color = (jargs.has("color") ? jargs.getInt("color") : null);
DB db = DB.getInstance(context);
db.message().setMessageNotes(message.id, notes, color);
return true;
}
private static Calendar getRelativeCalendar(boolean all, int minutes, long reference) {
int d = minutes / (24 * 60);
int h = minutes / 60 % 24;