polscm32 пре 2 година
родитељ
комит
62c9f7ce16

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

@@ -9,6 +9,7 @@ struct LiveActivityAttributes: ActivityAttributes {
         let date: Date
         let date: Date
         let chart: [Int?]
         let chart: [Int?]
         let chartDate: [Date?]
         let chartDate: [Date?]
+        let rotationDegrees: Double
     }
     }
 
 
     let startDate: Date
     let startDate: Date

+ 8 - 1
FreeAPS/Sources/Services/LiveActivity/LiveActivityBridge.swift

@@ -31,31 +31,38 @@ extension LiveActivityAttributes.ContentState {
         let formattedBG = Self.formatGlucose(glucose, mmol: mmol, forceSign: false)
         let formattedBG = Self.formatGlucose(glucose, mmol: mmol, forceSign: false)
 
 
         let trendString: String?
         let trendString: String?
+        var rotationDegrees: Double = 0.0
         switch bg.direction {
         switch bg.direction {
         case .doubleUp,
         case .doubleUp,
              .singleUp,
              .singleUp,
              .tripleUp:
              .tripleUp:
             trendString = "arrow.up"
             trendString = "arrow.up"
+            rotationDegrees = -90
 
 
         case .fortyFiveUp:
         case .fortyFiveUp:
             trendString = "arrow.up.right"
             trendString = "arrow.up.right"
+            rotationDegrees = -45
 
 
         case .flat:
         case .flat:
             trendString = "arrow.right"
             trendString = "arrow.right"
+            rotationDegrees = 0
 
 
         case .fortyFiveDown:
         case .fortyFiveDown:
             trendString = "arrow.down.right"
             trendString = "arrow.down.right"
+            rotationDegrees = 45
 
 
         case .doubleDown,
         case .doubleDown,
              .singleDown,
              .singleDown,
              .tripleDown:
              .tripleDown:
             trendString = "arrow.down"
             trendString = "arrow.down"
+            rotationDegrees = 90
 
 
         case .notComputable,
         case .notComputable,
              Optional.none,
              Optional.none,
              .rateOutOfRange,
              .rateOutOfRange,
              .some(.none):
              .some(.none):
             trendString = nil
             trendString = nil
+            rotationDegrees = 0
         }
         }
 
 
         let change = prev?.glucose.map({
         let change = prev?.glucose.map({
@@ -72,7 +79,7 @@ extension LiveActivityAttributes.ContentState {
             change: change,
             change: change,
             date: bg.dateString,
             date: bg.dateString,
             chart: chartBG,
             chart: chartBG,
-            chartDate: chartDate
+            chartDate: chartDate, rotationDegrees: rotationDegrees
         )
         )
     }
     }
 }
 }

+ 19 - 6
LiveActivity/LiveActivity.swift

@@ -54,6 +54,21 @@ struct LiveActivity: Widget {
         }
         }
     }
     }
 
 
