From d7a7f6a53345193dcd67e3da17507a7d2e7cc47c Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Thu, 24 Nov 2022 09:55:44 +0100 Subject: [PATCH] use tdd for cannula usage --- .../plugins/ui/StatusLightHandler.kt | 19 ++++++++----------- .../res/layout/actions_stats_fragment.xml | 8 ++++---- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt b/plugins/main/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt index d164e08a0d..a709d2df29 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt @@ -2,7 +2,6 @@ package info.nightscout.plugins.ui import android.widget.TextView import androidx.annotation.StringRes -import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.ValueWrapper @@ -10,6 +9,7 @@ import info.nightscout.interfaces.Config import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.pump.WarnColors import info.nightscout.interfaces.pump.defs.PumpType +import info.nightscout.interfaces.stats.TddCalculator import info.nightscout.interfaces.utils.DecimalFormatter import info.nightscout.plugins.R import info.nightscout.plugins.sync.nsclient.extensions.age @@ -27,7 +27,8 @@ class StatusLightHandler @Inject constructor( private val activePlugin: ActivePlugin, private val warnColors: WarnColors, private val config: Config, - private val repository: AppRepository + private val repository: AppRepository, + private val tddCalculator: TddCalculator ) { /** @@ -105,8 +106,7 @@ class StatusLightHandler @Inject constructor( private fun handleLevel(view: TextView?, criticalSetting: Int, criticalDefaultValue: Double, warnSetting: Int, warnDefaultValue: Double, level: Double, units: String) { val resUrgent = sp.getDouble(criticalSetting, criticalDefaultValue) 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) } @@ -117,8 +117,7 @@ class StatusLightHandler @Inject constructor( warnDefaultValue: Double, level: Double, units: String, maxReading: Double ) { if (level >= maxReading) { - @Suppress("SetTextI18n") - view?.text = " ${maxReading.toInt()}+$units" + view?.text = DecimalFormatter.to0Decimal(maxReading, units) view?.setTextColor(rh.gac(view.context, R.attr.defaultTextColor)) } else { handleLevel(view, criticalSetting, criticalDefaultValue, warnSetting, warnDefaultValue, level, units) @@ -129,11 +128,9 @@ class StatusLightHandler @Inject constructor( 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 } + val tdd = tddCalculator.calculate(therapyEvent.value.timestamp, dateUtil.now()) + usage = tdd.totalAmount } - view?.text = " " + DecimalFormatter.to0Decimal(usage) + units + view?.text = DecimalFormatter.to0Decimal(usage, units) } } diff --git a/plugins/main/src/main/res/layout/actions_stats_fragment.xml b/plugins/main/src/main/res/layout/actions_stats_fragment.xml index 1dda739d7c..f20d0c28bb 100644 --- a/plugins/main/src/main/res/layout/actions_stats_fragment.xml +++ b/plugins/main/src/main/res/layout/actions_stats_fragment.xml @@ -56,7 +56,7 @@ android:layout_height="wrap_content" android:layout_marginEnd="20dp" android:gravity="center_vertical" - android:paddingStart="2dp" + android:paddingStart="4dp" android:paddingEnd="0dp" android:textSize="14sp" /> @@ -128,7 +128,7 @@ android:layout_height="wrap_content" android:layout_marginEnd="20dp" android:gravity="center_vertical" - android:paddingStart="2dp" + android:paddingStart="4dp" android:paddingEnd="0dp" android:textSize="14sp" tools:text="15U" /> @@ -202,7 +202,7 @@ android:layout_height="wrap_content" android:layout_marginEnd="20dp" android:gravity="center_vertical" - android:paddingStart="2dp" + android:paddingStart="4dp" android:paddingEnd="0dp" android:textSize="14sp" tools:text="22U" /> @@ -277,7 +277,7 @@ android:layout_height="wrap_content" android:layout_marginEnd="20dp" android:gravity="center_vertical" - android:paddingStart="2dp" + android:paddingStart="4dp" android:paddingEnd="0dp" android:textSize="14sp" tools:text="70%" />