From eb84f5e6a7bba7f1ac52d57df9b2cfdf83c64b6c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 3 Jan 2021 17:26:37 +0100 Subject: [PATCH] LoopDialog protection --- .../androidaps/dialogs/LoopDialog.kt | 3 ++ .../general/overview/OverviewFragment.kt | 50 ++++++++++--------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt index 109197e91a..cda4b6e0be 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt @@ -237,18 +237,21 @@ class LoopDialog : DaggerDialogFragment() { val profile = profileFunction.getProfile() ?: return true when (v.id) { R.id.overview_closeloop -> { + aapsLogger.debug("USER ENTRY: CLOSED LOOP MODE") sp.putString(R.string.key_aps_mode, "closed") rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.closedloop))) return true } R.id.overview_lgsloop -> { + aapsLogger.debug("USER ENTRY: LGS LOOP MODE") sp.putString(R.string.key_aps_mode, "lgs") rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.lowglucosesuspend))) return true } R.id.overview_openloop -> { + aapsLogger.debug("USER ENTRY: OPEN LOOP MODE") sp.putString(R.string.key_aps_mode, "open") rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.lowglucosesuspend))) return true diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 8609a19c33..28bd08d3d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -289,12 +289,12 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList R.id.overview_temptarget -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { TempTargetDialog().show(childFragmentManager, "Overview") }) R.id.overview_activeprofile -> { - val args = Bundle() - args.putLong("time", DateUtil.now()) - args.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal) - val pvd = ProfileViewerDialog() - pvd.arguments = args - pvd.show(childFragmentManager, "ProfileViewDialog") + ProfileViewerDialog().also { pvd -> + pvd.arguments = Bundle().also { + it.putLong("time", DateUtil.now()) + it.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal) + } + }.show(childFragmentManager, "ProfileViewDialog") } R.id.overview_cgmbutton -> { @@ -329,24 +329,26 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList val lastRun = loopPlugin.lastRun loopPlugin.invoke("Accept temp button", false) if (lastRun?.lastAPSRun != null && lastRun.constraintsProcessed?.isChangeRequested == true) { - OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.tempbasal_label), lastRun.constraintsProcessed?.toSpanned() - ?: "".toSpanned(), { - aapsLogger.debug("USER ENTRY: ACCEPT TEMP BASAL") - overview_accepttempbutton?.visibility = View.GONE - (context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).cancel(Constants.notificationID) - actionStringHandler.handleInitiate("cancelChangeRequest") - loopPlugin.acceptChangeRequest() + protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { + OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.tempbasal_label), lastRun.constraintsProcessed?.toSpanned() + ?: "".toSpanned(), { + aapsLogger.debug("USER ENTRY: ACCEPT TEMP BASAL") + overview_accepttempbutton?.visibility = View.GONE + (context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).cancel(Constants.notificationID) + actionStringHandler.handleInitiate("cancelChangeRequest") + loopPlugin.acceptChangeRequest() + }) }) } } } R.id.overview_apsmode -> { - val args = Bundle() - args.putInt("showOkCancel", 1) // 1-> true - val pvd = LoopDialog() - pvd.arguments = args - pvd.show(childFragmentManager, "Overview") + protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { + LoopDialog().also { dialog -> + dialog.arguments = Bundle().also { it.putInt("showOkCancel", 1) } + }.show(childFragmentManager, "Overview") + }) } } } @@ -374,11 +376,13 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } R.id.overview_apsmode -> { - val args = Bundle() - args.putInt("showOkCancel", 0) // 0-> false - val pvd = LoopDialog() - pvd.arguments = args - pvd.show(childFragmentManager, "Overview") + activity?.let { activity -> + protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { + LoopDialog().also { dialog -> + dialog.arguments = Bundle().also { it.putInt("showOkCancel", 0) } + }.show(childFragmentManager, "Overview") + }) + } } R.id.overview_temptarget -> v.performClick()