From 8b41abb3881d85496510fe025ec54b135e04e1b6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 16 Dec 2022 11:19:15 +0100 Subject: [PATCH] Fix scheduling alarm --- core/interfaces/src/main/AndroidManifest.xml | 2 +- .../nightscout/interfaces/utils/TimerUtil.kt | 28 --------------- .../nightscout/automation/AutomationPlugin.kt | 2 +- .../automation/actions/ActionAlarm.kt | 2 +- .../nightscout/automation/ui/TimerUtil.kt | 36 +++++++++++++++++++ .../src/main/res/values/strings.xml | 1 + .../automation/BolusTimerImplTest.kt | 2 +- .../automation/CarbTimerImplTest.kt | 2 +- .../automation/actions/ActionAlarmTest.kt | 2 +- .../data/ProcessedDeviceStatusDataImpl.kt | 2 +- 10 files changed, 44 insertions(+), 35 deletions(-) delete mode 100644 core/interfaces/src/main/java/info/nightscout/interfaces/utils/TimerUtil.kt create mode 100644 plugins/automation/src/main/java/info/nightscout/automation/ui/TimerUtil.kt diff --git a/core/interfaces/src/main/AndroidManifest.xml b/core/interfaces/src/main/AndroidManifest.xml index a5918e68ab..aebf62b711 100644 --- a/core/interfaces/src/main/AndroidManifest.xml +++ b/core/interfaces/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/utils/TimerUtil.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/utils/TimerUtil.kt deleted file mode 100644 index 9537964de0..0000000000 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/utils/TimerUtil.kt +++ /dev/null @@ -1,28 +0,0 @@ -package info.nightscout.interfaces.utils - -import android.content.Context -import android.content.Intent -import android.provider.AlarmClock -import info.nightscout.androidaps.annotations.OpenForTesting -import javax.inject.Inject -import javax.inject.Singleton - -@OpenForTesting -@Singleton -open class TimerUtil @Inject constructor( - private val context: Context -) { - - /** - * Schedule alarm in @seconds - */ - fun scheduleReminder(seconds: Int, text: String) { - Intent(AlarmClock.ACTION_SET_TIMER).apply { - flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK - putExtra(AlarmClock.EXTRA_LENGTH, seconds) - putExtra(AlarmClock.EXTRA_SKIP_UI, true) - putExtra(AlarmClock.EXTRA_MESSAGE, text) - context.startActivity(this) - } - } -} \ No newline at end of file diff --git a/plugins/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt b/plugins/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt index 996345a787..caaaea9eeb 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt @@ -53,7 +53,7 @@ import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.queue.Callback -import info.nightscout.interfaces.utils.TimerUtil +import info.nightscout.automation.ui.TimerUtil import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventBTChange diff --git a/plugins/automation/src/main/java/info/nightscout/automation/actions/ActionAlarm.kt b/plugins/automation/src/main/java/info/nightscout/automation/actions/ActionAlarm.kt index b8e65bc5df..eb87995ed2 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/actions/ActionAlarm.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/actions/ActionAlarm.kt @@ -12,7 +12,7 @@ import info.nightscout.interfaces.Config import info.nightscout.interfaces.pump.PumpEnactResult import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.utils.JsonHelper -import info.nightscout.interfaces.utils.TimerUtil +import info.nightscout.automation.ui.TimerUtil import info.nightscout.rx.bus.RxBus import info.nightscout.shared.utils.DateUtil import org.json.JSONObject diff --git a/plugins/automation/src/main/java/info/nightscout/automation/ui/TimerUtil.kt b/plugins/automation/src/main/java/info/nightscout/automation/ui/TimerUtil.kt new file mode 100644 index 0000000000..861e4ebf42 --- /dev/null +++ b/plugins/automation/src/main/java/info/nightscout/automation/ui/TimerUtil.kt @@ -0,0 +1,36 @@ +package info.nightscout.automation.ui + +import android.content.Context +import android.content.Intent +import android.provider.AlarmClock +import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.automation.R +import info.nightscout.core.ui.toast.ToastUtils +import javax.inject.Inject +import javax.inject.Singleton + +@OpenForTesting +@Singleton +open class TimerUtil @Inject constructor( + private val context: Context +) { + + /** + * Schedule alarm in android + * + * @param seconds + */ + fun scheduleReminder(seconds: Int, text: String) { + try { + Intent(AlarmClock.ACTION_SET_TIMER).apply { + flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK + putExtra(AlarmClock.EXTRA_LENGTH, seconds) + putExtra(AlarmClock.EXTRA_SKIP_UI, true) + putExtra(AlarmClock.EXTRA_MESSAGE, text) + context.startActivity(this) + } + } catch (e: Exception) { + ToastUtils.errorToast(context, R.string.error_setting_reminder) + } + } +} \ No newline at end of file diff --git a/plugins/automation/src/main/res/values/strings.xml b/plugins/automation/src/main/res/values/strings.xml index 7764be8f19..fb351e0ccc 100644 --- a/plugins/automation/src/main/res/values/strings.xml +++ b/plugins/automation/src/main/res/values/strings.xml @@ -134,5 +134,6 @@ Time to eat!\nRun Bolus wizard and do calculation again. Time to bolus!\nRun Bolus wizard and do calculation again. + Error while setting future alarm \ No newline at end of file diff --git a/plugins/automation/src/test/java/info/nightscout/automation/BolusTimerImplTest.kt b/plugins/automation/src/test/java/info/nightscout/automation/BolusTimerImplTest.kt index 799a48864d..bb8400695f 100644 --- a/plugins/automation/src/test/java/info/nightscout/automation/BolusTimerImplTest.kt +++ b/plugins/automation/src/test/java/info/nightscout/automation/BolusTimerImplTest.kt @@ -13,7 +13,7 @@ import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.ProfileFunction -import info.nightscout.interfaces.utils.TimerUtil +import info.nightscout.automation.ui.TimerUtil import info.nightscout.rx.bus.RxBus import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP diff --git a/plugins/automation/src/test/java/info/nightscout/automation/CarbTimerImplTest.kt b/plugins/automation/src/test/java/info/nightscout/automation/CarbTimerImplTest.kt index 00bb7d4451..1ab982527d 100644 --- a/plugins/automation/src/test/java/info/nightscout/automation/CarbTimerImplTest.kt +++ b/plugins/automation/src/test/java/info/nightscout/automation/CarbTimerImplTest.kt @@ -13,7 +13,7 @@ import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.ProfileFunction -import info.nightscout.interfaces.utils.TimerUtil +import info.nightscout.automation.ui.TimerUtil import info.nightscout.rx.bus.RxBus import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP diff --git a/plugins/automation/src/test/java/info/nightscout/automation/actions/ActionAlarmTest.kt b/plugins/automation/src/test/java/info/nightscout/automation/actions/ActionAlarmTest.kt index febd9d13d4..bde934f0dd 100644 --- a/plugins/automation/src/test/java/info/nightscout/automation/actions/ActionAlarmTest.kt +++ b/plugins/automation/src/test/java/info/nightscout/automation/actions/ActionAlarmTest.kt @@ -9,7 +9,7 @@ import info.nightscout.automation.elements.InputString import info.nightscout.interfaces.Config import info.nightscout.interfaces.pump.PumpEnactResult import info.nightscout.interfaces.queue.Callback -import info.nightscout.interfaces.utils.TimerUtil +import info.nightscout.automation.ui.TimerUtil import info.nightscout.rx.bus.RxBus import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.utils.DateUtil diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/ProcessedDeviceStatusDataImpl.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/ProcessedDeviceStatusDataImpl.kt index 29de582b6c..d9051596f0 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/ProcessedDeviceStatusDataImpl.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/ProcessedDeviceStatusDataImpl.kt @@ -58,7 +58,7 @@ class ProcessedDeviceStatusDataImpl @Inject constructor( else -> ProcessedDeviceStatusData.Levels.INFO } string.append("") - val insulinUnit = rh.gs(info.nightscout.core.ui.R.string.insulin_unit_shortname) + // val insulinUnit = rh.gs(info.nightscout.core.ui.R.string.insulin_unit_shortname) val fields = nsSettingsStatus.pumpExtendedSettingsFields() // Removed here. Same value is in StatusLights // if (pumpData.reservoirDisplayOverride != "") string.append(pumpData.reservoirDisplayOverride).append("$insulinUnit ")