Просмотр исходного кода

fix conversion in mmol/L for y axis labels in live activity charts

improve readability for lockscreen widget in light mode
polscm32 2 лет назад
Родитель
Сommit
24b35a4c23

+ 1 - 1
FreeAPS/Sources/Services/LiveActivity/LiveActitiyShared.swift

@@ -7,7 +7,7 @@ struct LiveActivityAttributes: ActivityAttributes {
         let trendSystemImage: String?
         let change: String
         let date: Date
-        let chart: [Int16]
+        let chart: [Double]
         let chartDate: [Date?]
         let rotationDegrees: Double
     }

+ 9 - 7
FreeAPS/Sources/Services/LiveActivity/LiveActivityBridge.swift

@@ -21,7 +21,7 @@ extension LiveActivityAttributes.ContentState {
             .string(from: mmol ? value.asMmolL as NSNumber : NSNumber(value: value))!
     }
 
-    init?(new bg: BloodGlucose, prev: BloodGlucose?, mmol: Bool, chart: [Readings]) {
+    init?(new bg: BloodGlucose, prev: BloodGlucose?, mmol: Bool, chart: [Readings], settings: FreeAPSSettings) {
         guard let glucose = bg.glucose,
               bg.dateString.timeIntervalSinceNow > -TimeInterval(minutes: 6)
         else {
@@ -71,6 +71,9 @@ extension LiveActivityAttributes.ContentState {
 
         let chartBG = chart.map(\.glucose)
 
+        let conversionFactor: Double = settings.units == .mmolL ? 18.0 : 1.0
+        let convertedChartBG = chartBG.map { Double($0) / conversionFactor }
+
         let chartDate = chart.map(\.date)
 
         self.init(
@@ -78,7 +81,7 @@ extension LiveActivityAttributes.ContentState {
             trendSystemImage: trendString,
             change: change,
             date: bg.dateString,
-            chart: chartBG,
+            chart: convertedChartBG,
             chartDate: chartDate, rotationDegrees: rotationDegrees
         )
     }
@@ -211,11 +214,8 @@ extension LiveActivityBridge: GlucoseObserver {
         defer {
             self.latestGlucose = glucose.last
         }
-
-//        let last72Glucose = Array(glucose.dropLast().suffix(72))
+//        fetch glucose for chart from Core Data
         let coreDataStorage = CoreDataStorage()
-
-//        let fetchGlucose = coreDataStorage.fetchGlucose(interval: DateFilter().day)
         let sixHoursAgo = Calendar.current.date(byAdding: .hour, value: -6, to: Date()) ?? Date()
         let fetchGlucose = coreDataStorage.fetchGlucose(interval: sixHoursAgo as NSDate)
 
@@ -223,7 +223,9 @@ extension LiveActivityBridge: GlucoseObserver {
             new: bg,
             prev: latestGlucose,
             mmol: settings.units == .mmolL,
-            chart: fetchGlucose
+
+            chart: fetchGlucose, settings: settings
+
         ) else {
             // no bg or value stale. Don't update the activity if there already is one, just let it turn stale so that it can still be used once current bg is available again
             return

+ 11 - 2
LiveActivity/LiveActivity.swift

@@ -84,7 +84,16 @@ struct LiveActivity: Widget {
                 plotContent.background(.cyan.opacity(0.1))
             }
             .chartYAxis {
-                AxisMarks(position: .leading)
+                AxisMarks(position: .leading) { _ in
+                    AxisValueLabel().foregroundStyle(Color.white)
+                    AxisGridLine(stroke: .init(lineWidth: 0.1, dash: [2, 3])).foregroundStyle(Color.white)
+                }
+            }
+            .chartXAxis {
+                AxisMarks(position: .automatic) { _ in
+                    AxisValueLabel().foregroundStyle(Color.white)
+                    AxisGridLine(stroke: .init(lineWidth: 0.1, dash: [2, 3])).foregroundStyle(Color.white)
+                }
             }
         }
     }
@@ -118,7 +127,7 @@ struct LiveActivity: Widget {
             .background(Color.white.opacity(0.2))
             .foregroundColor(Color.white)
             .activityBackgroundTint(Color.black.opacity(0.7))
-            .activitySystemActionForegroundColor(Color.black)
+            .activitySystemActionForegroundColor(Color.white)
 
         } dynamicIsland: { context in
             DynamicIsland {

+ 4 - 6
LiveActivity/WidgetBobble.swift

@@ -40,7 +40,7 @@ struct TriangleShapeWidget: View {
             .fill(color)
             .frame(width: 35, height: 35)
             .rotationEffect(.degrees(90))
-            .offset(x: 78)
+            .offset(x: 88)
     }
 }
 
@@ -48,11 +48,9 @@ struct TriangleWidget: Shape {
     func path(in rect: CGRect) -> Path {
         var path = Path()
 
-        let cornerRadius: CGFloat = 2
-
-        path.move(to: CGPoint(x: rect.midX, y: rect.minY))
-        path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY - cornerRadius))
-        path.addQuadCurve(to: CGPoint(x: rect.minX, y: rect.maxY - cornerRadius), control: CGPoint(x: rect.midX, y: rect.maxY))
+        path.move(to: CGPoint(x: rect.midX, y: rect.minY + 15))
+        path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
+        path.addQuadCurve(to: CGPoint(x: rect.minX, y: rect.maxY), control: CGPoint(x: rect.midX, y: rect.midY + 10))
         path.closeSubpath()
 
         return path