Calendar trigger

This commit is contained in:
jens 2024-01-14 15:56:44 +01:00
parent 553d14b05f
commit dfe8594f06
5 changed files with 17 additions and 38 deletions

View File

@ -734,7 +734,8 @@ public class Action
try try
{ {
url = Miscellaneous.replaceVariablesInText(url, context); url = Miscellaneous.replaceVariablesInText(url, context);
params = Miscellaneous.replaceVariablesInText(params, context); if(!StringUtils.isEmpty(params))
params = Miscellaneous.replaceVariablesInText(params, context);
Actions myAction = new Actions(); Actions myAction = new Actions();

View File

@ -735,7 +735,6 @@ public class Actions
if (method == null) if (method == null)
throw new NoSuchMethodException(); throw new NoSuchMethodException();
/* /*
* For some reason this doesn't work, throws NoSuchMethodExpection even if the method is present. * For some reason this doesn't work, throws NoSuchMethodExpection even if the method is present.
*/ */

View File

@ -257,7 +257,7 @@ public class ActivityManageActionTriggerUrl extends Activity
{ {
if(lvTriggerUrlPostParameters.getAdapter() == null) if(lvTriggerUrlPostParameters.getAdapter() == null)
lvTriggerUrlPostParameters.setAdapter(lvTriggerUrlPostParametersAdapter); lvTriggerUrlPostParameters.setAdapter(lvTriggerUrlPostParametersAdapter);
lvTriggerUrlPostParametersAdapter.notifyDataSetChanged(); lvTriggerUrlPostParametersAdapter.notifyDataSetChanged();
} }
catch(NullPointerException e) catch(NullPointerException e)

View File

@ -621,52 +621,31 @@ public class Trigger
{ {
try try
{ {
String[] conditions = this.getTriggerParameter2().split(Trigger.triggerParameter2Split);
List<CalendarReceiver.CalendarEvent> calendarEvents = CalendarReceiver.readCalendarEvents(AutomationService.getInstance(), true,false); List<CalendarReceiver.CalendarEvent> calendarEvents = CalendarReceiver.readCalendarEvents(AutomationService.getInstance(), true,false);
/*
0 = titleDirection
1 = title;
2 = descriptionDirection
3 = description
4 = eventLocationDirection
5 = eventLocation
6 = evaluate all day event
7 = all day event
8 = availabilityList
9 = calendarList
*/
for(CalendarReceiver.CalendarEvent event : calendarEvents) for(CalendarReceiver.CalendarEvent event : calendarEvents)
{ {
if(!checkCalendarEvent(event, ignoreActive)) if(!checkCalendarEvent(event, ignoreActive))
continue; continue;
// No contradictions found //TODO: This line alone does not suffice and might also not be correct in some cases
Miscellaneous.logEvent("i", "CalendarCheck", "Event " + event + " matches.", 4);
/*
At this point the rule will either get executed for this event or it already has been executed for it.
*/
CalendarReceiver.addUsedPair(new CalendarReceiver.RuleEventPair(getParentRule(), event)); CalendarReceiver.addUsedPair(new CalendarReceiver.RuleEventPair(getParentRule(), event));
return true; return true;
} }
// At this point none of the calendar items matches this trigger // At this point none of the calendar items match this trigger
// If trigger demands no calendar event and there is absolutely no future event, we'll need to check for that. /*
if(calendarEvents.size() == 0) If trigger demands no calendar event and there is absolutely no future event,
{ further criteria don't matter if there are no events to check.
if(getTriggerParameter() == false) */
return true; if(calendarEvents.size() == 0 && getTriggerParameter() == false)
return true;
// Further criteria don't matter if there are no events to check
}
} }
catch(Exception e) catch(Exception e)
{ {
Miscellaneous.logEvent("e", "checkVariable()", Log.getStackTraceString(e), 1); Miscellaneous.logEvent("e", "checkCalendarEvent()", Log.getStackTraceString(e), 1);
} }
return false; return false;

View File

@ -42,6 +42,9 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
static List<CalendarEvent> calendarEventsCache = null; static List<CalendarEvent> calendarEventsCache = null;
static List<CalendarEvent> calendarEventsReoccurringCache = null; static List<CalendarEvent> calendarEventsReoccurringCache = null;
// To determine for which events which rules have been executed
static List<RuleEventPair> calendarEventsUsed = new ArrayList<>();
static Timer timer = null; static Timer timer = null;
static TimerTask timerTask = null; static TimerTask timerTask = null;
static Calendar nextWakeup = null; static Calendar nextWakeup = null;
@ -59,8 +62,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
this.event = event; this.event = event;
} }
} }
// To determine for which events which rules have been executed
static List<RuleEventPair> calendarEventsUsed = new ArrayList<>();
public static void addUsedPair(RuleEventPair pair) public static void addUsedPair(RuleEventPair pair)
{ {
// Add pair only if it's not in the list already. // Add pair only if it's not in the list already.
@ -188,7 +190,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
@Override @Override
public String toString() public String toString()
{ {
return title; return "Title: " + title + ", location: " + location + ", description: " + description + ", start: " + Miscellaneous.formatDate(start.getTime()) + ", end: " + Miscellaneous.formatDate(end.getTime()) + ", is currently active: " + String.valueOf(isCurrentlyActive()) + ", all day: " + String.valueOf(allDay) + ", availability: " + availability;
} }
@Override @Override
@ -241,8 +243,6 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
// fetching calendars name // fetching calendars name
String CNames[] = new String[cursor.getCount()]; String CNames[] = new String[cursor.getCount()];
List<AndroidCalendar> calendarlist = new ArrayList<>();
for (int i = 0; i < CNames.length; i++) for (int i = 0; i < CNames.length; i++)
{ {
try try