From 724b52e929d60300c2723f44e631d5079194fd04 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 23 Jan 2021 21:51:59 +0100 Subject: [PATCH] AutomationPlugin synchronized --- .../plugins/general/automation/AutomationPlugin.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt index 2f596cd2c6..86b28e6d6a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt @@ -200,7 +200,7 @@ class AutomationPlugin @Inject constructor( } aapsLogger.debug(LTag.AUTOMATION, "processActions") - val iterator = automationEvents.iterator() + val iterator : MutableIterator = automationEvents.iterator() while (iterator.hasNext()) { val event = iterator.next() if (event.isEnabled && event.shouldRun() && event.trigger.shouldRun() && event.getPreconditions().shouldRun()) { @@ -240,11 +240,13 @@ class AutomationPlugin @Inject constructor( storeToSP() // save last run time } + @Synchronized fun add(event: AutomationEvent) { automationEvents.add(event) rxBus.send(EventAutomationDataChanged()) } + @Synchronized fun addIfNotExists(event: AutomationEvent) { for (e in automationEvents) { if (event.title == e.title) return @@ -253,20 +255,24 @@ class AutomationPlugin @Inject constructor( rxBus.send(EventAutomationDataChanged()) } + @Synchronized fun set(event: AutomationEvent, index: Int) { automationEvents[index] = event rxBus.send(EventAutomationDataChanged()) } + @Synchronized fun removeAt(index: Int) { automationEvents.removeAt(index) rxBus.send(EventAutomationDataChanged()) } + @Synchronized fun at(index: Int) = automationEvents[index] fun size() = automationEvents.size + @Synchronized fun swap(fromPosition: Int, toPosition: Int) { Collections.swap(automationEvents, fromPosition, toPosition) rxBus.send(EventAutomationDataChanged())