Move Detailed Delta preference to Watch

This commit is contained in:
Philoul 2023-08-19 15:10:37 +02:00
parent e08159709f
commit ba64d0f833
12 changed files with 47 additions and 23 deletions

View file

@ -173,7 +173,9 @@ sealed class EventData : Event() {
val glucoseUnits: String = "-", val glucoseUnits: String = "-",
val slopeArrow: String = "--", val slopeArrow: String = "--",
val delta: String = "--", val delta: String = "--",
val deltaDetailed: String = "--",
val avgDelta: String = "--", val avgDelta: String = "--",
val avgDeltaDetailed: String = "--",
val sgvLevel: Long = 0, val sgvLevel: Long = 0,
val sgv: Double, val sgv: Double,
val high: Double, // highLine val high: Double, // highLine

View file

@ -943,15 +943,23 @@ class DataHandlerMobile @Inject constructor(
} }
private fun deltaString(deltaMGDL: Double, deltaMMOL: Double, units: GlucoseUnit): String { 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 "-" var deltaString = if (deltaMGDL >= 0) "+" else "-"
deltaString += if (units == GlucoseUnit.MGDL) { deltaString += if (units == GlucoseUnit.MGDL) {
if (detailed) DecimalFormatter.to1Decimal(abs(deltaMGDL)) else DecimalFormatter.to0Decimal(abs(deltaMGDL)) DecimalFormatter.to0Decimal(abs(deltaMGDL))
} else { } else {
if (detailed) DecimalFormatter.to2Decimal(abs(deltaMMOL)) else DecimalFormatter.to1Decimal(abs(deltaMMOL)) DecimalFormatter.to1Decimal(abs(deltaMMOL))
} }
return deltaString 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 { private fun getSingleBG(glucoseValue: InMemoryGlucoseValue): EventData.SingleBg {
val glucoseStatus = glucoseStatusProvider.getGlucoseStatusData(true) val glucoseStatus = glucoseStatusProvider.getGlucoseStatusData(true)
@ -965,7 +973,9 @@ class DataHandlerMobile @Inject constructor(
glucoseUnits = units.asText, glucoseUnits = units.asText,
slopeArrow = trendCalculator.getTrendArrow(glucoseValue).symbol, slopeArrow = trendCalculator.getTrendArrow(glucoseValue).symbol,
delta = glucoseStatus?.let { deltaString(it.delta, it.delta * Constants.MGDL_TO_MMOLL, units) } ?: "--", 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) } ?: "--", 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, sgvLevel = if (glucoseValue.recalculated > highLine) 1L else if (glucoseValue.recalculated < lowLine) -1L else 0L,
sgv = glucoseValue.recalculated, sgv = glucoseValue.recalculated,
high = highLine, high = highLine,

View file

@ -351,8 +351,6 @@
<string name="wear_wizard_settings_summary">Calculations included in the Wizard result:</string> <string name="wear_wizard_settings_summary">Calculations included in the Wizard result:</string>
<string name="wear_display_settings">Display Settings</string> <string name="wear_display_settings">Display Settings</string>
<string name="wear_general_settings">General Settings</string> <string name="wear_general_settings">General Settings</string>
<string name="wear_detailed_delta_title">Show detailed delta</string>
<string name="wear_detailed_delta_summary">Show delta with one more decimal place</string>
<string name="wear_notifysmb_title">Notify on SMB</string> <string name="wear_notifysmb_title">Notify on SMB</string>
<string name="wear_notifysmb_summary">Show SMB on the watch like a standard bolus.</string> <string name="wear_notifysmb_summary">Show SMB on the watch like a standard bolus.</string>
<string name="wear_predictions_summary">Show the predictions on the watchface.</string> <string name="wear_predictions_summary">Show the predictions on the watchface.</string>

View file

@ -53,12 +53,6 @@
<PreferenceCategory <PreferenceCategory
android:title="@string/wear_display_settings"> android:title="@string/wear_display_settings">
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_wear_detailed_delta"
android:summary="@string/wear_detailed_delta_summary"
android:title="@string/wear_detailed_delta_title" />
<SwitchPreference <SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="wear_predictions" android:key="wear_predictions"

View file

@ -20,7 +20,9 @@ class RawDisplayData {
glucoseUnits = "-", glucoseUnits = "-",
slopeArrow = "--", slopeArrow = "--",
delta = "--", delta = "--",
deltaDetailed = "--",
avgDelta = "--", avgDelta = "--",
avgDeltaDetailed = "--",
sgvLevel = 0, sgvLevel = 0,
sgv = 0.0, sgv = 0.0,
high = 0.0, high = 0.0,

View file

@ -61,24 +61,26 @@ class DisplayFormat @Inject internal constructor() {
fun shortTrend(raw: RawDisplayData): String { fun shortTrend(raw: RawDisplayData): String {
var minutes = "--" var minutes = "--"
val rawDelta = if (sp.getBoolean(R.string.key_show_detailed_delta, false)) raw.singleBg.deltaDetailed else raw.singleBg.delta
if (raw.singleBg.timeStamp > 0) { if (raw.singleBg.timeStamp > 0) {
minutes = shortTimeSince(raw.singleBg.timeStamp) minutes = shortTimeSince(raw.singleBg.timeStamp)
} }
if (minutes.length + raw.singleBg.delta.length + deltaSymbol().length + 1 <= MAX_FIELD_LEN_SHORT) { if (minutes.length + rawDelta.length + deltaSymbol().length + 1 <= MAX_FIELD_LEN_SHORT) {
return minutes + " " + deltaSymbol() + raw.singleBg.delta return minutes + " " + deltaSymbol() + rawDelta
} }
// that only optimizes obvious things like 0 before . or at end, + at beginning // 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) { if (minutes.length + delta.length + deltaSymbol().length + 1 <= MAX_FIELD_LEN_SHORT) {
return minutes + " " + deltaSymbol() + delta 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" return "$minutes $shortDelta"
} }
fun longGlucoseLine(raw: RawDisplayData): String { 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 { fun longDetailsLine(raw: RawDisplayData): String {

View file

@ -187,9 +187,10 @@ class CircleWatchface : WatchFace() {
textView?.visibility = View.INVISIBLE textView?.visibility = View.INVISIBLE
} }
textView = myLayout?.findViewById(R.id.deltaString) 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)) { if (sp.getBoolean(R.string.key_show_delta, true)) {
textView?.visibility = View.VISIBLE textView?.visibility = View.VISIBLE
textView?.text = singleBg.delta textView?.text = if (detailedDelta) singleBg.deltaDetailed else singleBg.delta
textView?.setTextColor(textColor) textView?.setTextColor(textColor)
if (sp.getBoolean(R.string.key_show_big_numbers, false)) { if (sp.getBoolean(R.string.key_show_big_numbers, false)) {
textView?.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25f) textView?.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25f)
@ -197,7 +198,7 @@ class CircleWatchface : WatchFace() {
textView?.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f) textView?.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f)
} }
if (sp.getBoolean(R.string.key_show_avg_delta, true)) { if (sp.getBoolean(R.string.key_show_avg_delta, true)) {
textView?.append(" " + singleBg.avgDelta) textView?.append(" " + if (detailedDelta) singleBg.avgDeltaDetailed else singleBg.avgDelta)
} }
} else { } else {
//Also possible: View.INVISIBLE instead of View.GONE (no layout change) //Also possible: View.INVISIBLE instead of View.GONE (no layout change)

View file

@ -298,15 +298,16 @@ abstract class BaseWatchFace : WatchFace() {
open fun setDataFields() { open fun setDataFields() {
detailedIob = sp.getBoolean(R.string.key_show_detailed_iob, false) detailedIob = sp.getBoolean(R.string.key_show_detailed_iob, false)
val showBgi = sp.getBoolean(R.string.key_show_bgi, false) val showBgi = sp.getBoolean(R.string.key_show_bgi, false)
val detailedDelta = sp.getBoolean(R.string.key_show_detailed_delta, false)
setDateAndTime() setDateAndTime()
binding.sgv?.text = singleBg.sgvString binding.sgv?.text = singleBg.sgvString
binding.sgv?.visibility = sp.getBoolean(R.string.key_show_bg, true).toVisibilityKeepSpace() binding.sgv?.visibility = sp.getBoolean(R.string.key_show_bg, true).toVisibilityKeepSpace()
strikeThroughSgvIfNeeded() strikeThroughSgvIfNeeded()
binding.direction?.text = "${singleBg.slopeArrow}\uFE0E" binding.direction?.text = "${singleBg.slopeArrow}\uFE0E"
binding.direction?.visibility = sp.getBoolean(R.string.key_show_direction, true).toVisibility() 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.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.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.cob1?.visibility = sp.getBoolean(R.string.key_show_cob, true).toVisibility()
binding.cob2?.text = status.cob binding.cob2?.text = status.cob

View file

@ -86,7 +86,7 @@ class BgGraphBuilder(
lines.add(highValuesLine()) lines.add(highValuesLine())
var minChart = lowMark var minChart = lowMark
var maxChart = highMark var maxChart = highMark
for ((_, _, _, _, _, _, _, sgv) in bgDataList) { for ((_, _, _, _, _, _, _, _, _, sgv) in bgDataList) {
if (sgv > maxChart) maxChart = sgv if (sgv > maxChart) maxChart = sgv
if (sgv < minChart) minChart = sgv if (sgv < minChart) minChart = sgv
} }
@ -197,7 +197,7 @@ class BgGraphBuilder(
private fun addPredictionLines(lines: MutableList<Line>) { private fun addPredictionLines(lines: MutableList<Line>) {
val values: MutableMap<Int, MutableList<PointValue>> = HashMap() val values: MutableMap<Int, MutableList<PointValue>> = HashMap()
val endTime = getPredictionEndTime() val endTime = getPredictionEndTime()
for ((timeStamp, _, _, _, _, _, _, sgv, _, _, color) in predictionsList) { for ((timeStamp, _, _, _, _, _, _, _, _, sgv, _, _, color) in predictionsList) {
if (timeStamp <= endTime) { if (timeStamp <= endTime) {
val value = min(sgv, UPPER_CUTOFF_SGV) val value = min(sgv, UPPER_CUTOFF_SGV)
if (!values.containsKey(color)) { if (!values.containsKey(color)) {
@ -262,7 +262,7 @@ class BgGraphBuilder(
} }
private fun addBgReadingValues() { private fun addBgReadingValues() {
for ((timeStamp, _, _, _, _, _, _, sgv) in bgDataList) { for ((timeStamp, _, _, _,_, _, _, _, _, sgv) in bgDataList) {
if (timeStamp > startingTime) { if (timeStamp > startingTime) {
when { when {
sgv >= 450 -> highValues.add(PointValue(fuzz(timeStamp), 450.toFloat())) sgv >= 450 -> highValues.add(PointValue(fuzz(timeStamp), 450.toFloat()))

View file

@ -29,6 +29,7 @@
<string name="pref_show_detailed_iob">Show detailed IOB</string> <string name="pref_show_detailed_iob">Show detailed IOB</string>
<string name="pref_show_cob">Show COB</string> <string name="pref_show_cob">Show COB</string>
<string name="pref_show_delta">Show Delta</string> <string name="pref_show_delta">Show Delta</string>
<string name="pref_show_detailed_delta">Show detailed Delta</string>
<string name="pref_show_avgdelta">Show AvgDelta</string> <string name="pref_show_avgdelta">Show AvgDelta</string>
<string name="pref_show_phone_battery">Show Phone Battery</string> <string name="pref_show_phone_battery">Show Phone Battery</string>
<string name="pref_show_rig_battery">Show Rig Battery</string> <string name="pref_show_rig_battery">Show Rig Battery</string>
@ -195,6 +196,7 @@
<string name="key_show_ago" translatable="false">showAgo</string> <string name="key_show_ago" translatable="false">showAgo</string>
<string name="key_show_big_numbers" translatable="false">showBigNumbers</string> <string name="key_show_big_numbers" translatable="false">showBigNumbers</string>
<string name="key_show_delta" translatable="false">showDelta</string> <string name="key_show_delta" translatable="false">showDelta</string>
<string name="key_show_detailed_delta" translatable="false">showDetailedDelta</string>
<string name="key_show_avg_delta" translatable="false">showAvgDelta</string> <string name="key_show_avg_delta" translatable="false">showAvgDelta</string>
<string name="key_show_ring_history" translatable="false">showRingHistory</string> <string name="key_show_ring_history" translatable="false">showRingHistory</string>
<string name="key_digital_style_frame_style" translatable="false">digital_style_frame_style</string> <string name="key_digital_style_frame_style" translatable="false">digital_style_frame_style</string>

View file

@ -58,6 +58,14 @@
app:wear_iconOff="@drawable/settings_off" app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" /> app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/key_show_detailed_delta"
android:summary="Show delta with one more decimal place"
android:title="@string/pref_show_detailed_delta"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/key_show_direction" android:key="@string/key_show_direction"

View file

@ -30,6 +30,8 @@ class RawDataMocker(wearUtil: WearUtil) {
"", "",
d, d,
deltaString, deltaString,
deltaString,
"",
"", "",
0, 0,
0.0, 0.0,
@ -48,6 +50,8 @@ class RawDataMocker(wearUtil: WearUtil) {
"", "",
"", "",
delta, delta,
delta,
"",
"", "",
0, 0,
0.0, 0.0,