Improve Setup Wizard for Omnipod

This commit is contained in:
Bart Sopers 2020-10-17 19:47:39 +02:00
parent e58fa0aff6
commit f64cc66298
5 changed files with 41 additions and 8 deletions

View file

@ -30,6 +30,7 @@ import info.nightscout.androidaps.plugins.profile.local.LocalProfileFragment
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin
import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin
import info.nightscout.androidaps.setupwizard.elements.*
import info.nightscout.androidaps.setupwizard.events.EventSWUpdate
@ -324,6 +325,12 @@ class SWDefinition @Inject constructor(
val activePump = activePlugin.activePump
activePump is OmnipodPumpPlugin && !activePump.isRileyLinkReady
}))
.add( // Omnipod only
SWEventListener(injector, EventRileyLinkDeviceStatusChange::class.java)
.label(R.string.setupwizard_pump_riley_link_status)
.visibility(SWValidator {
activePlugin.activePump is OmnipodPumpPlugin
}))
.add(SWButton(injector)
.text(R.string.readstatus)
.action(Runnable { commandQueue.readStatus("Clicked connect to pump", null) })
@ -332,7 +339,8 @@ class SWDefinition @Inject constructor(
// Getting the status might not be possible
activePlugin.activePump !is OmnipodPumpPlugin
}))
.add(SWEventListener(injector, EventPumpStatusChanged::class.java))
.add(SWEventListener(injector, EventPumpStatusChanged::class.java)
.visibility(SWValidator { activePlugin.activePump !is OmnipodPumpPlugin }))
.validator(SWValidator {
isPumpInitialized()
})

View file

@ -11,7 +11,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
class SWEventListener constructor(
injector:HasAndroidInjector,
injector: HasAndroidInjector,
clazz: Class<out EventStatus>
) : SWItem(injector, Type.LISTENER) {
@ -19,6 +19,7 @@ class SWEventListener constructor(
private var textLabel = 0
private var status = ""
private var textView: TextView? = null
private var visibilityValidator: SWValidator? = null
// TODO: Adrian how to clear disposable in this case?
init {
@ -43,6 +44,11 @@ class SWEventListener constructor(
return this
}
fun visibility(visibilityValidator: SWValidator): SWEventListener {
this.visibilityValidator = visibilityValidator
return this
}
@SuppressLint("SetTextI18n")
override fun generateDialog(layout: LinearLayout) {
val context = layout.context
@ -51,4 +57,8 @@ class SWEventListener constructor(
textView?.text = (if (textLabel != 0) resourceHelper.gs(textLabel) else "") + " " + status
layout.addView(textView)
}
override fun processVisibility() {
if (visibilityValidator != null && !visibilityValidator!!.isValid) textView?.visibility = View.GONE else textView?.visibility = View.VISIBLE
}
}

View file

@ -1443,4 +1443,5 @@
<string name="worker_state">Worker State: %s</string>
<string name="uploaded_data">Uploaded Data</string>
<string name="the_following_data_will_be_uploaded_to_your_open_humans_account">The following data will be uploaded to your Open Humans account: Glucose values, boluses, carbs, careportal events (except notes), extended boluses, profile switches, total daily doses, temporary basals, temp targets, preferences, application version, device model and screen dimensions. Secret or private information such as your Nightscout URL or API secret will not be uploaded.</string>
<string name="setupwizard_pump_riley_link_status">RileyLink status:</string>
</resources>

View file

@ -1,11 +1,13 @@
package info.nightscout.androidaps.plugins.pump.common.events
import info.nightscout.androidaps.events.Event
import info.nightscout.androidaps.events.EventStatus
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice
import info.nightscout.androidaps.utils.resources.ResourceHelper
open class EventRileyLinkDeviceStatusChange : Event {
open class EventRileyLinkDeviceStatusChange : EventStatus {
var rileyLinkServiceState: RileyLinkServiceState? = null
var rileyLinkError: RileyLinkError? = null
@ -14,10 +16,8 @@ open class EventRileyLinkDeviceStatusChange : Event {
var errorDescription: String? = null
constructor() {
}
constructor(rileyLinkServiceState: RileyLinkServiceState?, rileyLinkError: RileyLinkError?) {
this.rileyLinkServiceState = rileyLinkServiceState
this.rileyLinkError = rileyLinkError
@ -31,4 +31,16 @@ open class EventRileyLinkDeviceStatusChange : Event {
this.pumpDeviceState = pumpDeviceState
this.errorDescription = errorDescription
}
override fun getStatus(resourceHelper: ResourceHelper): String {
val rileyLinkServiceState = this.rileyLinkServiceState ?: return ""
val resourceId = rileyLinkServiceState.resourceId
val rileyLinkError = this.rileyLinkError
if (rileyLinkServiceState.isError && rileyLinkError != null) {
return resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.Omnipod))
}
return resourceHelper.gs(resourceId)
}
}

View file

@ -24,8 +24,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.Rile
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceResult;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -114,6 +112,10 @@ public abstract class RileyLinkService extends DaggerService {
public abstract RileyLinkCommunicationManager getDeviceCommunicationManager();
public RileyLinkServiceState getRileyLinkServiceState() {
return rileyLinkServiceData == null ? null : rileyLinkServiceData.rileyLinkServiceState;
}
// Here is where the wake-lock begins:
// We've received a service startCommand, we grab the lock.
@Override