Calendar trigger

This commit is contained in:
2024-01-14 23:18:12 +01:00
parent dfe8594f06
commit fe924f6fe9
3 changed files with 54 additions and 5 deletions

View File

@ -628,9 +628,6 @@ public class Trigger
if(!checkCalendarEvent(event, ignoreActive))
continue;
//TODO: This line alone does not suffice and might also not be correct in some cases
CalendarReceiver.addUsedPair(new CalendarReceiver.RuleEventPair(getParentRule(), event));
return true;
}

View File

@ -137,6 +137,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
}
clearCaches();
calendarEventsUsed.clear();
calendarReceiverActive = false;
}
@ -599,7 +600,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
return false;
}
static boolean hasEventBeenUsedInRule(Rule rule, CalendarEvent event)
public static boolean hasEventBeenUsedInRule(Rule rule, CalendarEvent event)
{
for (RuleEventPair executedPair : calendarEventsUsed)
{
@ -609,4 +610,32 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
return false;
}
public static List<CalendarReceiver.CalendarEvent> getApplyingCalendarEvents(Rule rule)
{
List<CalendarReceiver.CalendarEvent> returnList = new ArrayList<>();
try
{
List<CalendarReceiver.CalendarEvent> calendarEvents = CalendarReceiver.readCalendarEvents(AutomationService.getInstance(), true,false);
for(Trigger t : rule.getTriggerSet())
{
if(t.getTriggerType().equals(calendarEvents))
{
for (CalendarReceiver.CalendarEvent event : calendarEvents)
{
if (t.checkCalendarEvent(event, false))
returnList.add(event);
}
}
}
}
catch(Exception e)
{
Miscellaneous.logEvent("e", "getApplyingCalendarEvents()", Log.getStackTraceString(e), 1);
}
return returnList;
}
}