+    @ViewBuilder func bobble(context: ActivityViewContext<LiveActivityAttributes>) -> some View {
+        @State var angularGradient = AngularGradient(colors: [
+            Color(red: 0.7215686275, green: 0.3411764706, blue: 1),
+            Color(red: 0.6235294118, green: 0.4235294118, blue: 0.9803921569),
+            Color(red: 0.4862745098, green: 0.5450980392, blue: 0.9529411765),
+            Color(red: 0.3411764706, green: 0.6666666667, blue: 0.9254901961),
+            Color(red: 0.262745098, green: 0.7333333333, blue: 0.9137254902),
+            Color(red: 0.7215686275, green: 0.3411764706, blue: 1)
+        ], center: .center, startAngle: .degrees(270), endAngle: .degrees(-90))
+        let triangleColor = Color(red: 0.262745098, green: 0.7333333333, blue: 0.9137254902)
+
+        WidgetBobble(gradient: angularGradient, color: triangleColor)
+            .rotationEffect(.degrees(context.state.rotationDegrees))
+    }
+
     @ViewBuilder func chart(context: ActivityViewContext<LiveActivityAttributes>) -> some View {
     @ViewBuilder func chart(context: ActivityViewContext<LiveActivityAttributes>) -> some View {
         if context.isStale {
         if context.isStale {
             Text("--")
             Text("--")
@@ -84,13 +99,11 @@ struct LiveActivity: Widget {
             HStack(spacing: 2) {
             HStack(spacing: 2) {
                 VStack {
                 VStack {
                     chart(context: context).frame(width: UIScreen.main.bounds.width / 1.7)
                     chart(context: context).frame(width: UIScreen.main.bounds.width / 1.7)
-                }
+                }.padding(.vertical, 5).padding(.horizontal, 15)
                 Divider()
                 Divider()
                 VStack {
                 VStack {
                     ZStack {
                     ZStack {
-//                        Circle().fill(Color.green.opacity(0.7))
-//                            .frame(width: UIScreen.main.bounds.width / 5, height: UIScreen.main.bounds.height / 5).clipped()
-                        WidgetBobble()
+                        bobble(context: context)
                             .scaleEffect(0.6)
                             .scaleEffect(0.6)
                             .clipped()
                             .clipped()
                         VStack {
                         VStack {
@@ -98,8 +111,8 @@ struct LiveActivity: Widget {
                             bgLabel(context: context).font(.title2).imageScale(.small)
                             bgLabel(context: context).font(.title2).imageScale(.small)
                             changeLabel(context: context).font(.callout)
                             changeLabel(context: context).font(.callout)
                         }
                         }
-                    }
-                    updatedLabel(context: context).font(.caption)
+                    }.padding(.trailing, 5).padding(.top, 5)
+                    updatedLabel(context: context).font(.caption).padding(.bottom)
                 }
                 }
             }
             }
             .privacySensitive()
             .privacySensitive()

+ 15 - 74
LiveActivity/WidgetBobble.swift

@@ -1,80 +1,6 @@
 import SwiftUI
 import SwiftUI
 
 
 struct WidgetBobble: View {
 struct WidgetBobble: View {
-    @State private var rotationDegrees: Double = 0.0
-    @State private var angularGradient = AngularGradient(colors: [
-        // 184, 87, 255
-        // 159, 108, 250
-        // 124, 139, 243
-        // 87, 170, 236
-        // 67, 187, 233
-        Color(red: 0.7215686275, green: 0.3411764706, blue: 1),
-        Color(red: 0.6235294118, green: 0.4235294118, blue: 0.9803921569),
-        Color(red: 0.4862745098, green: 0.5450980392, blue: 0.9529411765),
-        Color(red: 0.3411764706, green: 0.6666666667, blue: 0.9254901961),
-        Color(red: 0.262745098, green: 0.7333333333, blue: 0.9137254902),
-        Color(red: 0.7215686275, green: 0.3411764706, blue: 1)
-    ], center: .center, startAngle: .degrees(270), endAngle: .degrees(-90))
-
-    @Environment(\.colorScheme) var colorScheme
-
-    var body: some View {
-        let triangleColor = Color(red: 0.262745098, green: 0.7333333333, blue: 0.9137254902)
-
-        TrendShape(gradient: angularGradient, color: triangleColor)
-            .rotationEffect(.degrees(rotationDegrees))
-
-//            .onChange(of: context.state.bg) { newDirection in
-//            withAnimation {
-//                switch newDirection {
-//                case .doubleUp,
-//                     .singleUp,
-//                     .tripleUp:
-//                    rotationDegrees = -90
-//
-//                case .fortyFiveUp:
-//                    rotationDegrees = -45
-//
-//                case .flat:
-//                    rotationDegrees = 0
-//
-//                case .fortyFiveDown:
-//                    rotationDegrees = 45
-//
-//                case .doubleDown,
-//                     .singleDown,
-//                     .tripleDown:
-//                    rotationDegrees = 90
-//
-//                case .none,
-//                     .notComputable,
-//                     .rateOutOfRange:
-//                    rotationDegrees = 0
-//
-//                @unknown default:
-//                    rotationDegrees = 0
-//                }
-//            }
-//        }
-    }
-}
-
-struct Triangle: Shape {
-    func path(in rect: CGRect) -> Path {
-        var path = Path()
-
-        let cornerRadius: CGFloat = 8
-
-        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.closeSubpath()
-
-        return path
-    }
-}
-
-struct TrendShape: View {
     @Environment(\.colorScheme) var colorScheme
     @Environment(\.colorScheme) var colorScheme
 
 
     let gradient: AngularGradient
     let gradient: AngularGradient
@@ -123,3 +49,18 @@ struct TriangleShape: View {
             .offset(x: 70)
             .offset(x: 70)
     }
     }
 }
 }
+
+struct Triangle: Shape {
+    func path(in rect: CGRect) -> Path {
+        var path = Path()
+
+        let cornerRadius: CGFloat = 8
+
+        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.closeSubpath()
+
+        return path
+    }
+}