Преглед изворни кода

Fix mmol/L conversion issue for dynamic color in Live Activity

Deniz Cengiz пре 1 година
родитељ
комит
fb8f8381c2
1 измењених фајлова са 10 додато и 8 уклоњено
  1. 10 8
      LiveActivity/LiveActivity.swift

+ 10 - 8
LiveActivity/LiveActivity.swift

@@ -418,11 +418,13 @@ struct LiveActivity: Widget {
         // TODO: grab target from proper targets, do not hard code.
         let glucoseColor = getDynamicGlucoseColor(
             glucoseValue: Decimal(string: context.state.bg) ?? 100,
-            highGlucoseColorValue: context.state.highGlucose,
-            lowGlucoseColorValue: context.state.lowGlucose,
-            targetGlucose: 90,
+            highGlucoseColorValue: context.state.detailedViewState?.unit == "mg/dL" ? context.state.highGlucose : context.state
+                .highGlucose.asMmolL,
+            lowGlucoseColorValue: context.state.detailedViewState?.unit == "mg/dL" ? context.state.lowGlucose : context.state
+                .lowGlucose.asMmolL,
+            targetGlucose: context.state.detailedViewState?.unit == "mg/dL" ? 90 : 90.asMmolL,
             glucoseColorScheme: context.state.glucoseColorScheme,
-            offset: 20
+            offset: context.state.detailedViewState?.unit == "mg/dL" ? 20 : 20.asMmolL
         )
 
         if let detailedViewState = context.state.detailedViewState {
@@ -499,11 +501,11 @@ struct LiveActivity: Widget {
         // TODO: grab target from proper targets, do not hard code.
         let glucoseColor = getDynamicGlucoseColor(
             glucoseValue: Decimal(string: glucoseValueForColor) ?? 100,
-            highGlucoseColorValue: highGlucose,
-            lowGlucoseColorValue: lowGlucose,
-            targetGlucose: 90,
+            highGlucoseColorValue: context.state.detailedViewState?.unit == "mg/dL" ? highGlucose : highGlucose.asMmolL,
+            lowGlucoseColorValue: context.state.detailedViewState?.unit == "mg/dL" ? lowGlucose : lowGlucose.asMmolL,
+            targetGlucose: context.state.detailedViewState?.unit == "mg/dL" ? 90 : 90.asMmolL,
             glucoseColorScheme: context.state.glucoseColorScheme,
-            offset: 20
+            offset: context.state.detailedViewState?.unit == "mg/dL" ? 20 : 20.asMmolL
         )
 
         return DynamicIsland {