Explorar el Código

add setting for live activity to display complex or simple view

polscm32 hace 2 años
padre
commit
36d82f2618

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

@@ -50,5 +50,6 @@
   "fattyMealFactor": 0.7,
   "fattyMealFactor": 0.7,
   "sweetMeals": false,
   "sweetMeals": false,
   "sweetMealFactor": 2
   "sweetMealFactor": 2
-  "historyLayout": "twoTabs"
+  "historyLayout": "twoTabs",
+  "lockScreenView": "simple"
 }
 }

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

@@ -55,6 +55,7 @@ struct FreeAPSSettings: JSON, Equatable {
     var displayPredictions: Bool = true
     var displayPredictions: Bool = true
     var useLiveActivity: Bool = false
     var useLiveActivity: Bool = false
     var historyLayout: HistoryLayout = .twoTabs
     var historyLayout: HistoryLayout = .twoTabs
+    var lockScreenView: LockScreenView = .simple
 }
 }
 
 
 extension FreeAPSSettings: Decodable {
 extension FreeAPSSettings: Decodable {
@@ -283,6 +284,10 @@ extension FreeAPSSettings: Decodable {
         if let historyLayout = try? container.decode(HistoryLayout.self, forKey: .historyLayout) {
         if let historyLayout = try? container.decode(HistoryLayout.self, forKey: .historyLayout) {
             settings.historyLayout = historyLayout
             settings.historyLayout = historyLayout
         }
         }
+        
+        if let lockScreenView = try? container.decode(LockScreenView.self, forKey: .lockScreenView) {
+            settings.lockScreenView = lockScreenView
+        }
 
 
         self = settings
         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: "")
+        }
+    }
+}

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

@@ -13,6 +13,7 @@ extension StatConfig {
         @Published var useFPUconversion: Bool = true
         @Published var useFPUconversion: Bool = true
         @Published var tins: Bool = false
         @Published var tins: Bool = false
         @Published var historyLayout: HistoryLayout = .twoTabs
         @Published var historyLayout: HistoryLayout = .twoTabs
+        @Published var lockScreenView: LockScreenView = .simple
 
 
         var units: GlucoseUnits = .mmolL
         var units: GlucoseUnits = .mmolL
 
 
@@ -29,6 +30,7 @@ extension StatConfig {
             subscribeSetting(\.skipBolusScreenAfterCarbs, on: $skipBolusScreenAfterCarbs) { skipBolusScreenAfterCarbs = $0 }
             subscribeSetting(\.skipBolusScreenAfterCarbs, on: $skipBolusScreenAfterCarbs) { skipBolusScreenAfterCarbs = $0 }
             subscribeSetting(\.oneDimensionalGraph, on: $oneDimensionalGraph) { oneDimensionalGraph = $0 }
             subscribeSetting(\.oneDimensionalGraph, on: $oneDimensionalGraph) { oneDimensionalGraph = $0 }
             subscribeSetting(\.historyLayout, on: $historyLayout) { historyLayout = $0 }
             subscribeSetting(\.historyLayout, on: $historyLayout) { historyLayout = $0 }
+            subscribeSetting(\.lockScreenView, on: $lockScreenView) { lockScreenView = $0 }
 
 
             subscribeSetting(\.low, on: $low, initial: {
             subscribeSetting(\.low, on: $low, initial: {
                 let value = max(min($0, 90), 40)
                 let value = max(min($0, 90), 40)

+ 11 - 0
FreeAPS/Sources/Modules/StatConfig/View/StatConfigRootView.swift

@@ -66,6 +66,17 @@ extension StatConfig {
                         }
                         }
                     }
                     }
                 } header: { Text("History Settings") }
                 } header: { Text("History Settings") }
+                
+                Section {
+                    Picker(
+                        selection: $state.lockScreenView,
+                        label: Text("Lock screen widget")
+                    ) {
+                        ForEach(LockScreenView.allCases) { selection in
+                            Text(selection.displayName).tag(selection)
+                        }
+                    }
+                } header: { Text("Lock screen widget") }
             }
             }
             .onAppear(perform: configureView)
             .onAppear(perform: configureView)
             .navigationBarTitle("UI/UX")
             .navigationBarTitle("UI/UX")

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

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

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

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

+ 42 - 27
LiveActivity/LiveActivity.swift

@@ -148,35 +148,50 @@ struct LiveActivity: Widget {
     var body: some WidgetConfiguration {
     var body: some WidgetConfiguration {
         ActivityConfiguration(for: LiveActivityAttributes.self) { context in
         ActivityConfiguration(for: LiveActivityAttributes.self) { context in
             // Lock screen/banner UI goes here
             // 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: { context in
             DynamicIsland {
             DynamicIsland {
                 // Expanded UI goes here.  Compose the expanded UI through
                 // Expanded UI goes here.  Compose the expanded UI through