From b38ca31df5fa4009875931c6fb98fc97e1ededce Mon Sep 17 00:00:00 2001 From: Jens Date: Tue, 9 Jan 2024 22:56:42 +0100 Subject: [PATCH] Calendar trigger --- .../automation2/receivers/CalendarReceiver.java | 13 ++++++------- .../activity_manage_action_close_notification.xml | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java b/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java index 0bf3fac..50f777b 100644 --- a/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java +++ b/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java @@ -46,7 +46,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis static TimerTask timerTask = null; static Calendar nextWakeup = null; static AlarmManager alarmManager = null; - static boolean wakeupNeedsToBeScheduled = false; + static boolean wakeupNeedsToBeScheduledOrRescheduled = false; public static class RuleEventPair { @@ -94,8 +94,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis calendarEventsCache = null; calendarEventsReoccurringCache = null; - checkForRules(context); - armOrRearmTimer(); + routineAtAlarm(); } else if(intent.getAction().equalsIgnoreCase(calendarAlarmAction)) { @@ -466,7 +465,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis } // If it's now filled, go on - if(nextWakeup != null && wakeupNeedsToBeScheduled) + if(nextWakeup != null && wakeupNeedsToBeScheduledOrRescheduled) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -482,7 +481,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis } Miscellaneous.logEvent("i", "armOrRearmTimer()", "Scheduling wakeup for calendar at " + Miscellaneous.formatDate(nextWakeup.getTime()), 4); alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextWakeup.getTimeInMillis(), pi); - wakeupNeedsToBeScheduled = false; + wakeupNeedsToBeScheduledOrRescheduled = false; } } else @@ -543,8 +542,8 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis else Miscellaneous.logEvent("i", "calculateNextWakeupForCalendar()", "Chose " + Miscellaneous.formatDate(newAlarm.getTime()) + " as next wakeup for calendar triggers. Old was " + Miscellaneous.formatDate(nextWakeup.getTime()), 4); nextWakeup = newAlarm; - if (!wakeupNeedsToBeScheduled) - wakeupNeedsToBeScheduled = true; + if (!wakeupNeedsToBeScheduledOrRescheduled) + wakeupNeedsToBeScheduledOrRescheduled = true; } else Miscellaneous.logEvent("i", "calculateNextWakeupForCalendar()", "Alarm " + Miscellaneous.formatDate(nextWakeup.getTime()) + " has been selected as next wakeup, but not rescheduling since this was not a change.", 4); diff --git a/app/src/main/res/layout/activity_manage_action_close_notification.xml b/app/src/main/res/layout/activity_manage_action_close_notification.xml index 4cf4ebc..43b2180 100644 --- a/app/src/main/res/layout/activity_manage_action_close_notification.xml +++ b/app/src/main/res/layout/activity_manage_action_close_notification.xml @@ -180,6 +180,7 @@ android:id="@+id/rbNotificationDismissSimple" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:checked="true" android:text="@string/simplyDismissNotification" />