diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt index 1d7c37929f..eb6e39d0ac 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -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() }) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWEventListener.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWEventListener.kt index 9757cbca32..5a7806b9a7 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWEventListener.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWEventListener.kt @@ -11,7 +11,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable class SWEventListener constructor( - injector:HasAndroidInjector, + injector: HasAndroidInjector, clazz: Class ) : 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 + } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2b6e4788aa..e8fecced88 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1443,4 +1443,5 @@ Worker State: %s Uploaded Data 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. + RileyLink status: diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/events/EventRileyLinkDeviceStatusChange.kt b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/events/EventRileyLinkDeviceStatusChange.kt index b3425d14a5..59c084eb1f 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/events/EventRileyLinkDeviceStatusChange.kt +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/events/EventRileyLinkDeviceStatusChange.kt @@ -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) + } } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java index b4fb23d65f..b039e49c59 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java @@ -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