From 94e7cc57f037e60dabd369ca2a52abb3cf387b12 Mon Sep 17 00:00:00 2001 From: vanelsberg Date: Sat, 13 Dec 2025 23:39:55 +0100 Subject: [PATCH 1/2] Medtrum pump overview tab status coloring --- core/ui/src/main/res/values/attrs.xml | 2 +- .../app/aaps/pump/medtrum/MedtrumPump.kt | 12 +++ .../medtrum/ui/MedtrumOverviewFragment.kt | 9 ++- .../ui/viewmodel/MedtrumOverviewViewModel.kt | 76 ++++++++++++++++--- .../res/layout/fragment_medtrum_overview.xml | 2 + 5 files changed, 88 insertions(+), 13 deletions(-) diff --git a/core/ui/src/main/res/values/attrs.xml b/core/ui/src/main/res/values/attrs.xml index 09188066112..2514e8edb50 100644 --- a/core/ui/src/main/res/values/attrs.xml +++ b/core/ui/src/main/res/values/attrs.xml @@ -102,11 +102,11 @@ + - diff --git a/pump/medtrum/src/main/kotlin/app/aaps/pump/medtrum/MedtrumPump.kt b/pump/medtrum/src/main/kotlin/app/aaps/pump/medtrum/MedtrumPump.kt index 626dad2624d..08d224f6cb2 100644 --- a/pump/medtrum/src/main/kotlin/app/aaps/pump/medtrum/MedtrumPump.kt +++ b/pump/medtrum/src/main/kotlin/app/aaps/pump/medtrum/MedtrumPump.kt @@ -633,4 +633,16 @@ class MedtrumPump @Inject constructor( private fun newRecordInfo(newRecord: Boolean): String { return if (newRecord) "**NEW** " else "" } + + var hasStateColors = false + var defaultTextColor: Int? = null + var stateWarnColor: Int? = null + var stateUrgentColor: Int? = null + + fun setStateColors(textColor: Int, warnColor: Int, urgentColor: Int) { + defaultTextColor = textColor + stateWarnColor = warnColor + stateUrgentColor = urgentColor + hasStateColors = true + } } diff --git a/pump/medtrum/src/main/kotlin/app/aaps/pump/medtrum/ui/MedtrumOverviewFragment.kt b/pump/medtrum/src/main/kotlin/app/aaps/pump/medtrum/ui/MedtrumOverviewFragment.kt index 352892abec0..2b323339f98 100644 --- a/pump/medtrum/src/main/kotlin/app/aaps/pump/medtrum/ui/MedtrumOverviewFragment.kt +++ b/pump/medtrum/src/main/kotlin/app/aaps/pump/medtrum/ui/MedtrumOverviewFragment.kt @@ -6,7 +6,6 @@ import androidx.lifecycle.ViewModelProvider import app.aaps.core.interfaces.logging.AAPSLogger import app.aaps.core.interfaces.protection.ProtectionCheck import app.aaps.core.interfaces.resources.ResourceHelper -import app.aaps.core.interfaces.rx.AapsSchedulers import app.aaps.core.ui.dialogs.OKDialog import app.aaps.pump.medtrum.MedtrumPump import app.aaps.pump.medtrum.R @@ -20,7 +19,6 @@ import javax.inject.Inject class MedtrumOverviewFragment : MedtrumBaseFragment() { - @Inject lateinit var aapsSchedulers: AapsSchedulers @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var medtrumPump: MedtrumPump @Inject lateinit var protectionCheck: ProtectionCheck @@ -77,5 +75,12 @@ class MedtrumOverviewFragment : MedtrumBaseFragment() { private val scope = CoroutineScope(Dispatchers.Default) @@ -80,10 +83,18 @@ class MedtrumOverviewViewModel @Inject constructor( val patchExpiry: LiveData get() = _patchExpiry + private val _patchExpiryColor = SingleLiveEvent() + val patchExpiryColor: LiveData + get() = _patchExpiryColor + private val _patchAge = SingleLiveEvent() val patchAge: LiveData get() = _patchAge + private val _patchAgeColor = SingleLiveEvent() + val patchAgeColor: LiveData + get() = _patchAgeColor + private val _activeBolusStatus = SingleLiveEvent() val activeBolusStatus: LiveData get() = _activeBolusStatus @@ -208,37 +219,82 @@ class MedtrumOverviewViewModel @Inject constructor( _fwVersion.postValue(medtrumPump.swVersion) _patchNo.postValue(medtrumPump.patchId.toString()) + // Get status thresholds for AAPS Overview + val cageCriticalHours = preferences.get(IntKey.OverviewCageCritical).toLong() + val cageWarningHours = preferences.get(IntKey.OverviewCageWarning).toLong() + // Pump age + setPumpAgeStatus(cageCriticalHours, cageWarningHours) + // Pump Expiration + setPumpExpirationStatus(cageCriticalHours, cageWarningHours) + } + + // Set Pump Age related status fields in overview + private fun setPumpAgeStatus(criticalHours: Long, warningHours: Long) { if (medtrumPump.patchStartTime == 0L) { _patchAge.postValue("") } else { + // Get Age text string val age = System.currentTimeMillis() - medtrumPump.patchStartTime - val agoString = dateUtil.timeAgoFullString(age, rh) - val ageString = dateUtil.dateAndTimeString(medtrumPump.patchStartTime) + "\n" + agoString + val ageString = buildString { + append(dateUtil.dateAndTimeString(medtrumPump.patchStartTime)) + appendLine() + append(dateUtil.timeAgoFullString(age, rh)) + } + // Get Age field state color + val ageColor = when { + age > T.hours(criticalHours).msecs() -> medtrumPump.stateUrgentColor + age > T.hours(warningHours).msecs() -> medtrumPump.stateWarnColor + else -> medtrumPump.defaultTextColor // fallback + } + + // Update Age text string and color in view field + ageColor?.let { _patchAgeColor.postValue(it) } _patchAge.postValue(ageString) } + } - // Pump Expiration + // Set Pump expiration related status fields in overview + private fun setPumpExpirationStatus(criticalHours: Long, warningHours: Long) { if (medtrumPump.desiredPatchExpiration) { if (medtrumPump.patchStartTime == 0L) { _patchExpiry.postValue("") } else { + // Show when patch is expiring val expiry = medtrumPump.patchStartTime + T.hours(72).msecs() - val currentTime = System.currentTimeMillis() - val timeLeft = expiry - currentTime + val timeLeft = expiry - System.currentTimeMillis() val daysLeft = T.msecs(timeLeft).days() val hoursLeft = T.msecs(timeLeft).hours() % 24 - val daysString = if (daysLeft > 0) "$daysLeft ${rh.gs(app.aaps.core.interfaces.R.string.days)} " else "" - val hoursString = "$hoursLeft ${rh.gs(app.aaps.core.interfaces.R.string.hours)}" + // Build Expiry text string + val expiryString = buildString { + append(dateUtil.dateAndTimeString(expiry)) + appendLine() + append("(") + if (daysLeft > 0) { + append("$daysLeft ${rh.gs(app.aaps.core.interfaces.R.string.days)} ") + } + append("$hoursLeft ${rh.gs(app.aaps.core.interfaces.R.string.hours)})") + } - val expiryString = dateUtil.dateAndTimeString(expiry) + "\n(" + daysString + hoursString + ")" + // Get Expiry field state color + val age = System.currentTimeMillis() - medtrumPump.patchStartTime + val expiryColor = when { + age > T.hours(criticalHours).msecs() -> medtrumPump.stateUrgentColor + age > T.hours(warningHours).msecs() -> medtrumPump.stateWarnColor + else -> medtrumPump.defaultTextColor + } + // Update text string and color in view field + expiryColor?.let { _patchExpiryColor.postValue(it) } _patchExpiry.postValue(expiryString) } } else { - _patchExpiry.postValue(rh.gs(R.string.expiry_not_enabled)) + // Update text string and warning color color in view field + medtrumPump.stateWarnColor?.let { _patchExpiryColor.postValue(it) } + _patchExpiry.postValue(rh.gs(R.string.expiry_not_enabled) + " ⚠\uFE0F") } } + } diff --git a/pump/medtrum/src/main/res/layout/fragment_medtrum_overview.xml b/pump/medtrum/src/main/res/layout/fragment_medtrum_overview.xml index 840b1975670..a4ac89f3a8c 100644 --- a/pump/medtrum/src/main/res/layout/fragment_medtrum_overview.xml +++ b/pump/medtrum/src/main/res/layout/fragment_medtrum_overview.xml @@ -417,6 +417,7 @@ android:paddingStart="5dp" android:paddingEnd="5dp" android:text="@{viewmodel.patchAge}" + android:textColor="@{viewmodel.patchAgeColor}" android:textSize="14sp" /> @@ -662,6 +663,7 @@ android:paddingStart="5dp" android:paddingEnd="5dp" android:text="@{viewmodel.patchExpiry}" + android:textColor="@{viewmodel.patchExpiryColor}" android:textSize="14sp" /> From e157d7e0bd0ade71387e66f50874754dc9e83936 Mon Sep 17 00:00:00 2001 From: vanelsberg Date: Mon, 22 Dec 2025 11:01:16 +0100 Subject: [PATCH 2/2] Feedback: remove warning triangle. --- .../aaps/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pump/medtrum/src/main/kotlin/app/aaps/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt b/pump/medtrum/src/main/kotlin/app/aaps/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt index 6e073788c1e..231d7dc3d44 100644 --- a/pump/medtrum/src/main/kotlin/app/aaps/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt +++ b/pump/medtrum/src/main/kotlin/app/aaps/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt @@ -293,7 +293,7 @@ class MedtrumOverviewViewModel @Inject constructor( } else { // Update text string and warning color color in view field medtrumPump.stateWarnColor?.let { _patchExpiryColor.postValue(it) } - _patchExpiry.postValue(rh.gs(R.string.expiry_not_enabled) + " ⚠\uFE0F") + _patchExpiry.postValue(rh.gs(R.string.expiry_not_enabled)) } }