feat: cannula usage

This commit is contained in:
Andries Smit 2022-11-23 19:52:21 +01:00
parent 32bf2e592a
commit c5925c4f8f
6 changed files with 56 additions and 33 deletions

View file

@ -923,6 +923,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
} }
statusLightHandler.updateStatusLights( statusLightHandler.updateStatusLights(
binding.statusLightsLayout.cannulaAge, binding.statusLightsLayout.cannulaAge,
null,
binding.statusLightsLayout.insulinAge, binding.statusLightsLayout.insulinAge,
binding.statusLightsLayout.reservoirLevel, binding.statusLightsLayout.reservoirLevel,
binding.statusLightsLayout.sensorAge, binding.statusLightsLayout.sensorAge,

View file

@ -289,12 +289,14 @@ class ActionsFragment : DaggerFragment() {
val imageResource = if (isPatchPump) R.drawable.ic_patch_pump_outline else R.drawable.ic_cp_age_cannula val imageResource = if (isPatchPump) R.drawable.ic_patch_pump_outline else R.drawable.ic_cp_age_cannula
cannulaOrPatch.setCompoundDrawablesWithIntrinsicBounds(imageResource, 0, 0, 0) cannulaOrPatch.setCompoundDrawablesWithIntrinsicBounds(imageResource, 0, 0, 0)
batteryLayout.visibility = (!isPatchPump || pump.pumpDescription.useHardwareLink).toVisibility() batteryLayout.visibility = (!isPatchPump || pump.pumpDescription.useHardwareLink).toVisibility()
cannulaUsageLabel.visibility = isPatchPump.not().toVisibility()
cannulaUsage.visibility = isPatchPump.not().toVisibility()
if (!config.NSCLIENT) { if (!config.NSCLIENT) {
statusLightHandler.updateStatusLights(cannulaAge, insulinAge, reservoirLevel, sensorAge, sensorLevel, pbAge, batteryLevel) statusLightHandler.updateStatusLights(cannulaAge, cannulaUsage, insulinAge, reservoirLevel, sensorAge, sensorLevel, pbAge, batteryLevel)
sensorLevelLabel.text = if (activeBgSource.sensorBatteryLevel == -1) "" else rh.gs(R.string.level_label) sensorLevelLabel.text = if (activeBgSource.sensorBatteryLevel == -1) "" else rh.gs(R.string.level_label)
} else { } else {
statusLightHandler.updateStatusLights(cannulaAge, insulinAge, null, sensorAge, null, pbAge, null) statusLightHandler.updateStatusLights(cannulaAge, cannulaUsage, insulinAge, null, sensorAge, null, pbAge, null)
sensorLevelLabel.text = "" sensorLevelLabel.text = ""
insulinLevelLabel.text = "" insulinLevelLabel.text = ""
pbLevelLabel.text = "" pbLevelLabel.text = ""

View file

@ -30,7 +30,7 @@ class SkinLowRes @Inject constructor(private val config: Config) : SkinInterface
insulinAgeLabel.visibility = GONE insulinAgeLabel.visibility = GONE
insulinLevelLabel.visibility = GONE insulinLevelLabel.visibility = GONE
cannulaAgeLabel.visibility = GONE cannulaAgeLabel.visibility = GONE
cannulaPlaceholder.visibility = GONE cannulaUsageLabel.visibility = GONE
pbAgeLabel.visibility = GONE pbAgeLabel.visibility = GONE
pbLevelLabel.visibility = GONE pbLevelLabel.visibility = GONE
} }

View file

@ -2,6 +2,7 @@ package info.nightscout.plugins.ui
import android.widget.TextView import android.widget.TextView
import androidx.annotation.StringRes import androidx.annotation.StringRes
import info.nightscout.database.entities.Bolus
import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.entities.TherapyEvent
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.database.impl.ValueWrapper import info.nightscout.database.impl.ValueWrapper
@ -33,27 +34,28 @@ class StatusLightHandler @Inject constructor(
* applies the extended statusLight subview on the overview fragment * applies the extended statusLight subview on the overview fragment
*/ */
fun updateStatusLights( fun updateStatusLights(
careportal_cannula_age: TextView?, cannulaAge: TextView?,
careportal_insulin_age: TextView?, cannulaUsage: TextView?,
careportal_reservoir_level: TextView?, insulinAge: TextView?,
careportal_sensor_age: TextView?, reservoirLevel: TextView?,
careportal_sensor_battery_level: TextView?, sensorAge: TextView?,
careportal_pb_age: TextView?, sensorBatteryLevel: TextView?,
careportal_battery_level: TextView? batteryAge: TextView?,
batteryLevel: TextView?
) { ) {
val pump = activePlugin.activePump val pump = activePlugin.activePump
val bgSource = activePlugin.activeBgSource val bgSource = activePlugin.activeBgSource
handleAge(careportal_cannula_age, TherapyEvent.Type.CANNULA_CHANGE, R.string.key_statuslights_cage_warning, 48.0, R.string.key_statuslights_cage_critical, 72.0) handleAge(cannulaAge, TherapyEvent.Type.CANNULA_CHANGE, R.string.key_statuslights_cage_warning, 48.0, R.string.key_statuslights_cage_critical, 72.0)
handleAge(careportal_insulin_age, TherapyEvent.Type.INSULIN_CHANGE, R.string.key_statuslights_iage_warning, 72.0, R.string.key_statuslights_iage_critical, 144.0) handleAge(insulinAge, TherapyEvent.Type.INSULIN_CHANGE, R.string.key_statuslights_iage_warning, 72.0, R.string.key_statuslights_iage_critical, 144.0)
handleAge(careportal_sensor_age, TherapyEvent.Type.SENSOR_CHANGE, R.string.key_statuslights_sage_warning, 216.0, R.string.key_statuslights_sage_critical, 240.0) handleAge(sensorAge, TherapyEvent.Type.SENSOR_CHANGE, R.string.key_statuslights_sage_warning, 216.0, R.string.key_statuslights_sage_critical, 240.0)
if (pump.pumpDescription.isBatteryReplaceable || pump.isBatteryChangeLoggingEnabled()) { if (pump.pumpDescription.isBatteryReplaceable || pump.isBatteryChangeLoggingEnabled()) {
handleAge(careportal_pb_age, TherapyEvent.Type.PUMP_BATTERY_CHANGE, R.string.key_statuslights_bage_warning, 216.0, R.string.key_statuslights_bage_critical, 240.0) handleAge(batteryAge, TherapyEvent.Type.PUMP_BATTERY_CHANGE, R.string.key_statuslights_bage_warning, 216.0, R.string.key_statuslights_bage_critical, 240.0)
} }
val insulinUnit = rh.gs(R.string.insulin_unit_shortname) val insulinUnit = rh.gs(R.string.insulin_unit_shortname)
if (pump.pumpDescription.isPatchPump) if (pump.pumpDescription.isPatchPump) {
handlePatchReservoirLevel( handlePatchReservoirLevel(
careportal_reservoir_level, reservoirLevel,
R.string.key_statuslights_res_critical, R.string.key_statuslights_res_critical,
10.0, 10.0,
R.string.key_statuslights_res_warning, R.string.key_statuslights_res_warning,
@ -62,14 +64,15 @@ class StatusLightHandler @Inject constructor(
insulinUnit, insulinUnit,
pump.pumpDescription.maxResorvoirReading.toDouble() pump.pumpDescription.maxResorvoirReading.toDouble()
) )
else } else {
handleLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit) handleUsage(cannulaUsage, TherapyEvent.Type.CANNULA_CHANGE, insulinUnit)
handleLevel(reservoirLevel, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit)
}
if (!config.NSCLIENT) { if (!config.NSCLIENT) {
if (bgSource.sensorBatteryLevel != -1) if (bgSource.sensorBatteryLevel != -1)
handleLevel(careportal_sensor_battery_level, R.string.key_statuslights_sbat_critical, 5.0, R.string.key_statuslights_sbat_warning, 20.0, bgSource.sensorBatteryLevel.toDouble(), "%") handleLevel(sensorBatteryLevel, R.string.key_statuslights_sbat_critical, 5.0, R.string.key_statuslights_sbat_warning, 20.0, bgSource.sensorBatteryLevel.toDouble(), "%")
else else
careportal_sensor_battery_level?.text = "" sensorBatteryLevel?.text = ""
} }
if (!config.NSCLIENT) { if (!config.NSCLIENT) {
@ -79,10 +82,10 @@ class StatusLightHandler @Inject constructor(
val erosBatteryLinkAvailable = pump.model() == PumpType.OMNIPOD_EROS && pump.isUseRileyLinkBatteryLevel() val erosBatteryLinkAvailable = pump.model() == PumpType.OMNIPOD_EROS && pump.isUseRileyLinkBatteryLevel()
if (pump.model().supportBatteryLevel || erosBatteryLinkAvailable) { if (pump.model().supportBatteryLevel || erosBatteryLinkAvailable) {
handleLevel(careportal_battery_level, R.string.key_statuslights_bat_critical, 26.0, R.string.key_statuslights_bat_warning, 51.0, pump.batteryLevel.toDouble(), "%") handleLevel(batteryLevel, R.string.key_statuslights_bat_critical, 26.0, R.string.key_statuslights_bat_warning, 51.0, pump.batteryLevel.toDouble(), "%")
} else { } else {
careportal_battery_level?.text = rh.gs(R.string.value_unavailable_short) batteryLevel?.text = rh.gs(R.string.value_unavailable_short)
careportal_battery_level?.setTextColor(rh.gac(careportal_battery_level.context, R.attr.defaultTextColor)) batteryLevel?.setTextColor(rh.gac(batteryLevel.context, R.attr.defaultTextColor))
} }
} }
} }
@ -121,4 +124,16 @@ class StatusLightHandler @Inject constructor(
handleLevel(view, criticalSetting, criticalDefaultValue, warnSetting, warnDefaultValue, level, units) handleLevel(view, criticalSetting, criticalDefaultValue, warnSetting, warnDefaultValue, level, units)
} }
} }
private fun handleUsage(view: TextView?, type: TherapyEvent.Type, units: String) {
val therapyEvent = repository.getLastTherapyRecordUpToNow(type).blockingGet()
var usage = 0.0
if (therapyEvent is ValueWrapper.Existing) {
val startTime = therapyEvent.value.timestamp
usage = repository.getBolusesDataFromTime(startTime, true).blockingGet()
.filter { it.type != Bolus.Type.PRIMING }
.sumOf { t -> t.amount }
}
view?.text = " " + DecimalFormatter.to0Decimal(usage) + units
}
} }

