From b1b318dd5e596338aa94dfe608f0f0ff3ff027d7 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 16 Feb 2021 11:46:34 +0100 Subject: [PATCH] fix LoopDialog --- .../androidaps/dialogs/LoopDialog.kt | 12 ++- .../objectives/ObjectivesPlugin.kt | 2 +- .../interfaces/ConstraintsInterface.kt | 90 ++++--------------- 3 files changed, 22 insertions(+), 82 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 484e445136..0e11aea05d 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt @@ -22,7 +22,6 @@ import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.ToastUtils @@ -42,7 +41,6 @@ class LoopDialog : DaggerDialogFragment() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var loopPlugin: LoopPlugin - @Inject lateinit var objectivesPlugin: ObjectivesPlugin @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var constraintChecker: ConstraintChecker @Inject lateinit var commandQueue: CommandQueueProvider @@ -107,7 +105,7 @@ class LoopDialog : DaggerDialogFragment() { binding.cancel.setOnClickListener { dismiss() } refreshDialog = Runnable { - scheduleUpdateGUI("refreshDialog") + scheduleUpdateGUI() loopHandler.postDelayed(refreshDialog, 15 * 1000L) } loopHandler.postDelayed(refreshDialog, 15 * 1000L) @@ -122,11 +120,11 @@ class LoopDialog : DaggerDialogFragment() { var task: Runnable? = null - private fun scheduleUpdateGUI(from: String) { + private fun scheduleUpdateGUI() { class UpdateRunnable : Runnable { override fun run() { - updateGUI(from) + updateGUI("refreshDialog") task = null } } @@ -140,8 +138,8 @@ class LoopDialog : DaggerDialogFragment() { if (_binding == null) return aapsLogger.debug("UpdateGUI from $from") val pumpDescription: PumpDescription = activePlugin.activePump.pumpDescription - val closedLoopAllowed = objectivesPlugin.isClosedLoopAllowed(Constraint(true)) - val lgsEnabled = objectivesPlugin.isLgsAllowed(Constraint(true)) + val closedLoopAllowed = constraintChecker.isClosedLoopAllowed(Constraint(true)) + val lgsEnabled = constraintChecker.isLgsAllowed(Constraint(true)) val apsMode = sp.getString(R.string.key_aps_mode, "open") if (profileFunction.isProfileValid("LoopDialogUpdateGUI")) { if (loopPlugin.isEnabled(PluginType.LOOP)) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt index c5b836ac71..561760abe7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt @@ -165,7 +165,7 @@ class ObjectivesPlugin @Inject constructor( return value } - fun isLgsAllowed(value: Constraint): Constraint { + override fun isLgsAllowed(value: Constraint): Constraint { if (!objectives[MAXBASAL_OBJECTIVE].isStarted) value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), MAXBASAL_OBJECTIVE + 1), this) return value diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.kt index 1afa1f4738..7142bf251a 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.kt @@ -7,78 +7,20 @@ import info.nightscout.androidaps.data.Profile */ interface ConstraintsInterface { - @JvmDefault - fun isLoopInvocationAllowed(value: Constraint): Constraint { - return value - } - - @JvmDefault - fun isClosedLoopAllowed(value: Constraint): Constraint { - return value - } - - @JvmDefault - fun isAutosensModeEnabled(value: Constraint): Constraint { - return value - } - - @JvmDefault - fun isAMAModeEnabled(value: Constraint): Constraint { - return value - } - - @JvmDefault - fun isSMBModeEnabled(value: Constraint): Constraint { - return value - } - - @JvmDefault - fun isUAMEnabled(value: Constraint): Constraint { - return value - } - - @JvmDefault - fun isAdvancedFilteringEnabled(value: Constraint): Constraint { - return value - } - - @JvmDefault - fun isSuperBolusEnabled(value: Constraint): Constraint { - return value - } - - @JvmDefault - fun applyBasalConstraints(absoluteRate: Constraint, profile: Profile): Constraint { - return absoluteRate - } - - @JvmDefault - fun applyBasalPercentConstraints(percentRate: Constraint, profile: Profile): Constraint { - return percentRate - } - - @JvmDefault - fun applyBolusConstraints(insulin: Constraint): Constraint { - return insulin - } - - @JvmDefault - fun applyExtendedBolusConstraints(insulin: Constraint): Constraint { - return insulin - } - - @JvmDefault - fun applyCarbsConstraints(carbs: Constraint): Constraint { - return carbs - } - - @JvmDefault - fun applyMaxIOBConstraints(maxIob: Constraint): Constraint { - return maxIob - } - - @JvmDefault - fun isAutomationEnabled(value: Constraint): Constraint { - return value - } + @JvmDefault fun isLoopInvocationAllowed(value: Constraint): Constraint = value + @JvmDefault fun isClosedLoopAllowed(value: Constraint): Constraint = value + @JvmDefault fun isLgsAllowed(value: Constraint): Constraint = value + @JvmDefault fun isAutosensModeEnabled(value: Constraint): Constraint = value + @JvmDefault fun isAMAModeEnabled(value: Constraint): Constraint = value + @JvmDefault fun isSMBModeEnabled(value: Constraint): Constraint = value + @JvmDefault fun isUAMEnabled(value: Constraint): Constraint = value + @JvmDefault fun isAdvancedFilteringEnabled(value: Constraint): Constraint = value + @JvmDefault fun isSuperBolusEnabled(value: Constraint): Constraint = value + @JvmDefault fun applyBasalConstraints(absoluteRate: Constraint, profile: Profile): Constraint = absoluteRate + @JvmDefault fun applyBasalPercentConstraints(percentRate: Constraint, profile: Profile): Constraint = percentRate + @JvmDefault fun applyBolusConstraints(insulin: Constraint): Constraint = insulin + @JvmDefault fun applyExtendedBolusConstraints(insulin: Constraint): Constraint = insulin + @JvmDefault fun applyCarbsConstraints(carbs: Constraint): Constraint = carbs + @JvmDefault fun applyMaxIOBConstraints(maxIob: Constraint): Constraint = maxIob + @JvmDefault fun isAutomationEnabled(value: Constraint): Constraint = value } \ No newline at end of file