Procházet zdrojové kódy

Merge branch 'dev' into feat-addtoproject

Sjoerd-Bo3 před 1 rokem
rodič
revize
b87c0b90fd

+ 6 - 1
FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift

@@ -316,7 +316,12 @@ extension DataTable {
                         state.units == .mmolL ? $0.asMmolL : Decimal($0)
                     ) as NSNumber)!
                 } ?? "--")
-                Text(item.glucose.direction?.symbol ?? "--")
+                if item.glucose.type == "Manual" {
+                    Image(systemName: "drop.fill")
+                        .foregroundColor(Color.loopRed)
+                } else {
+                    Text(item.glucose.direction?.symbol ?? "--")
+                }
                 Spacer()
 
                 Text(dateFormatter.string(from: item.glucose.dateString))

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

@@ -57,6 +57,7 @@ struct MainChartView: View {
     @State var didAppearTrigger = false
     @State private var glucoseDots: [CGRect] = []
     @State private var unSmoothedGlucoseDots: [CGRect] = []
+    @State private var manualGlucoseDots: [CGRect] = []
     @State private var predictionDots: [PredictionType: [CGRect]] = [:]
     @State private var bolusDots: [DotInfo] = []
     @State private var bolusPath = Path()
@@ -270,6 +271,7 @@ struct MainChartView: View {
                     bolusView(fullSize: fullSize)
                     if smooth { unSmoothedGlucoseView(fullSize: fullSize) }
                     glucoseView(fullSize: fullSize)
+                    manualGlucoseView(fullSize: fullSize)
                     predictionsView(fullSize: fullSize)
                 }
                 timeLabelsView(fullSize: fullSize)
@@ -363,6 +365,32 @@ struct MainChartView: View {
         }
     }
 
+    private func manualGlucoseView(fullSize: CGSize) -> some View {
+        ZStack {
+            Path { path in
+                for rect in manualGlucoseDots {
+                    path.addEllipse(in: rect)
+                }
+            }
+            .fill(Color.loopRed)
+            Path { path in
+                for rect in manualGlucoseDots {
+                    path.addEllipse(in: rect)
+                }
+            }
+            .stroke(Color.primary, lineWidth: 0.5)
+        }
+        .onChange(of: glucose) { _ in
+            update(fullSize: fullSize)
+        }
+        .onChange(of: didAppearTrigger) { _ in
+            update(fullSize: fullSize)
+        }
+        .onReceive(Foundation.NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
+            update(fullSize: fullSize)
+        }
+    }
+
     private func bolusView(fullSize: CGSize) -> some View {
         ZStack {
             bolusPath
@@ -489,6 +517,7 @@ extension MainChartView {
         calculatePredictionDots(fullSize: fullSize, type: .uam)
         calculateGlucoseDots(fullSize: fullSize)
         calculateUnSmoothedGlucoseDots(fullSize: fullSize)
+        calculateManualGlucoseDots(fullSize: fullSize)
         calculateBolusDots(fullSize: fullSize)
         calculateCarbsDots(fullSize: fullSize)
         calculateFPUsDots(fullSize: fullSize)
@@ -499,7 +528,10 @@ extension MainChartView {
 
     private func calculateGlucoseDots(fullSize: CGSize) {
         calculationQueue.async {
-            let dots = glucose.concurrentMap { value -> CGRect in
+            let sgvs = glucose
+                .filter { $0.type != "Manual"
+                } // as fingerpricks will be drawn differently, slightly larger and red - so do not draw them here
+            let dots = sgvs.concurrentMap { value -> CGRect in
                 let position = glucoseToCoordinate(value, fullSize: fullSize)
                 return CGRect(x: position.x - 2, y: position.y - 2, width: 4, height: 4)
             }
@@ -515,7 +547,8 @@ extension MainChartView {
 
     private func calculateUnSmoothedGlucoseDots(fullSize: CGSize) {
         calculationQueue.async {
-            let dots = glucose.concurrentMap { value -> CGRect in
+            let sgvs = glucose.filter { $0.type == "sgv" }
+            let dots = sgvs.concurrentMap { value -> CGRect in
                 let position = UnSmoothedGlucoseToCoordinate(value, fullSize: fullSize)
                 return CGRect(x: position.x - 2, y: position.y - 2, width: 4, height: 4)
             }
@@ -529,6 +562,23 @@ extension MainChartView {
         }
     }
 
+    private func calculateManualGlucoseDots(fullSize: CGSize) {
+        calculationQueue.async {
+            let manuals = glucose.filter { $0.type == "Manual" }
+            let dots = manuals.concurrentMap { value -> CGRect in
+                let position = glucoseToCoordinate(value, fullSize: fullSize)
+                return CGRect(x: position.x - 2, y: position.y - 2, width: 6, height: 6)
+            }
+
+            let range = self.getGlucoseYRange(fullSize: fullSize)
+
+            DispatchQueue.main.async {
+                glucoseYRange = range
+                manualGlucoseDots = dots
+            }
+        }
+    }
+
     private func calculateBolusDots(fullSize: CGSize) {
         calculationQueue.async {
             let dots = boluses.map { value -> DotInfo in