소스 검색

add setting for live activity to display complex or simple view

polscm32 2 년 전
부모
커밋
570dd3a611

+ 2 - 1
FreeAPS/Resources/json/defaults/freeaps/freeaps_settings.json

@@ -40,5 +40,6 @@
   "oneDimensionalGraph" : false,
   "rulerMarks" : false,
   "maxCarbs": 1000,
-  "displayFatAndProteinOnWatch": false
+  "displayFatAndProteinOnWatch": false,
+  "lockScreenView": "simple"
 }

+ 4 - 0
FreeAPS/Sources/Models/FreeAPSSettings.swift

@@ -44,6 +44,7 @@ struct FreeAPSSettings: JSON, Equatable {
     var displayFatAndProteinOnWatch: Bool = false
     var onlyAutotuneBasals: Bool = false
     var useLiveActivity: Bool = false
+    var lockScreenView: LockScreenView = .simple
 }
 
 extension FreeAPSSettings: Decodable {
@@ -228,6 +229,9 @@ extension FreeAPSSettings: Decodable {
         if let useLiveActivity = try? container.decode(Bool.self, forKey: .useLiveActivity) {
             settings.useLiveActivity = useLiveActivity
         }
+        if let lockScreenView = try? container.decode(LockScreenView.self, forKey: .lockScreenView) {
+            settings.lockScreenView = lockScreenView
+        }
 
         self = settings
     }

+ 16 - 0
FreeAPS/Sources/Models/LockScreenView.swift

@@ -0,0 +1,16 @@
+import Foundation
+
+enum LockScreenView: String, JSON, CaseIterable, Identifiable, Codable, Hashable {
+    var id: String { rawValue }
+    case simple
+    case detailed
+
+    var displayName: String {
+        switch self {
+        case .simple:
+            return NSLocalizedString("Simple", comment: "")
+        case .detailed:
+            return NSLocalizedString("Detailed", comment: "")
+        }
+    }
+}

+ 8 - 0
FreeAPS/Sources/Modules/NotificationsConfig/View/NotificationsConfigRootView.swift

@@ -64,6 +64,14 @@ extension NotificationsConfig {
                         )
                     ) {
                         Toggle("Show live activity", isOn: $state.useLiveActivity)
+                        Picker(
+                            selection: $state.lockScreenView,
+                            label: Text("Lock screen widget")
+                        ) {
+                            ForEach(LockScreenView.allCases) { selection in
+                                Text(selection.displayName).tag(selection)
+                            }
+                        }
                     }
                 }
             }

+ 2 - 0
FreeAPS/Sources/Modules/StatConfig/StatConfigStateModel.swift