View file

@ -57,8 +57,8 @@
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingStart="2dp" android:paddingStart="2dp"
android:textSize="14sp" android:paddingEnd="0dp"
tools:ignore="RtlSymmetry" /> android:textSize="14sp" />
</TableRow> </TableRow>
@ -129,8 +129,9 @@
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingStart="2dp" android:paddingStart="2dp"
android:paddingEnd="0dp"
android:textSize="14sp" android:textSize="14sp"
tools:ignore="RtlSymmetry" /> tools:text="15U" />
</TableRow> </TableRow>
@ -186,23 +187,25 @@
android:textSize="14sp" /> android:textSize="14sp" />
<TextView <TextView
android:id="@+id/cannula_placeholder" android:id="@+id/cannula_usage_label"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingStart="0dp" android:paddingStart="0dp"
android:paddingEnd="0dp" android:paddingEnd="0dp"
android:text="@string/cannula_usage"
android:textSize="14sp" /> android:textSize="14sp" />
<TextView <TextView
android:id="@+id/cannula_usage"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingStart="2dp" android:paddingStart="2dp"
android:text="" android:paddingEnd="0dp"
android:textSize="14sp" android:textSize="14sp"
tools:ignore="RtlSymmetry" /> tools:text="22U" />
</TableRow> </TableRow>
@ -275,8 +278,9 @@
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingStart="2dp" android:paddingStart="2dp"
android:paddingEnd="0dp"
android:textSize="14sp" android:textSize="14sp"
tools:ignore="RtlSymmetry" /> tools:text="70%" />
</TableRow> </TableRow>

View file

@ -583,5 +583,6 @@
<!-- DataBroadcast--> <!-- DataBroadcast-->
<string name="data_broadcaster" translatable="false">Data Broadcaster</string> <string name="data_broadcaster" translatable="false">Data Broadcaster</string>
<string name="cannula_usage">usage:</string>
</resources> </resources>