Merge pull request #2217 from Andries-Smit/feat/cannula-usage

feat: cannula usage
This commit is contained in:
Milos Kozak 2022-11-24 11:39:57 +01:00 committed by GitHub
commit bd9c149b80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 42 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

@ -9,6 +9,7 @@ import info.nightscout.interfaces.Config
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.pump.WarnColors import info.nightscout.interfaces.pump.WarnColors
import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.interfaces.stats.TddCalculator
import info.nightscout.interfaces.utils.DecimalFormatter import info.nightscout.interfaces.utils.DecimalFormatter
import info.nightscout.plugins.R import info.nightscout.plugins.R
import info.nightscout.plugins.sync.nsclient.extensions.age import info.nightscout.plugins.sync.nsclient.extensions.age
@ -26,34 +27,36 @@ class StatusLightHandler @Inject constructor(
private val activePlugin: ActivePlugin, private val activePlugin: ActivePlugin,
private val warnColors: WarnColors, private val warnColors: WarnColors,
private val config: Config, private val config: Config,
private val repository: AppRepository private val repository: AppRepository,
private val tddCalculator: TddCalculator
) { ) {
/** /**
* 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 +65,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 +83,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))
} }
} }
} }
@ -102,8 +106,7 @@ class StatusLightHandler @Inject constructor(
private fun handleLevel(view: TextView?, criticalSetting: Int, criticalDefaultValue: Double, warnSetting: Int, warnDefaultValue: Double, level: Double, units: String) { private fun handleLevel(view: TextView?, criticalSetting: Int, criticalDefaultValue: Double, warnSetting: Int, warnDefaultValue: Double, level: Double, units: String) {
val resUrgent = sp.getDouble(criticalSetting, criticalDefaultValue) val resUrgent = sp.getDouble(criticalSetting, criticalDefaultValue)
val resWarn = sp.getDouble(warnSetting, warnDefaultValue) val resWarn = sp.getDouble(warnSetting, warnDefaultValue)
@Suppress("SetTextI18n") view?.text = " " + DecimalFormatter.to0Decimal(level, units)
view?.text = " " + DecimalFormatter.to0Decimal(level) + units
warnColors.setColorInverse(view, level, resWarn, resUrgent) warnColors.setColorInverse(view, level, resWarn, resUrgent)
} }
@ -114,11 +117,20 @@ class StatusLightHandler @Inject constructor(
warnDefaultValue: Double, level: Double, units: String, maxReading: Double warnDefaultValue: Double, level: Double, units: String, maxReading: Double
) { ) {
if (level >= maxReading) { if (level >= maxReading) {
@Suppress("SetTextI18n") view?.text = DecimalFormatter.to0Decimal(maxReading, units)
view?.text = " ${maxReading.toInt()}+$units"
view?.setTextColor(rh.gac(view.context, R.attr.defaultTextColor)) view?.setTextColor(rh.gac(view.context, R.attr.defaultTextColor))
} else { } else {
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 tdd = tddCalculator.calculate(therapyEvent.value.timestamp, dateUtil.now())
usage = tdd.totalAmount
}
view?.text = DecimalFormatter.to0Decimal(usage, units)
}
} }

View file

@ -56,9 +56,9 @@
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="4dp"
android:textSize="14sp" android:paddingEnd="0dp"
tools:ignore="RtlSymmetry" /> android:textSize="14sp" />
</TableRow> </TableRow>
@ -128,9 +128,10 @@
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="4dp"
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="4dp"
android:text="" android:paddingEnd="0dp"
android:textSize="14sp" android:textSize="14sp"
tools:ignore="RtlSymmetry" /> tools:text="22U" />
</TableRow> </TableRow>
@ -274,9 +277,10 @@
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="4dp"
android:paddingEnd="0dp"
android:textSize="14sp" android:textSize="14sp"
tools:ignore="RtlSymmetry" /> tools:text="70%" />
</TableRow> </TableRow>

View file

@ -583,6 +583,7 @@
<!-- 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>
<!-- Iob--> <!-- Iob-->
<string name="send_logfiles">Send today\'s log files to developers along with this time. Unexpected situation.</string> <string name="send_logfiles">Send today\'s log files to developers along with this time. Unexpected situation.</string>