Parcourir la source

Color glucose in Header View

Jon Mårtensson il y a 3 ans
Parent
commit
6d4de85029

+ 18 - 1
FreeAPS/Sources/Modules/Home/View/Header/CurrentGlucoseView.swift

@@ -45,7 +45,7 @@ struct CurrentGlucoseView: View {
                 )
                 .font(.system(size: 24, weight: .bold))
                 .fixedSize()
-                .foregroundColor(alarm == nil ? .primary : .loopRed)
+                .foregroundColor(alarm == nil ? colorOfGlucose : .loopRed)
                 image.padding(.bottom, 2)
 
             }.padding(.leading, 4)
@@ -91,4 +91,21 @@ struct CurrentGlucoseView: View {
             return Image(systemName: "arrow.left.and.right")
         }
     }
+
+    var colorOfGlucose: Color {
+        let whichGlucose = recentGlucose?.glucose ?? 0
+
+        switch whichGlucose {
+        case 72 ... 145:
+            return .loopGreen
+        case 1 ... 55,
+             217...:
+            return .loopRed
+        case 56 ... 71,
+             146 ... 216:
+            return .loopYellow
+        default:
+            return .primary
+        }
+    }
 }

+ 0 - 14
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -722,19 +722,5 @@ extension Home {
                 }
             }
         }
-
-        private func colorOfGlucose(_ glucose: Decimal) -> Color {
-            switch glucose {
-            case 4 ... 8,
-                 30 ... 46,
-                 72 ... 144:
-                return .loopGreen
-            case 0 ... 4,
-                 20 ... 71:
-                return .loopRed
-            default:
-                return .loopYellow
-            }
-        }
     }
 }