Merge pull request #634 from Philoul/Fix_DisableLoop
Fix Overview LoopDialog (Disable Loop)
This commit is contained in:
commit
56a0c97e96
|
@ -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,80 +161,94 @@ 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")
|
||||||
if (profileFunction.isProfileValid("LoopDialogUpdateGUI")) {
|
val pump = activePlugin.activePump
|
||||||
if (loopPlugin.isEnabled()) {
|
|
||||||
|
binding.overviewDisconnect15m.visibility = pumpDescription.tempDurationStep15mAllowed.toVisibility()
|
||||||
|
binding.overviewDisconnect30m.visibility = pumpDescription.tempDurationStep30mAllowed.toVisibility()
|
||||||
|
when {
|
||||||
|
pump.isSuspended() -> {
|
||||||
|
binding.overviewLoop.visibility = View.GONE
|
||||||
|
binding.overviewSuspend.visibility = View.GONE
|
||||||
|
binding.overviewPump.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
!profileFunction.isProfileValid("LoopDialogUpdateGUI") -> {
|
||||||
|
binding.overviewLoop.visibility = View.GONE
|
||||||
|
binding.overviewSuspend.visibility = View.GONE
|
||||||
|
binding.overviewPump.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
loopPlugin.isDisconnected -> {
|
||||||
|
binding.overviewLoop.visibility = View.GONE
|
||||||
|
binding.overviewSuspend.visibility = View.GONE
|
||||||
|
binding.overviewPump.visibility = View.VISIBLE
|
||||||
|
binding.overviewPumpHeader.text = resourceHelper.gs(R.string.reconnect)
|
||||||
|
binding.overviewDisconnectButtons.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 -> {
|
||||||
|
binding.overviewLoop.visibility = View.GONE
|
||||||
|
binding.overviewSuspend.visibility = View.VISIBLE
|
||||||
|
binding.overviewSuspendHeader.text = resourceHelper.gs(R.string.resumeloop)
|
||||||
|
binding.overviewSuspendButtons.visibility = View.VISIBLE
|
||||||
|
binding.overviewResume.visibility = View.VISIBLE
|
||||||
|
binding.overviewPump.visibility = View.GONE
|
||||||
|
binding.overviewReconnect.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
binding.overviewLoop.visibility = View.VISIBLE
|
||||||
|
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
|
||||||
binding.overviewOpenloop.visibility = View.GONE
|
binding.overviewOpenloop.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.overviewEnable.visibility = View.GONE
|
binding.overviewSuspend.visibility = View.VISIBLE
|
||||||
binding.overviewDisable.visibility = View.VISIBLE
|
binding.overviewSuspendHeader.text = resourceHelper.gs(R.string.suspendloop)
|
||||||
if (!loopPlugin.isSuspended) {
|
binding.overviewSuspendButtons.visibility = View.VISIBLE
|
||||||
binding.overviewSuspendHeader.text = resourceHelper.gs(R.string.suspendloop)
|
binding.overviewResume.visibility = View.GONE
|
||||||
binding.overviewResume.visibility = View.GONE
|
|
||||||
binding.overviewSuspendButtons.visibility = View.VISIBLE
|
binding.overviewPump.visibility = View.VISIBLE
|
||||||
binding.overviewSuspend.visibility = View.VISIBLE
|
binding.overviewPumpHeader.text = resourceHelper.gs(R.string.disconnectpump)
|
||||||
} else {
|
binding.overviewDisconnectButtons.visibility = View.VISIBLE
|
||||||
if (!loopPlugin.isDisconnected) {
|
binding.overviewReconnect.visibility = View.GONE
|
||||||
binding.overviewSuspendHeader.text = resourceHelper.gs(R.string.resumeloop)
|
|
||||||
binding.overviewResume.visibility = View.VISIBLE
|
|
||||||
binding.overviewSuspendButtons.visibility = View.GONE
|
|
||||||
binding.overviewSuspend.visibility = View.VISIBLE
|
|
||||||
} else
|
|
||||||
binding.overviewSuspend.visibility = View.GONE
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
binding.overviewEnable.visibility = View.VISIBLE
|
|
||||||
binding.overviewDisable.visibility = View.GONE
|
|
||||||
binding.overviewSuspend.visibility = View.GONE
|
|
||||||
if (!loopPlugin.isDisconnected) {
|
|
||||||
binding.overviewPumpHeader.text = resourceHelper.gs(R.string.disconnectpump)
|
|
||||||
binding.overviewDisconnect15m.visibility =
|
|
||||||
pumpDescription.tempDurationStep15mAllowed.toVisibility()
|
|
||||||
binding.overviewDisconnect30m.visibility =
|
|
||||||
pumpDescription.tempDurationStep30mAllowed.toVisibility()
|
|
||||||
binding.overviewDisconnectButtons.visibility = View.VISIBLE
|
|
||||||
binding.overviewReconnect.visibility = View.GONE
|
|
||||||
} else {
|
|
||||||
binding.overviewPumpHeader.text = resourceHelper.gs(R.string.reconnect)
|
|
||||||
binding.overviewDisconnectButtons.visibility = View.GONE
|
|
||||||
binding.overviewReconnect.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
binding.overviewLoop.visibility = (!loopPlugin.isSuspended && !loopPlugin.isDisconnected).toVisibility()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val profile = profileFunction.getProfile()
|
|
||||||
val profileStore = activePlugin.activeProfileSource.profile
|
|
||||||
|
|
||||||
if (profile == null || profileStore == null) {
|
|
||||||
ToastUtils.showToastInUiThread(ctx, resourceHelper.gs(R.string.noprofile))
|
|
||||||
dismiss()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onClickOkCancelEnabled(v: View): Boolean {
|
private fun onClickOkCancelEnabled(v: View): Boolean {
|
||||||
|
|
|
@ -275,6 +275,7 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/overview_pump"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
Loading…
Reference in a new issue