From c9dcac6368ed3f90d914f65d0f43222620693900 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Sun, 23 Aug 2020 13:06:42 +0200 Subject: [PATCH] Improve Pod Status display --- .../plugins/pump/omnipod/OmnipodFragment.kt | 76 ++++++++++++------- .../omnipod/defs/state/PodStateManager.java | 2 +- omnipod/src/main/res/values/strings.xml | 13 ++-- 3 files changed, 57 insertions(+), 34 deletions(-) diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt index 30e3d1360f..9d5cfdb3ab 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt @@ -148,8 +148,6 @@ class OmnipodFragment : DaggerFragment() { }) } } - - omnipod_lastconnection.setTextColor(Color.WHITE) } override fun onResume() { @@ -230,6 +228,7 @@ class OmnipodFragment : DaggerFragment() { fun updateOmipodUiElements() { updateLastConnectionUiElements() updateAcknowledgeAlertsUiElements() + updatePodStatusUiElements() setVisibilityOfPodDebugButton() val errors = ArrayList(); @@ -253,11 +252,6 @@ class OmnipodFragment : DaggerFragment() { omnipod_tempbasal.text = "-" omnipod_lastbolus.text = "-" omnipod_lastconnection.setTextColor(Color.WHITE) - if (podStateManager.hasPodState()) { - omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_not_initalized) - } else { - omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_no_pod_connected) - } } else { omnipod_pod_address.text = podStateManager.address.toString() omnipod_pod_lot.text = podStateManager.lot.toString() @@ -266,25 +260,10 @@ class OmnipodFragment : DaggerFragment() { val expiresAt = podStateManager.expiresAt omnipod_pod_expiry.text = if (expiresAt == null) "???" else dateUtil.dateAndTimeString(expiresAt.toDate()) - val stateText: String - when { - podStateManager.hasFaultEvent() -> { - val faultEventCode = podStateManager.faultEvent.faultEventCode - stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_fault) - errors.add(resourceHelper.gs(R.string.omnipod_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name)) - } - - podStateManager.isPodRunning -> { - stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_running, if (podStateManager.lastDeliveryStatus == null) null else podStateManager.lastDeliveryStatus.name) - } - - else -> { - stateText = resourceHelper.gs(R.string.omnipod_pod_setup_in_progress, podStateManager.podProgressStatus.name) - } + if (podStateManager.hasFaultEvent()) { + val faultEventCode = podStateManager.faultEvent.faultEventCode + errors.add(resourceHelper.gs(R.string.omnipod_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name)) } - omnipod_pod_status.text = stateText - - updateLastConnectionUiElements() // last bolus if (podStateManager.lastBolusStartTime != null && podStateManager.lastBolusAmount != null) { @@ -310,8 +289,13 @@ class OmnipodFragment : DaggerFragment() { } } - omnipod_pod_status.setTextColor(if (podStateManager.hasFaultEvent()) Color.RED else Color.WHITE) - omnipod_errors.text = if (errors.size == 0) "-" else StringUtils.join(errors, System.lineSeparator()) + if (errors.size == 0) { + omnipod_errors.text = "-" + omnipod_errors.setTextColor(Color.WHITE) + } else { + omnipod_errors.text = StringUtils.join(errors, System.lineSeparator()) + omnipod_errors.setTextColor(Color.RED) + } val status = commandQueue.spannedStatus() if (status.toString() == "") { @@ -346,6 +330,44 @@ class OmnipodFragment : DaggerFragment() { } } + private fun updatePodStatusUiElements() { + if (!podStateManager.hasPodState()) { + omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_no_active_pod) + } else if (!podStateManager.isPodActivationCompleted) { + if (!podStateManager.isPodInitialized) { + omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_waiting_for_pair_and_prime) + } else { + if (PodProgressStatus.ACTIVATION_TIME_EXCEEDED == podStateManager.podProgressStatus) { + omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_activation_time_exceeded) + } else if (podStateManager.podProgressStatus.isBefore(PodProgressStatus.PRIMING_COMPLETED)) { + omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_waiting_for_pair_and_prime) + } else { + omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_waiting_for_cannula_insertion) + } + } + } else { + if (podStateManager.podProgressStatus.isRunning) { + if (podStateManager.isSuspended) { + omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_suspended) + } else { + omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_running) + } + } else if (podStateManager.podProgressStatus == PodProgressStatus.FAULT_EVENT_OCCURRED) { + omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_pod_fault) + } else if (podStateManager.podProgressStatus == PodProgressStatus.INACTIVE) { + omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_inactive) + } else { + omnipod_pod_status.text = podStateManager.podProgressStatus.toString() + } + } + + if (!podStateManager.isPodActivationCompleted || podStateManager.isPodDead || podStateManager.isSuspended) { + omnipod_pod_status.setTextColor(Color.RED) + } else { + omnipod_pod_status.setTextColor(Color.WHITE) + } + } + private fun updateAcknowledgeAlertsUiElements() { if (podStateManager.isPodInitialized && podStateManager.hasActiveAlerts()) { omnipod_pod_active_alerts_ack.isEnabled = true diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodStateManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodStateManager.java index 169d39a0a8..e9b27d8ec7 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodStateManager.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodStateManager.java @@ -79,7 +79,7 @@ public abstract class PodStateManager { * @return true if we have a Pod state and the Pod activation has been completed. The pod could also be dead at this point */ public final boolean isPodActivationCompleted() { - return isPodInitialized() && podState.getPodProgressStatus().isAtLeast(PodProgressStatus.ABOVE_FIFTY_UNITS); + return isPodInitialized() && podState.getPodProgressStatus().isAtLeast(PodProgressStatus.ABOVE_FIFTY_UNITS) && podState.getPodProgressStatus() != PodProgressStatus.ACTIVATION_TIME_EXCEEDED; } /** diff --git a/omnipod/src/main/res/values/strings.xml b/omnipod/src/main/res/values/strings.xml index 17a4c6d407..67cfe9e0e8 100644 --- a/omnipod/src/main/res/values/strings.xml +++ b/omnipod/src/main/res/values/strings.xml @@ -31,18 +31,19 @@ Pod Address Pod Expires Warning - No Pod connected - Pod setup in progress (Pod progress status: %1$s) - Pod not initialized + No active Pod + Setup in progress (waiting for pair and prime) + Setup in progress (waiting for cannula insertion) + Running + Suspended Pod Fault + Activation time exceeded + Inactive Pod Fault: %1$s %2$s - Pod running (last delivery status: %1$s) Active Pod Alerts Ack Alerts %1$.2f %2$s (%3$s) Initializing - Active - Unknown