Przeglądaj źródła

Fix rulermark colors (thresholds) for dynamic and static

Deniz Cengiz 1 rok temu
rodzic
commit
75084c9c4a

+ 3 - 2
FreeAPS/Sources/Modules/Bolus/View/ForecastChart.swift

@@ -125,11 +125,12 @@ struct ForecastChart: View {
             // TODO: workaround for now: set low value to 55, to have dynamic color shades between 55 and user-set low (approx. 70); same for high glucose
             let hardCodedLow = Decimal(55)
             let hardCodedHigh = Decimal(220)
+            let isDynamicColorScheme = state.glucoseColorScheme == .dynamicColor
 
             let pointMarkColor: Color = FreeAPS.getDynamicGlucoseColor(
                 glucoseValue: Decimal(item.glucose),
-                highGlucoseColorValue: hardCodedHigh,
-                lowGlucoseColorValue: hardCodedLow,
+                highGlucoseColorValue: isDynamicColorScheme ? hardCodedHigh : highGlucose,
+                lowGlucoseColorValue: isDynamicColorScheme ? hardCodedLow : lowGlucose,
                 targetGlucose: targetGlucose,
                 glucoseColorScheme: state.glucoseColorScheme
             )

+ 10 - 4
FreeAPS/Sources/Modules/Home/View/Chart/DummyCharts.swift

@@ -7,18 +7,24 @@ extension MainChartView {
     var staticYAxisChart: some View {
         Chart {
             /// high and low threshold lines
+
+            // TODO: workaround for now: set low value to 55, to have dynamic color shades between 55 and user-set low (approx. 70); same for high glucose
+            let hardCodedLow = Decimal(55)
+            let hardCodedHigh = Decimal(220)
+            let isDynamicColorScheme = glucoseColorScheme == .dynamicColor
+
             if thresholdLines {
                 let highColor = FreeAPS.getDynamicGlucoseColor(
                     glucoseValue: highGlucose,
-                    highGlucoseColorValue: highGlucose,
-                    lowGlucoseColorValue: lowGlucose,
+                    highGlucoseColorValue: isDynamicColorScheme ? hardCodedHigh : highGlucose,
+                    lowGlucoseColorValue: isDynamicColorScheme ? hardCodedLow : lowGlucose,
                     targetGlucose: currentGlucoseTarget,
                     glucoseColorScheme: glucoseColorScheme
                 )
                 let lowColor = FreeAPS.getDynamicGlucoseColor(
                     glucoseValue: lowGlucose,
-                    highGlucoseColorValue: highGlucose,
-                    lowGlucoseColorValue: lowGlucose,
+                    highGlucoseColorValue: isDynamicColorScheme ? hardCodedHigh : highGlucose,
+                    lowGlucoseColorValue: isDynamicColorScheme ? hardCodedLow : lowGlucose,
                     targetGlucose: currentGlucoseTarget,
                     glucoseColorScheme: glucoseColorScheme
                 )

+ 3 - 2
FreeAPS/Sources/Modules/Home/View/Chart/GlucoseChartView.swift

@@ -26,11 +26,12 @@ struct GlucoseChartView: ChartContent {
             // TODO: workaround for now: set low value to 55, to have dynamic color shades between 55 and user-set low (approx. 70); same for high glucose
             let hardCodedLow = Decimal(55)
             let hardCodedHigh = Decimal(220)
+            let isDynamicColorScheme = glucoseColorScheme == .dynamicColor
 
             let pointMarkColor: Color = FreeAPS.getDynamicGlucoseColor(
                 glucoseValue: Decimal(item.glucose),
-                highGlucoseColorValue: hardCodedHigh,
-                lowGlucoseColorValue: hardCodedLow,
+                highGlucoseColorValue: isDynamicColorScheme ? hardCodedHigh : highGlucose,
+                lowGlucoseColorValue: isDynamicColorScheme ? hardCodedLow : lowGlucose,
                 targetGlucose: currentGlucoseTarget,
                 glucoseColorScheme: glucoseColorScheme
             )

+ 3 - 2
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -254,11 +254,12 @@ extension MainChartView {
                 // TODO: workaround for now: set low value to 55, to have dynamic color shades between 55 and user-set low (approx. 70); same for high glucose
                 let hardCodedLow = Decimal(55)
                 let hardCodedHigh = Decimal(220)
+                let isDynamicColorScheme = glucoseColorScheme == .dynamicColor
 
                 let glucoseColor = FreeAPS.getDynamicGlucoseColor(
                     glucoseValue: Decimal(sgv),
-                    highGlucoseColorValue: hardCodedHigh,
-                    lowGlucoseColorValue: hardCodedLow,
+                    highGlucoseColorValue: isDynamicColorScheme ? hardCodedHigh : highGlucose,
+                    lowGlucoseColorValue: isDynamicColorScheme ? hardCodedLow : lowGlucose,
                     targetGlucose: units == .mgdL ? currentGlucoseTarget : currentGlucoseTarget.asMgdL,
                     glucoseColorScheme: glucoseColorScheme
                 )

+ 3 - 2
FreeAPS/Sources/Modules/Home/View/Header/CurrentGlucoseView.swift

@@ -92,12 +92,13 @@ struct CurrentGlucoseView: View {
                             // TODO: workaround for now: set low value to 55, to have dynamic color shades between 55 and user-set low (approx. 70); same for high glucose
                             let hardCodedLow = Decimal(55)
                             let hardCodedHigh = Decimal(220)
+                            let isDynamicColorScheme = glucoseColorScheme == .dynamicColor
 
                             if Decimal(glucoseValue) <= lowGlucose || Decimal(glucoseValue) >= highGlucose {
                                 glucoseDisplayColor = FreeAPS.getDynamicGlucoseColor(
                                     glucoseValue: Decimal(glucoseValue),
-                                    highGlucoseColorValue: hardCodedHigh,
-                                    lowGlucoseColorValue: hardCodedLow,
+                                    highGlucoseColorValue: isDynamicColorScheme ? hardCodedHigh : highGlucose,
+                                    lowGlucoseColorValue: isDynamicColorScheme ? hardCodedLow : lowGlucose,
                                     targetGlucose: targetGlucose,
                                     glucoseColorScheme: glucoseColorScheme
                                 )

+ 0 - 17
FreeAPS/Sources/Modules/LiveActivitySettings/View/LiveActivityWidgetConfiguration.swift

@@ -108,23 +108,6 @@ struct LiveActivityWidgetConfiguration: BaseView {
                 .padding(.vertical, 8)
                 .padding(.horizontal)
 
-//                Group {
-//                    Button {
-//                        saveOrder()
-//                        isEditMode = false
-//                    } label: {
-//                        Text("Save Configuration")
-//                            .frame(maxWidth: .infinity, alignment: .center)
-//                            .tint(Color.white)
-//                            .background(Color(.systemBlue))
-//                    }
-//                    .padding(.vertical)
-//                    .tint(Color(.systemBlue))
-//                    .buttonStyle(.borderedProminent)
-//                    .cornerRadius(12)
-//                }.padding(.vertical)
-//            }
-
             Spacer()
         }
         .padding()

+ 30 - 24
LiveActivity/LiveActivity.swift

@@ -83,9 +83,9 @@ extension Color {
         }
         // Otheriwse, use static (orange = high, red = low, green = range)
         else {
-            if glucoseValue > highGlucoseColorValue {
+            if glucoseValue >= highGlucoseColorValue {
                 return Color.orange
-            } else if glucoseValue < lowGlucoseColorValue {
+            } else if glucoseValue <= lowGlucoseColorValue {
                 return Color.red
             } else {
                 return Color.green
@@ -134,6 +134,8 @@ struct LiveActivity: Widget {
         ActivityConfiguration(for: LiveActivityAttributes.self) { context in
             LiveActivityView(context: context)
         } dynamicIsland: { context in
+            let hasStaticColorScheme = context.state.glucoseColorScheme == "staticColor"
+
             var glucoseColor: Color {
                 let state = context.state
                 let detailedState = state.detailedViewState
@@ -145,15 +147,13 @@ struct LiveActivity: Widget {
 
                 return Color.getDynamicGlucoseColor(
                     glucoseValue: Decimal(string: state.bg) ?? 100,
-                    highGlucoseColorValue: hardCodedHigh,
-                    lowGlucoseColorValue: hardCodedLow,
+                    highGlucoseColorValue: !hasStaticColorScheme ? hardCodedHigh : state.highGlucose,
+                    lowGlucoseColorValue: !hasStaticColorScheme ? hardCodedLow : state.lowGlucose,
                     targetGlucose: isMgdL ? state.target : state.target.asMmolL,
                     glucoseColorScheme: state.glucoseColorScheme
                 )
             }
 
-            let hasStaticColorScheme = context.state.glucoseColorScheme == "staticColor"
-
             return DynamicIsland {
                 DynamicIslandExpandedRegion(.leading) {
                     LiveActivityExpandedLeadingView(context: context, glucoseColor: glucoseColor)
@@ -190,6 +190,10 @@ struct LiveActivityView: View {
     @Environment(\.colorScheme) var colorScheme
     var context: ActivityViewContext<LiveActivityAttributes>
 
+    private var hasStaticColorScheme: Bool {
+        context.state.glucoseColorScheme == "staticColor"
+    }
+
     private var glucoseColor: Color {
         let state = context.state
         let detailedState = state.detailedViewState
@@ -201,17 +205,13 @@ struct LiveActivityView: View {
 
         return Color.getDynamicGlucoseColor(
             glucoseValue: Decimal(string: state.bg) ?? 100,
-            highGlucoseColorValue: hardCodedHigh,
-            lowGlucoseColorValue: hardCodedLow,
+            highGlucoseColorValue: !hasStaticColorScheme ? hardCodedHigh : state.highGlucose,
+            lowGlucoseColorValue: !hasStaticColorScheme ? hardCodedLow : state.lowGlucose,
             targetGlucose: isMgdL ? state.target : state.target.asMmolL,
             glucoseColorScheme: state.glucoseColorScheme
         )
     }
 
-    private var hasStaticColorScheme: Bool {
-        context.state.glucoseColorScheme == "staticColor"
-    }
-
     var body: some View {
         if let detailedViewState = context.state.detailedViewState {
             VStack {
@@ -439,17 +439,17 @@ struct LiveActivityChartView: View {
 
     var body: some View {
         let state = context.state
-        let isMgdl: Bool = additionalState.unit == "mg/dL"
+        let isMgdL: Bool = additionalState.unit == "mg/dL"
 
         // Determine scale
         let minValue = min(additionalState.chart.min() ?? 39, 39) as Decimal
         let maxValue = max(additionalState.chart.max() ?? 300, 300) as Decimal
 
-        let yAxisRuleMarkMin = isMgdl ? state.lowGlucose : state.lowGlucose
+        let yAxisRuleMarkMin = isMgdL ? state.lowGlucose : state.lowGlucose
             .asMmolL
-        let yAxisRuleMarkMax = isMgdl ? state.highGlucose : state.highGlucose
+        let yAxisRuleMarkMax = isMgdL ? state.highGlucose : state.highGlucose
             .asMmolL
-        let target = isMgdl ? state.target : state.target.asMmolL
+        let target = isMgdL ? state.target : state.target.asMmolL
 
         let isOverrideActive = additionalState.isOverrideActive == true
 
@@ -459,19 +459,24 @@ struct LiveActivityChartView: View {
         let startDate = calendar.date(byAdding: .hour, value: -6, to: now) ?? now
         let endDate = isOverrideActive ? (calendar.date(byAdding: .hour, value: 2, to: now) ?? now) : now
 
+        // TODO: workaround for now: set low value to 55, to have dynamic color shades between 55 and user-set low (approx. 70); same for high glucose
+        let hardCodedLow = isMgdL ? Decimal(55) : 55.asMmolL
+        let hardCodedHigh = isMgdL ? Decimal(220) : 220.asMmolL
+        let hasStaticColorScheme = context.state.glucoseColorScheme == "staticColor"
+
         let highColor = Color.getDynamicGlucoseColor(
             glucoseValue: yAxisRuleMarkMax,
-            highGlucoseColorValue: yAxisRuleMarkMax,
-            lowGlucoseColorValue: yAxisRuleMarkMin,
-            targetGlucose: isMgdl ? state.target : state.target.asMmolL,
+            highGlucoseColorValue: !hasStaticColorScheme ? hardCodedHigh : yAxisRuleMarkMax,
+            lowGlucoseColorValue: !hasStaticColorScheme ? hardCodedLow : yAxisRuleMarkMin,
+            targetGlucose: target,
             glucoseColorScheme: context.state.glucoseColorScheme
         )
 
         let lowColor = Color.getDynamicGlucoseColor(
             glucoseValue: yAxisRuleMarkMin,
-            highGlucoseColorValue: yAxisRuleMarkMax,
-            lowGlucoseColorValue: yAxisRuleMarkMin,
-            targetGlucose: isMgdl ? state.target : state.target.asMmolL,
+            highGlucoseColorValue: !hasStaticColorScheme ? hardCodedHigh : yAxisRuleMarkMax,
+            lowGlucoseColorValue: !hasStaticColorScheme ? hardCodedLow : yAxisRuleMarkMin,
+            targetGlucose: target,
             glucoseColorScheme: context.state.glucoseColorScheme
         )
 
@@ -546,11 +551,12 @@ struct LiveActivityChartView: View {
             // TODO: workaround for now: set low value to 55, to have dynamic color shades between 55 and user-set low (approx. 70); same for high glucose
             let hardCodedLow = Decimal(55)
             let hardCodedHigh = Decimal(220)
+            let hasStaticColorScheme = context.state.glucoseColorScheme == "staticColor"
 
             let pointMarkColor = Color.getDynamicGlucoseColor(
                 glucoseValue: currentValue,
-                highGlucoseColorValue: hardCodedHigh,
-                lowGlucoseColorValue: hardCodedLow,
+                highGlucoseColorValue: !hasStaticColorScheme ? hardCodedHigh : context.state.highGlucose,
+                lowGlucoseColorValue: !hasStaticColorScheme ? hardCodedLow : context.state.lowGlucose,
                 targetGlucose: context.state.target,
                 glucoseColorScheme: context.state.glucoseColorScheme
             )