From ba64d0f833cf36c073026ff577a71ad5c303532b Mon Sep 17 00:00:00 2001 From: Philoul Date: Sat, 19 Aug 2023 15:10:37 +0200 Subject: [PATCH] Move Detailed Delta preference to Watch --- .../info/nightscout/rx/weardata/EventData.kt | 2 ++ .../wear/wearintegration/DataHandlerMobile.kt | 16 +++++++++++++--- plugins/main/src/main/res/values/strings.xml | 2 -- plugins/main/src/main/res/xml/pref_wear.xml | 6 ------ .../nightscout/androidaps/data/RawDisplayData.kt | 2 ++ .../interaction/utils/DisplayFormat.kt | 12 +++++++----- .../androidaps/watchfaces/CircleWatchface.kt | 5 +++-- .../androidaps/watchfaces/utils/BaseWatchFace.kt | 5 +++-- .../watchfaces/utils/BgGraphBuilder.kt | 6 +++--- wear/src/main/res/values/strings.xml | 2 ++ wear/src/main/res/xml/preferences.xml | 8 ++++++++ .../androidaps/testing/mockers/RawDataMocker.kt | 4 ++++ 12 files changed, 47 insertions(+), 23 deletions(-) diff --git a/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/EventData.kt b/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/EventData.kt index 578be4d474..2c14ee491a 100644 --- a/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/EventData.kt +++ b/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/EventData.kt @@ -173,7 +173,9 @@ sealed class EventData : Event() { val glucoseUnits: String = "-", val slopeArrow: String = "--", val delta: String = "--", + val deltaDetailed: String = "--", val avgDelta: String = "--", + val avgDeltaDetailed: String = "--", val sgvLevel: Long = 0, val sgv: Double, val high: Double, // highLine diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt index a022c82621..51d8b2ee35 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt @@ -943,15 +943,23 @@ class DataHandlerMobile @Inject constructor( } private fun deltaString(deltaMGDL: Double, deltaMMOL: Double, units: GlucoseUnit): String { - val detailed = sp.getBoolean(info.nightscout.core.utils.R.string.key_wear_detailed_delta, false) var deltaString = if (deltaMGDL >= 0) "+" else "-" deltaString += if (units == GlucoseUnit.MGDL) { - if (detailed) DecimalFormatter.to1Decimal(abs(deltaMGDL)) else DecimalFormatter.to0Decimal(abs(deltaMGDL)) + DecimalFormatter.to0Decimal(abs(deltaMGDL)) } else { - if (detailed) DecimalFormatter.to2Decimal(abs(deltaMMOL)) else DecimalFormatter.to1Decimal(abs(deltaMMOL)) + DecimalFormatter.to1Decimal(abs(deltaMMOL)) } return deltaString } + private fun deltaStringDetailed(deltaMGDL: Double, deltaMMOL: Double, units: GlucoseUnit): String { + var deltaStringDetailed = if (deltaMGDL >= 0) "+" else "-" + deltaStringDetailed += if (units == GlucoseUnit.MGDL) { + DecimalFormatter.to1Decimal(abs(deltaMGDL)) + } else { + DecimalFormatter.to2Decimal(abs(deltaMMOL)) + } + return deltaStringDetailed + } private fun getSingleBG(glucoseValue: InMemoryGlucoseValue): EventData.SingleBg { val glucoseStatus = glucoseStatusProvider.getGlucoseStatusData(true) @@ -965,7 +973,9 @@ class DataHandlerMobile @Inject constructor( glucoseUnits = units.asText, slopeArrow = trendCalculator.getTrendArrow(glucoseValue).symbol, delta = glucoseStatus?.let { deltaString(it.delta, it.delta * Constants.MGDL_TO_MMOLL, units) } ?: "--", + deltaDetailed = glucoseStatus?.let { deltaStringDetailed(it.delta, it.delta * Constants.MGDL_TO_MMOLL, units) } ?: "--", avgDelta = glucoseStatus?.let { deltaString(it.shortAvgDelta, it.shortAvgDelta * Constants.MGDL_TO_MMOLL, units) } ?: "--", + avgDeltaDetailed = glucoseStatus?.let { deltaStringDetailed(it.shortAvgDelta, it.shortAvgDelta * Constants.MGDL_TO_MMOLL, units) } ?: "--", sgvLevel = if (glucoseValue.recalculated > highLine) 1L else if (glucoseValue.recalculated < lowLine) -1L else 0L, sgv = glucoseValue.recalculated, high = highLine, diff --git a/plugins/main/src/main/res/values/strings.xml b/plugins/main/src/main/res/values/strings.xml index 08d18ddc84..0e7b4845b4 100644 --- a/plugins/main/src/main/res/values/strings.xml +++ b/plugins/main/src/main/res/values/strings.xml @@ -351,8 +351,6 @@ Calculations included in the Wizard result: Display Settings General Settings - Show detailed delta - Show delta with one more decimal place Notify on SMB Show SMB on the watch like a standard bolus. Show the predictions on the watchface. diff --git a/plugins/main/src/main/res/xml/pref_wear.xml b/plugins/main/src/main/res/xml/pref_wear.xml index f9ac0409b0..3d0378db49 100644 --- a/plugins/main/src/main/res/xml/pref_wear.xml +++ b/plugins/main/src/main/res/xml/pref_wear.xml @@ -53,12 +53,6 @@ - - 0) { minutes = shortTimeSince(raw.singleBg.timeStamp) } - if (minutes.length + raw.singleBg.delta.length + deltaSymbol().length + 1 <= MAX_FIELD_LEN_SHORT) { - return minutes + " " + deltaSymbol() + raw.singleBg.delta + if (minutes.length + rawDelta.length + deltaSymbol().length + 1 <= MAX_FIELD_LEN_SHORT) { + return minutes + " " + deltaSymbol() + rawDelta } // that only optimizes obvious things like 0 before . or at end, + at beginning - val delta = SmallestDoubleString(raw.singleBg.delta).minimise(MAX_FIELD_LEN_SHORT - 1) + val delta = SmallestDoubleString(rawDelta).minimise(MAX_FIELD_LEN_SHORT - 1) if (minutes.length + delta.length + deltaSymbol().length + 1 <= MAX_FIELD_LEN_SHORT) { return minutes + " " + deltaSymbol() + delta } - val shortDelta = SmallestDoubleString(raw.singleBg.delta).minimise(MAX_FIELD_LEN_SHORT - (1 + minutes.length)) + val shortDelta = SmallestDoubleString(rawDelta).minimise(MAX_FIELD_LEN_SHORT - (1 + minutes.length)) return "$minutes $shortDelta" } fun longGlucoseLine(raw: RawDisplayData): String { - return raw.singleBg.sgvString + raw.singleBg.slopeArrow + " " + deltaSymbol() + SmallestDoubleString(raw.singleBg.delta).minimise(8) + " (" + shortTimeSince(raw.singleBg.timeStamp) + ")" + val rawDelta = if (sp.getBoolean(R.string.key_show_detailed_delta, false)) raw.singleBg.deltaDetailed else raw.singleBg.delta + return raw.singleBg.sgvString + raw.singleBg.slopeArrow + " " + deltaSymbol() + SmallestDoubleString(rawDelta).minimise(8) + " (" + shortTimeSince(raw.singleBg.timeStamp) + ")" } fun longDetailsLine(raw: RawDisplayData): String { diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.kt index 7d622af937..478306bac9 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.kt @@ -187,9 +187,10 @@ class CircleWatchface : WatchFace() { textView?.visibility = View.INVISIBLE } textView = myLayout?.findViewById(R.id.deltaString) + val detailedDelta = sp.getBoolean(R.string.key_show_detailed_delta, false) if (sp.getBoolean(R.string.key_show_delta, true)) { textView?.visibility = View.VISIBLE - textView?.text = singleBg.delta + textView?.text = if (detailedDelta) singleBg.deltaDetailed else singleBg.delta textView?.setTextColor(textColor) if (sp.getBoolean(R.string.key_show_big_numbers, false)) { textView?.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25f) @@ -197,7 +198,7 @@ class CircleWatchface : WatchFace() { textView?.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f) } if (sp.getBoolean(R.string.key_show_avg_delta, true)) { - textView?.append(" " + singleBg.avgDelta) + textView?.append(" " + if (detailedDelta) singleBg.avgDeltaDetailed else singleBg.avgDelta) } } else { //Also possible: View.INVISIBLE instead of View.GONE (no layout change) diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BaseWatchFace.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BaseWatchFace.kt index a95ce5731f..0c2f21066f 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BaseWatchFace.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BaseWatchFace.kt @@ -298,15 +298,16 @@ abstract class BaseWatchFace : WatchFace() { open fun setDataFields() { detailedIob = sp.getBoolean(R.string.key_show_detailed_iob, false) val showBgi = sp.getBoolean(R.string.key_show_bgi, false) + val detailedDelta = sp.getBoolean(R.string.key_show_detailed_delta, false) setDateAndTime() binding.sgv?.text = singleBg.sgvString binding.sgv?.visibility = sp.getBoolean(R.string.key_show_bg, true).toVisibilityKeepSpace() strikeThroughSgvIfNeeded() binding.direction?.text = "${singleBg.slopeArrow}\uFE0E" binding.direction?.visibility = sp.getBoolean(R.string.key_show_direction, true).toVisibility() - binding.delta?.text = singleBg.delta + binding.delta?.text = if (detailedDelta) singleBg.deltaDetailed else singleBg.delta binding.delta?.visibility = sp.getBoolean(R.string.key_show_delta, true).toVisibility() - binding.avgDelta?.text = singleBg.avgDelta + binding.avgDelta?.text = if (detailedDelta) singleBg.avgDeltaDetailed else singleBg.avgDelta binding.avgDelta?.visibility = sp.getBoolean(R.string.key_show_avg_delta, true).toVisibility() binding.cob1?.visibility = sp.getBoolean(R.string.key_show_cob, true).toVisibility() binding.cob2?.text = status.cob diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt index 5cd8aa682a..24e8ac5c38 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt @@ -86,7 +86,7 @@ class BgGraphBuilder( lines.add(highValuesLine()) var minChart = lowMark var maxChart = highMark - for ((_, _, _, _, _, _, _, sgv) in bgDataList) { + for ((_, _, _, _, _, _, _, _, _, sgv) in bgDataList) { if (sgv > maxChart) maxChart = sgv if (sgv < minChart) minChart = sgv } @@ -197,7 +197,7 @@ class BgGraphBuilder( private fun addPredictionLines(lines: MutableList) { val values: MutableMap> = HashMap() val endTime = getPredictionEndTime() - for ((timeStamp, _, _, _, _, _, _, sgv, _, _, color) in predictionsList) { + for ((timeStamp, _, _, _, _, _, _, _, _, sgv, _, _, color) in predictionsList) { if (timeStamp <= endTime) { val value = min(sgv, UPPER_CUTOFF_SGV) if (!values.containsKey(color)) { @@ -262,7 +262,7 @@ class BgGraphBuilder( } private fun addBgReadingValues() { - for ((timeStamp, _, _, _, _, _, _, sgv) in bgDataList) { + for ((timeStamp, _, _, _,_, _, _, _, _, sgv) in bgDataList) { if (timeStamp > startingTime) { when { sgv >= 450 -> highValues.add(PointValue(fuzz(timeStamp), 450.toFloat())) diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml index 5c9b6c1383..6011568759 100644 --- a/wear/src/main/res/values/strings.xml +++ b/wear/src/main/res/values/strings.xml @@ -29,6 +29,7 @@ Show detailed IOB Show COB Show Delta + Show detailed Delta Show AvgDelta Show Phone Battery Show Rig Battery @@ -195,6 +196,7 @@ showAgo showBigNumbers showDelta + showDetailedDelta showAvgDelta showRingHistory digital_style_frame_style diff --git a/wear/src/main/res/xml/preferences.xml b/wear/src/main/res/xml/preferences.xml index c4caa84aaf..47f0122a3b 100644 --- a/wear/src/main/res/xml/preferences.xml +++ b/wear/src/main/res/xml/preferences.xml @@ -58,6 +58,14 @@ app:wear_iconOff="@drawable/settings_off" app:wear_iconOn="@drawable/settings_on" /> + +