@@ -10,6 +10,7 @@ extension StatConfig {
         @Published var yGridLines: Bool = false
         @Published var oneDimensionalGraph = false
         @Published var rulerMarks: Bool = false
+        @Published var lockScreenView: LockScreenView = .simple
 
         var units: GlucoseUnits = .mmolL
 
@@ -22,6 +23,7 @@ extension StatConfig {
             subscribeSetting(\.yGridLines, on: $yGridLines) { yGridLines = $0 }
             subscribeSetting(\.rulerMarks, on: $rulerMarks) { rulerMarks = $0 }
             subscribeSetting(\.oneDimensionalGraph, on: $oneDimensionalGraph) { oneDimensionalGraph = $0 }
+            subscribeSetting(\.lockScreenView, on: $lockScreenView) { lockScreenView = $0 }
 
             subscribeSetting(\.low, on: $low, initial: {
                 let value = max(min($0, 90), 40)

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

@@ -14,6 +14,7 @@ struct LiveActivityAttributes: ActivityAttributes {
         let lowGlucose: Double
         let cob: Decimal
         let iob: Decimal
+        let lockScreenView: String
     }
 
     let startDate: Date

+ 5 - 2
FreeAPS/Sources/Services/LiveActivity/LiveActivityBridge.swift

@@ -90,6 +90,8 @@ extension LiveActivityAttributes.ContentState {
         let cob = suggestion.cob ?? 0
         let iob = suggestion.iob ?? 0
 
+        let lockScreenView = settings.lockScreenView.displayName
+        
         self.init(
             bg: formattedBG,
             trendSystemImage: trendString,
@@ -101,7 +103,8 @@ extension LiveActivityAttributes.ContentState {
             highGlucose: Double(highGlucose),
             lowGlucose: Double(lowGlucose),
             cob: cob,
-            iob: iob
+            iob: iob,
+            lockScreenView: lockScreenView
         )
     }
 }
@@ -146,7 +149,7 @@ extension LiveActivityAttributes.ContentState {
     init(resolver: Resolver) {
         injectServices(resolver)
         broadcaster.register(GlucoseObserver.self, observer: self)
-
+        
         Foundation.NotificationCenter.default.addObserver(
             forName: UIApplication.didEnterBackgroundNotification,
             object: nil,

+ 42 - 27
LiveActivity/LiveActivity.swift

@@ -148,35 +148,50 @@ struct LiveActivity: Widget {
     var body: some WidgetConfiguration {
         ActivityConfiguration(for: LiveActivityAttributes.self) { context in
             // Lock screen/banner UI goes here
-
-            HStack(spacing: 2) {
-                VStack {
-                    chart(context: context).frame(width: UIScreen.main.bounds.width / 1.8)
-                }.padding(.all, 15)
-                Divider().foregroundStyle(Color.white)
-                VStack(alignment: .center) {
-                    Spacer()
-                    ZStack {
-                        bobble(context: context)
-                            .scaleEffect(0.6)
-                            .clipped()
-                        VStack {
-                            bgLabel(context: context).font(.title2).imageScale(.small)
-                            changeLabel(context: context).font(.callout)
-                        }
-                    }.scaleEffect(0.85).offset(y: 15)
-                    mealLabel(context: context).padding(.bottom, 8)
-                    updatedLabel(context: context).font(.caption).padding(.bottom, 50)
+            if context.state.lockScreenView == "Simple" {
+                HStack(spacing: 3) {
+                   bgAndTrend(context: context).font(.title)
+                   Spacer()
+                   VStack(alignment: .trailing, spacing: 5) {
+                       changeLabel(context: context).font(.title3)
+                       updatedLabel(context: context).font(.caption).foregroundStyle(.black.opacity(0.7))
+                   }
+               }
+               .privacySensitive()
+               .imageScale(.small)
+               .padding(.all, 15)
+               .background(Color.white.opacity(0.2))
+               .foregroundColor(Color.black)
+               .activityBackgroundTint(Color.cyan.opacity(0.2))
+               .activitySystemActionForegroundColor(Color.black)
+            } else {
+                HStack(spacing: 2) {
+                    VStack {
+                        chart(context: context).frame(width: UIScreen.main.bounds.width / 1.8)
+                    }.padding(.all, 15)
+                    Divider().foregroundStyle(Color.white)
+                    VStack(alignment: .center) {
+                        Spacer()
+                        ZStack {
+                            bobble(context: context)
+                                .scaleEffect(0.6)
+                                .clipped()
+                            VStack {
+                                bgLabel(context: context).font(.title2).imageScale(.small)
+                                changeLabel(context: context).font(.callout)
+                            }
+                        }.scaleEffect(0.85).offset(y: 15)
+                        mealLabel(context: context).padding(.bottom, 8)
+                        updatedLabel(context: context).font(.caption).padding(.bottom, 50)
+                    }
                 }
+                .privacySensitive()
+                .imageScale(.small)
+                .background(Color.white.opacity(0.2))
+                .foregroundColor(Color.white)
+                .activityBackgroundTint(Color.black.opacity(0.7))
+                .activitySystemActionForegroundColor(Color.white)
             }
-            .privacySensitive()
-            .imageScale(.small)
-//            .padding(.all, 15)
-            .background(Color.white.opacity(0.2))
-            .foregroundColor(Color.white)
-            .activityBackgroundTint(Color.black.opacity(0.7))
-            .activitySystemActionForegroundColor(Color.white)
-
         } dynamicIsland: { context in
             DynamicIsland {
                 // Expanded UI goes here.  Compose the expanded UI through