Переглянути джерело

Use .asMmolL instead of calculate it again.

(cherry picked from commit a12f70a34f5a58537faa45e8eaa2c4d54622e3d7)
(cherry picked from commit 2793cbafcd5729923638f3739d870003dc7996a0)
Jon Mårtensson 5 роки тому
батько
коміт
e3039009a5

+ 32 - 33
FreeAPS/Sources/Modules/Home/View/Header/CurrentGlucoseView.swift

@@ -55,45 +55,44 @@ struct CurrentGlucoseView: View {
                         .map { deltaFormatter.string(from: Double(units == .mmolL ? $0.asMmolL : Decimal($0)) as NSNumber)!
                         } ??
                         "--"
-                    
-                ).font(.caption2).foregroundColor(.secondary)
-            }
+                ).font(.system(size: 12, weight: .bold)) }
         }
+    }
 
-        var colorOfGlucose: Color {
-            guard var recentBG = recentGlucose?.glucose
-            else { return .loopYellow }
-
-            recentBG /= 18 // convert to mmol/l for calculation
+    var colorOfGlucose: Color {
+        guard var recentBG = recentGlucose?.glucose
+        else { return .loopYellow }
 
-            switch recentBG {
-            case 4 ... 7:
-                return .loopGreen
-            case 8 ... 9:
-                return .loopYellow
-            default:
-                return .loopRed
-            }
+        recentBG = Int(recentBG.asMmolL) // convert to mmol/l for calculation
+        
+        switch recentBG {
+        case 4 ... 7:
+            return .loopGreen
+        case 8 ... 9:
+            return .loopYellow
+        default:
+            return .loopRed
         }
+    }
 
-        var minutesAgo: Int {
-            let lastGlucoseDateString = recentGlucose.map { dateFormatter.string(from: $0.dateString) } ?? "--"
-            let LastGlucoseDate = Date(lastGlucoseDateString) ?? Date()
-            let now = Date()
-            let diff = Int(now.timeIntervalSince1970 - LastGlucoseDate.timeIntervalSince1970)
-            let hoursDiff = diff / 3600
-            let minutesDiff = (diff - hoursDiff * 3600) / 60
-            return minutesDiff
-        }
+    var minutesAgo: Int {
+        let lastGlucoseDateString = recentGlucose.map { dateFormatter.string(from: $0.dateString) } ?? "--"
+        let LastGlucoseDate = Date(lastGlucoseDateString) ?? Date()
+        let now = Date()
+        let diff = Int(now.timeIntervalSince1970 - LastGlucoseDate.timeIntervalSince1970)
+        let hoursDiff = diff / 3600
+        let minutesDiff = (diff - hoursDiff * 3600) / 60
+        return minutesDiff
+    }
 
-        func colorOfMinutesAgo(_ minutes: Int) -> Color {
-            switch minutes {
-            case 0 ... 5:
-                return .loopGreen
-            case 6 ... 9:
-                return .loopYellow
-            default:
-                return .loopRed
+    func colorOfMinutesAgo(_ minutes: Int) -> Color {
+        switch minutes {
+        case 0 ... 5:
+            return .loopGreen
+        case 6 ... 9:
+            return .loopYellow
+        default:
+            return .loopRed
         }
     }