Add Closed / LGS / Open switching in Loop paragraph

This commit is contained in:
Philoul 2020-12-27 15:32:12 +01:00
parent b4710b4936
commit 08ab436d90
3 changed files with 170 additions and 51 deletions

View file

@ -2,22 +2,29 @@ package info.nightscout.androidaps.dialogs
import android.content.Intent
import android.os.Bundle
import android.view.*
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager
import androidx.fragment.app.FragmentManager
import dagger.android.support.DaggerDialogFragment
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification
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.*
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
@ -36,7 +43,9 @@ 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
@Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin
@ -71,6 +80,9 @@ class LoopDialog : DaggerDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
updateGUI("LoopDialogOnViewCreated")
overview_closeloop?.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() }
overview_lgsloop?.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() }
overview_openloop?.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() }
overview_disable?.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() }
overview_enable?.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() }
overview_resume?.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() }
@ -106,11 +118,26 @@ class LoopDialog : DaggerDialogFragment() {
fun updateGUI(from: String) {
aapsLogger.debug("UpdateGUI from $from")
val pumpDescription: PumpDescription = activePlugin.activePump.pumpDescription
val closedLoopAllowed = objectivesPlugin.isClosedLoopAllowed(Constraint(true))
val lgsEnabled = objectivesPlugin.isLgsAllowed(Constraint(true))
var APSmode = sp.getString(R.string.key_aps_mode, "open")
if (profileFunction.isProfileValid("LoopDialogUpdateGUI")) {
if (loopPlugin.isEnabled(PluginType.LOOP)) {
if (closedLoopAllowed.value()) {
overview_closeloop?.visibility = if (APSmode == "closed") View.GONE else View.VISIBLE
overview_lgsloop?.visibility = if (APSmode == "lgs") View.GONE else View.VISIBLE
overview_openloop?.visibility = if (APSmode == "open") View.GONE else View.VISIBLE
} else if (lgsEnabled.value() ) {
overview_closeloop?.visibility = View.GONE
overview_lgsloop?.visibility = if (APSmode == "lgs") View.GONE else View.VISIBLE
overview_openloop?.visibility = if (APSmode == "open") View.GONE else View.VISIBLE
} else {
overview_closeloop?.visibility = View.GONE
overview_lgsloop?.visibility = View.GONE
overview_openloop?.visibility = View.GONE
}
overview_enable?.visibility = View.GONE //sp.getBoolean(R.string.key_usesuperbolus, false).toVisibility()
overview_disable?.visibility = View.VISIBLE
overview_loop_header?.text = resourceHelper.gs(R.string.disableloop)
if (!loopPlugin.isSuspended) {
overview_suspend_header?.text=resourceHelper.gs(R.string.suspendloop)
overview_resume?.visibility = View.GONE
@ -128,7 +155,6 @@ class LoopDialog : DaggerDialogFragment() {
} else {
overview_enable?.visibility = View.VISIBLE
overview_disable?.visibility = View.GONE
overview_loop_header?.text = resourceHelper.gs(R.string.enableloop)
overview_suspend?.visibility = View.GONE
}
if (!loopPlugin.isDisconnected) {
@ -157,6 +183,9 @@ class LoopDialog : DaggerDialogFragment() {
fun onClick_OkCancelEnabled(v: View): Boolean {
var description = ""
when(v.id) {
R.id.overview_closeloop -> description = resourceHelper.gs(R.string.closedloop)
R.id.overview_lgsloop -> description = resourceHelper.gs(R.string.lowglucosesuspend)
R.id.overview_openloop -> description = resourceHelper.gs(R.string.openloop)
R.id.overview_disable -> description = resourceHelper.gs(R.string.disableloop)
R.id.overview_enable -> description = resourceHelper.gs(R.string.enableloop)
R.id.overview_resume -> description = resourceHelper.gs(R.string.resume)
@ -182,6 +211,18 @@ class LoopDialog : DaggerDialogFragment() {
fun onClick(v: View): Boolean {
val profile = profileFunction.getProfile() ?: return true
when (v.id) {
R.id.overview_closeloop -> {
sp.putString(R.string.key_aps_mode, "closed")
rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.closedloop)))
}
R.id.overview_lgsloop -> {
sp.putString(R.string.key_aps_mode, "lgs")
rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.lowglucosesuspend)))
}
R.id.overview_openloop -> {
sp.putString(R.string.key_aps_mode, "open")
rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.lowglucosesuspend)))
}
R.id.overview_disable -> {
aapsLogger.debug("USER ENTRY: LOOP DISABLED")
loopPlugin.setPluginEnabled(PluginType.LOOP, false)

View file

@ -163,6 +163,12 @@ class ObjectivesPlugin @Inject constructor(
return value
}
fun isLgsAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
if (!objectives[MAXBASAL_OBJECTIVE].isStarted)
value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), MAXBASAL_OBJECTIVE + 1), this)
return value
}
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
if (!objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted)
value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), MAXIOB_ZERO_CL_OBJECTIVE + 1), this)

View file

@ -62,13 +62,68 @@
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/disableloop"
android:text="@string/loop"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="@+id/overview_loop_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/overview_closeloop"
style="?android:attr/buttonStyle"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginEnd="-4dp"
android:layout_weight="0.5"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:drawableTop="@drawable/ic_loop_closed"
android:text="@string/closedloop"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textSize="11sp"
android:visibility="gone" />
<info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/overview_lgsloop"
style="?android:attr/buttonStyle"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginEnd="-4dp"
android:layout_weight="0.5"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:drawableTop="@drawable/ic_loop_lgs"
android:text="@string/lowglucosesuspend"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textSize="11sp"
android:visibility="gone" />
<info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/overview_openloop"
style="?android:attr/buttonStyle"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginEnd="-4dp"
android:layout_weight="0.5"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:drawableTop="@drawable/ic_loop_open"
android:text="@string/openloop"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textSize="11sp"
android:visibility="gone" />
<info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/overview_enable"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginEnd="-4dp"
@ -84,7 +139,7 @@
<info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/overview_disable"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginEnd="-4dp"
@ -98,6 +153,15 @@
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@color/listdelimiter" />
</LinearLayout>
<LinearLayout
android:id="@+id/overview_suspend"
@ -134,8 +198,9 @@
<LinearLayout
android:id="@+id/overview_suspend_buttons"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<info.nightscout.androidaps.utils.ui.SingleClickButton
@ -198,6 +263,14 @@
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@color/listdelimiter" />
</LinearLayout>
<LinearLayout
@ -233,8 +306,9 @@
<LinearLayout
android:id="@+id/overview_disconnect_buttons"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<info.nightscout.androidaps.utils.ui.SingleClickButton
@ -312,7 +386,6 @@
</LinearLayout>
<View
android:id="@+id/treatments_wizard_delimiter"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginStart="5dp"
@ -320,7 +393,6 @@
android:layout_marginBottom="5dp"
android:background="@color/listdelimiter" />
<Button
android:id="@+id/cancel"
style="@style/mdtp_ActionButton.Text"