Simplify a bit more LoopPlugin

This commit is contained in:
Philoul 2021-08-29 22:24:52 +02:00
parent 8770cfa4ad
commit c00000e079

View file

@ -35,6 +35,7 @@ import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.extensions.toVisibility import info.nightscout.androidaps.extensions.toVisibility
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -60,6 +61,7 @@ class LoopDialog : DaggerDialogFragment() {
@Inject lateinit var uel: UserEntryLogger @Inject lateinit var uel: UserEntryLogger
@Inject lateinit var dateUtil: DateUtil @Inject lateinit var dateUtil: DateUtil
@Inject lateinit var repository: AppRepository @Inject lateinit var repository: AppRepository
@Inject lateinit var objectivePlugin: ObjectivesPlugin
private var showOkCancel: Boolean = true private var showOkCancel: Boolean = true
private var _binding: DialogLoopBinding? = null private var _binding: DialogLoopBinding? = null
@ -159,6 +161,7 @@ class LoopDialog : DaggerDialogFragment() {
aapsLogger.debug("UpdateGUI from $from") aapsLogger.debug("UpdateGUI from $from")
val pumpDescription: PumpDescription = activePlugin.activePump.pumpDescription val pumpDescription: PumpDescription = activePlugin.activePump.pumpDescription
val closedLoopAllowed = constraintChecker.isClosedLoopAllowed(Constraint(true)) val closedLoopAllowed = constraintChecker.isClosedLoopAllowed(Constraint(true))
val closedLoopAllowed2 = objectivePlugin.objectives[ObjectivesPlugin.MAXIOB_OBJECTIVE].isCompleted
val lgsEnabled = constraintChecker.isLgsAllowed(Constraint(true)) val lgsEnabled = constraintChecker.isLgsAllowed(Constraint(true))
val apsMode = sp.getString(R.string.key_aps_mode, "open") val apsMode = sp.getString(R.string.key_aps_mode, "open")
val pump = activePlugin.activePump val pump = activePlugin.activePump
@ -178,15 +181,6 @@ class LoopDialog : DaggerDialogFragment() {
binding.overviewPump.visibility = View.GONE binding.overviewPump.visibility = View.GONE
} }
!loopPlugin.isEnabled(PluginType.LOOP) -> {
binding.overviewLoop.visibility = View.VISIBLE
binding.overviewEnable.visibility = View.VISIBLE
binding.overviewDisable.visibility = View.GONE
binding.overviewSuspend.visibility = View.GONE
binding.overviewPump.visibility = View.VISIBLE
binding.overviewReconnect.visibility = View.GONE
}
loopPlugin.isDisconnected -> { loopPlugin.isDisconnected -> {
binding.overviewLoop.visibility = View.GONE binding.overviewLoop.visibility = View.GONE
binding.overviewSuspend.visibility = View.GONE binding.overviewSuspend.visibility = View.GONE
@ -196,6 +190,15 @@ class LoopDialog : DaggerDialogFragment() {
binding.overviewReconnect.visibility = View.VISIBLE binding.overviewReconnect.visibility = View.VISIBLE
} }
!loopPlugin.isEnabled(PluginType.LOOP) -> {
binding.overviewLoop.visibility = View.VISIBLE
binding.overviewEnable.visibility = View.VISIBLE
binding.overviewDisable.visibility = View.GONE
binding.overviewSuspend.visibility = View.GONE
binding.overviewPump.visibility = View.VISIBLE
binding.overviewReconnect.visibility = View.GONE
}
loopPlugin.isSuspended -> { loopPlugin.isSuspended -> {
binding.overviewLoop.visibility = View.GONE binding.overviewLoop.visibility = View.GONE
binding.overviewSuspend.visibility = View.VISIBLE binding.overviewSuspend.visibility = View.VISIBLE
@ -210,24 +213,24 @@ class LoopDialog : DaggerDialogFragment() {
binding.overviewLoop.visibility = View.VISIBLE binding.overviewLoop.visibility = View.VISIBLE
binding.overviewEnable.visibility = View.GONE binding.overviewEnable.visibility = View.GONE
when { when {
closedLoopAllowed.value() -> { apsMode == "closed" -> {
binding.overviewCloseloop.visibility = (apsMode != "closed").toVisibility() binding.overviewCloseloop.visibility = View.GONE
binding.overviewLgsloop.visibility = (apsMode != "lgs").toVisibility() binding.overviewLgsloop.visibility = View.VISIBLE
binding.overviewOpenloop.visibility = (apsMode != "open").toVisibility() binding.overviewOpenloop.visibility = View.VISIBLE
}
apsMode == "lgs" -> {
binding.overviewCloseloop.visibility = closedLoopAllowed.value().toVisibility() //show Close loop button only if Close loop allowed
binding.overviewLgsloop.visibility = View.GONE
binding.overviewOpenloop.visibility = View.VISIBLE
} }
apsMode == "open" -> { apsMode == "open" -> {
binding.overviewCloseloop.visibility = View.VISIBLE binding.overviewCloseloop.visibility = closedLoopAllowed2.toVisibility() //show CloseLoop button only if Objective 6 is completed (closedLoopAllowed always false in open loop mode)
binding.overviewLgsloop.visibility = View.GONE binding.overviewLgsloop.visibility = lgsEnabled.value().toVisibility()
binding.overviewOpenloop.visibility = View.GONE binding.overviewOpenloop.visibility = View.GONE
} }
lgsEnabled.value() -> {
binding.overviewCloseloop.visibility = View.GONE
binding.overviewLgsloop.visibility = (apsMode != "lgs").toVisibility()
binding.overviewOpenloop.visibility = (apsMode != "open").toVisibility()
}
else -> { else -> {
binding.overviewCloseloop.visibility = View.GONE binding.overviewCloseloop.visibility = View.GONE
binding.overviewLgsloop.visibility = View.GONE binding.overviewLgsloop.visibility = View.GONE
@ -247,7 +250,6 @@ class LoopDialog : DaggerDialogFragment() {
} }
} }
/************************************************************************************************** /**************************************************************************************************
val profile = profileFunction.getProfile() val profile = profileFunction.getProfile()
val profileStore = activePlugin.activeProfileSource.profile val profileStore = activePlugin.activeProfileSource.profile
@ -258,7 +260,6 @@ class LoopDialog : DaggerDialogFragment() {
return return
} }
**************************************************************************************************/ **************************************************************************************************/
} }
private fun onClickOkCancelEnabled(v: View): Boolean { private fun onClickOkCancelEnabled(v: View): Boolean {