Bladeren bron

Major cleanup; address PR feedback by @10nas, @AndreasStokholm, @mikeplante1
* Clean up unnecessary boolean settings
* Properly update LA widget when order is changed by posting custom notification
* Move widgetItem fetch to LA bridge
* Remove edit mode, view is always in edit mode
* Adjust texts, remove unnecessary texts
* Misc

Deniz Cengiz 1 jaar geleden
bovenliggende
commit
469f2e5189

+ 0 - 6
FreeAPS/Resources/json/defaults/freeaps/freeaps_settings.json

@@ -54,12 +54,6 @@
   "sweetMeals": false,
   "sweetMealFactor": 2,
   "lockScreenView": "simple",
-  "showChart": true,
-  "showCurrentGlucose": true,
-  "showChangeLabel": true,
-  "showIOB": true,
-  "showCOB": true,
-  "showUpdatedLabel": true,
   "useCalendar": false,
   "displayCalendarIOBandCOB": false,
   "displayCalendarEmojis": false

+ 8 - 2
FreeAPS/Sources/Models/DecimalPickerSettings.swift

@@ -18,10 +18,16 @@ class PickerSettingsProvider: ObservableObject {
         }
 
         // Glucose values are stored as mg/dl values, so Integers.
-        // Filter out odd numbers to avoid duplicate mmol/L values due to rounding.
+        // Filter out duplicate values when rounded to 1 decimal place.
         if units == .mmolL, setting.type == PickerSetting.PickerSettingType.glucose {
-            values = values.filter { Int($0) % 2 == 0 }
+            // Use a Set to track unique values rounded to 1 decimal
+            var uniqueRoundedValues = Set<String>()
+            values = values.filter { value in
+                let roundedValue = String(format: "%.1f", NSDecimalNumber(decimal: value.asMmolL).doubleValue)
+                return uniqueRoundedValues.insert(roundedValue).inserted
+            }
         }
+
         return values
     }
 }

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

@@ -73,12 +73,6 @@ struct FreeAPSSettings: JSON, Equatable {
     var displayPresets: Bool = true
     var useLiveActivity: Bool = false
     var lockScreenView: LockScreenView = .simple
-    var showChart: Bool = true
-    var showCurrentGlucose: Bool = true
-    var showChangeLabel: Bool = true
-    var showIOB: Bool = true
-    var showCOB: Bool = true
-    var showUpdatedLabel: Bool = true
     var bolusShortcut: BolusShortcutLimit = .notAllowed
 }
 
@@ -321,30 +315,6 @@ extension FreeAPSSettings: Decodable {
             settings.lockScreenView = lockScreenView
         }
 
-        if let showChart = try? container.decode(Bool.self, forKey: .showChart) {
-            settings.showChart = showChart
-        }
-
-        if let showCurrentGlucose = try? container.decode(Bool.self, forKey: .showCurrentGlucose) {
-            settings.showCurrentGlucose = showCurrentGlucose
-        }
-
-        if let showChangeLabel = try? container.decode(Bool.self, forKey: .showChangeLabel) {
-            settings.showChangeLabel = showChangeLabel
-        }
-
-        if let showIOB = try? container.decode(Bool.self, forKey: .showIOB) {
-            settings.showIOB = showIOB
-        }
-
-        if let showCOB = try? container.decode(Bool.self, forKey: .showCOB) {
-            settings.showCOB = showCOB
-        }
-
-        if let showUpdatedLabel = try? container.decode(Bool.self, forKey: .showUpdatedLabel) {
-            settings.showUpdatedLabel = showUpdatedLabel
-        }
-
         if let bolusShortcut = try? container.decode(BolusShortcutLimit.self, forKey: .bolusShortcut) {
             settings.bolusShortcut = bolusShortcut
         }

+ 0 - 21
FreeAPS/Sources/Modules/LiveActivitySettings/LiveActivitySettingsStateModel.swift

@@ -8,25 +8,10 @@ extension LiveActivitySettings {
         @Published var units: GlucoseUnits = .mgdL
         @Published var useLiveActivity = false
         @Published var lockScreenView: LockScreenView = .simple
-        @Published var showChart: Bool = true
-        @Published var showCurrentGlucose: Bool = true
-        @Published var showChangeLabel: Bool = true
-        @Published var showIOB: Bool = true
-        @Published var showCOB: Bool = true
-        @Published var showUpdatedLabel: Bool = true
-
         override func subscribe() {
             units = settingsManager.settings.units
-
             subscribeSetting(\.useLiveActivity, on: $useLiveActivity) { useLiveActivity = $0 }
             subscribeSetting(\.lockScreenView, on: $lockScreenView) { lockScreenView = $0 }
-
-            subscribeSetting(\.showChart, on: $showChart) { showChart = $0 }
-            subscribeSetting(\.showCurrentGlucose, on: $showCurrentGlucose) { showCurrentGlucose = $0 }
-            subscribeSetting(\.showChangeLabel, on: $showChangeLabel) { showChangeLabel = $0 }
-            subscribeSetting(\.showIOB, on: $showIOB) { showIOB = $0 }
-            subscribeSetting(\.showCOB, on: $showCOB) { showCOB = $0 }
-            subscribeSetting(\.showUpdatedLabel, on: $showUpdatedLabel) { showUpdatedLabel = $0 }
         }
     }
 }
@@ -34,11 +19,5 @@ extension LiveActivitySettings {
 extension LiveActivitySettings.StateModel: SettingsObserver {
     func settingsDidChange(_: FreeAPSSettings) {
         units = settingsManager.settings.units
-        showChart = settingsManager.settings.showChart
-        showCurrentGlucose = settingsManager.settings.showCurrentGlucose
-        showChangeLabel = settingsManager.settings.showChangeLabel
-        showIOB = settingsManager.settings.showIOB
-        showCOB = settingsManager.settings.showCOB
-        showUpdatedLabel = settingsManager.settings.showUpdatedLabel
     }
 }

+ 37 - 92
FreeAPS/Sources/Modules/LiveActivitySettings/View/LiveActivityWidgetConfiguration.swift

@@ -12,11 +12,9 @@ struct LiveActivityWidgetConfiguration: BaseView {
     @State private var selectedItems: [LiveActivityItem?] = Array(repeating: nil, count: 4)
     @State private var showAddItemDialog: Bool = false
     @State private var buttonIndexToUpdate: Int?
-
-    @State private var isEditMode: Bool = false
-    @State private var draggingItem: LiveActivityItem?
     @State private var itemToRemove: LiveActivityItem?
     @State private var isRemovalConfirmationPresented: Bool = false
+    @State private var glucoseData: [DummyGlucoseData] = []
 
     @Environment(\.colorScheme) var colorScheme
     @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
@@ -49,25 +47,25 @@ struct LiveActivityWidgetConfiguration: BaseView {
             let time = Double(minute) / 60.0 // Convert minutes to hours
 
             let trendFactor: Double
+            let randomFactor = Double.random(in: -5 ... 5) // Add slight randomness to each point
 
             // Simulate different phases during the 6-hour window
             if time < 1 { // Stable glucose (pre-meal or fasting period)
-                trendFactor = 0.5 // Small increase
+                trendFactor = 0.5 + randomFactor // Small increase with some variability
             } else if time >= 1, time < 2 { // Glucose rising (e.g., post-meal spike)
-                trendFactor = 3.0 // Rapid increase for glucose spike
+                trendFactor = 3.0 + randomFactor // Rapid increase with slight variation
             } else if time >= 2, time < 3.5 { // Peak and plateau
-                trendFactor = -0.1 // Gradual decrease after the peak
+                trendFactor = -0.1 + randomFactor // Gradual decrease after the peak with variability
             } else if time >= 3.5, time < 4.5 { // Second peak (optional, simulate another meal)
-                trendFactor = 2.5 // Another spike (e.g., after a second meal)
+                trendFactor = 2.5 + randomFactor // Another spike with some randomness
             } else { // Post-meal decrease (insulin effect)
-                trendFactor = -1.5 // Glucose decreasing gradually
+                trendFactor = -1.5 + randomFactor // Glucose decreasing gradually with some variability
             }
 
-            // Calculate the next glucose level with trend factors only
+            // Calculate the next glucose level with trend factors
             glucoseLevel += trendFactor
 
             // Ensure glucose level doesn't go out of realistic bounds:
-            // Clamp glucose levels between 70 and 200 mg/dL
             glucoseLevel = max(70, min(glucoseLevel, 200))
 
             data.append(DummyGlucoseData(time: Double(minute), glucoseLevel: Int(glucoseLevel.rounded())))
@@ -76,30 +74,16 @@ struct LiveActivityWidgetConfiguration: BaseView {
     }
 
     var body: some View {
-        let glucoseData: [DummyGlucoseData] = generateDummyGlucoseData()
-
         VStack {
             Group {
-                VStack(alignment: .leading, spacing: 0) {
+                VStack(alignment: .trailing, spacing: 0) {
                     Text("Live Activity Personalization".uppercased())
                         .frame(maxWidth: .infinity, alignment: .leading)
                         .foregroundColor(.secondary)
                         .font(.footnote)
                         .padding(.leading)
                 }
-                VStack {
-                    Text(
-                        "Trio offers you to customize your Live Activity lock screen widget. The default configuration will display current glucose, IOB, COB and the time of last algorithm run."
-                    )
-                    .padding()
-                    .font(.footnote)
-                    .foregroundColor(.secondary)
-                }
-                .background(
-                    RoundedRectangle(cornerRadius: 10, style: .continuous)
-                        .fill(Color.chart)
-                )
-            }
+            }.padding(.bottom, -15)
 
             GroupBox {
                 VStack {
@@ -122,15 +106,15 @@ struct LiveActivityWidgetConfiguration: BaseView {
             }.padding(.vertical).groupBoxStyle(.dummyChart)
 
             Group {
-                Text(
-                    "Tap 'Edit Mode' to add or remove a widget. You can re-order widgets by removing them from their current position and adding them to the desired one."
-                )
-
-                Text("Note: Once you confirm the removal of a widget, you cannot undo it.")
+                HStack {
+                    Image(systemName: "info.circle")
+                    Text(
+                        "To re-order widgets, remove them and re-add them in the desired order."
+                    )
+                }
             }.frame(maxWidth: .infinity, alignment: .leading)
                 .foregroundColor(.secondary)
                 .font(.footnote)
-                .padding(.vertical, 8)
                 .padding(.horizontal)
 
             Spacer()
@@ -139,19 +123,13 @@ struct LiveActivityWidgetConfiguration: BaseView {
         .scrollContentBackground(.hidden).background(color)
         .navigationTitle("Widget Configuration")
         .navigationBarTitleDisplayMode(.automatic)
-        .toolbar {
-            ToolbarItem(placement: .topBarTrailing) {
-                Button {
-                    isEditMode.toggle()
-                } label: {
-                    Text(isEditMode ? "Exit Edit Mode" : "Edit Mode")
-                }
-            }
-        }
         .onAppear {
+            if glucoseData.isEmpty {
+                glucoseData = generateDummyGlucoseData()
+            }
             loadOrder() // Load the saved order when the view appears
         }
-        .confirmationDialog("Choose Widget to add", isPresented: $showAddItemDialog, titleVisibility: .visible) {
+        .confirmationDialog("Add Widget", isPresented: $showAddItemDialog, titleVisibility: .visible) {
             ForEach(LiveActivityItem.allCases.filter { !selectedItems.contains($0) }, id: \.self) { item in
                 Button(item.displayName) {
                     if let index = buttonIndexToUpdate {
@@ -175,23 +153,21 @@ struct LiveActivityWidgetConfiguration: BaseView {
                         RoundedRectangle(cornerRadius: 12)
                             .stroke(Color.primary, lineWidth: 1)
                     )
-                if isEditMode {
-                    Button(action: {
-                        isRemovalConfirmationPresented = true
-                        itemToRemove = selectedItem
-                    }) {
-                        Image(systemName: "minus.circle.fill")
-                            .foregroundColor(Color(UIColor.systemGray2))
-                            .background(Color.white)
-                            .clipShape(Circle())
-                            .font(.system(size: 20))
-                    }
-                    .offset(x: -45, y: -10)
-                    .confirmationDialog("Remove Widget", isPresented: $isRemovalConfirmationPresented, titleVisibility: .hidden) {
-                        Button("Remove Widget", role: .destructive) {
-                            if let itemToRemove = itemToRemove {
-                                removeItem(itemToRemove)
-                            }
+                Button(action: {
+                    isRemovalConfirmationPresented = true
+                    itemToRemove = selectedItem
+                }) {
+                    Image(systemName: "trash.circle.fill")
+                        .foregroundColor(Color(UIColor.systemGray2))
+                        .background(Color.white)
+                        .clipShape(Circle())
+                        .font(.system(size: 20))
+                }
+                .offset(x: 10, y: -10)
+                .confirmationDialog("Remove Widget", isPresented: $isRemovalConfirmationPresented, titleVisibility: .hidden) {
+                    Button("Remove Widget", role: .destructive) {
+                        if let itemToRemove = itemToRemove {
+                            removeItem(itemToRemove)
                         }
                     }
                 }
@@ -215,7 +191,6 @@ struct LiveActivityWidgetConfiguration: BaseView {
                         .foregroundColor(.primary)
                 )
             }
-            .disabled(!isEditMode)
             .buttonStyle(.plain)
         }
     }
@@ -324,53 +299,24 @@ struct LiveActivityWidgetConfiguration: BaseView {
             selectedItems = LiveActivityItem.defaultItems
             saveOrder()
         }
-        updateVisibilityForSelectedItems()
     }
 
     private func saveOrder() {
         UserDefaults.standard.saveLiveActivityOrder(selectedItems)
+        Foundation.NotificationCenter.default.post(name: .liveActivityOrderDidChange, object: nil)
     }
 
     private func addItem(_ item: LiveActivityItem, at index: Int) {
-        setItemVisibility(item: item, isVisible: true)
         selectedItems[index] = item
         saveOrder()
-        updateVisibilityForSelectedItems()
     }
 
     private func removeItem(_ item: LiveActivityItem) {
         if let index = selectedItems.firstIndex(of: item) {
             selectedItems[index] = nil
-            setItemVisibility(item: item, isVisible: false)
             saveOrder()
         }
     }
-
-    private func setItemVisibility(item: LiveActivityItem, isVisible: Bool) {
-        switch item {
-        case .currentGlucose:
-            state.showCurrentGlucose = isVisible
-        case .iob:
-            state.showIOB = isVisible
-        case .cob:
-            state.showCOB = isVisible
-        case .updatedLabel:
-            state.showUpdatedLabel = isVisible
-        }
-    }
-
-    private func updateVisibilityForSelectedItems() {
-        for item in selectedItems {
-            if let widget = item {
-                setItemVisibility(item: widget, isVisible: true)
-            }
-        }
-        let allItems = LiveActivityItem.allCases
-        let hiddenItems = allItems.filter { !selectedItems.contains($0) }
-        for item in hiddenItems {
-            setItemVisibility(item: item, isVisible: false)
-        }
-    }
 }
 
 // Extension for UserDefaults to save and load the order
@@ -382,7 +328,6 @@ extension UserDefaults {
     func saveLiveActivityOrder(_ items: [LiveActivityItem?]) {
         let itemStrings = items.map { $0?.rawValue ?? "" }
         set(itemStrings, forKey: Keys.liveActivityOrder)
-        print("Saved order to UserDefaults: \(itemStrings)")
     }
 
     func loadLiveActivityOrder() -> [LiveActivityItem?]? {
@@ -415,7 +360,7 @@ enum LiveActivityItem: String, CaseIterable, Identifiable {
         case .cob:
             return "COB"
         case .updatedLabel:
-            return "Updated Label"
+            return "Last Updated"
         }
     }
 }

+ 4 - 10
FreeAPS/Sources/Services/LiveActivity/LiveActitiyAttributes.swift

@@ -2,12 +2,14 @@ import ActivityKit
 import Foundation
 
 struct LiveActivityAttributes: ActivityAttributes {
-    enum ItemOrder: String, Hashable, Codable, Equatable {
+    enum LiveActivityItem: String, Hashable, Codable, Equatable {
         case currentGlucose
         case iob
         case cob
         case updatedLabel
         case empty
+
+        static let defaultItems: [Self] = [.currentGlucose, .iob, .cob, .updatedLabel]
     }
 
     struct ContentState: Codable, Hashable {
@@ -37,16 +39,8 @@ struct LiveActivityAttributes: ActivityAttributes {
         let overrideDate: Date
         let overrideDuration: Decimal
         let overrideTarget: Decimal
-        let itemOrder: [ItemOrder]
-        let showCOB: Bool
-        let showIOB: Bool
-        let showCurrentGlucose: Bool
-        let showUpdatedLabel: Bool
+        let widgetItems: [LiveActivityItem]
     }
 
     let startDate: Date
 }
-
-extension LiveActivityAttributes.ItemOrder {
-    static let defaultOrders: [Self] = [.currentGlucose, .iob, .cob, .updatedLabel]
-}

+ 7 - 10
FreeAPS/Sources/Services/LiveActivity/LiveActivityAttributes+Helper.swift

@@ -5,13 +5,13 @@ extension UserDefaults {
         static let liveActivityOrder = "liveActivityOrder"
     }
 
-    func loadLiveActivityOrderFromUserDefaults() -> [LiveActivityAttributes.ItemOrder]? {
+    func loadLiveActivityOrderFromUserDefaults() -> [LiveActivityAttributes.LiveActivityItem]? {
         if let itemStrings = stringArray(forKey: Keys.liveActivityOrder) {
             return itemStrings.map { string in
                 if string == "" {
                     return .empty
                 } else {
-                    return LiveActivityAttributes.ItemOrder(rawValue: string) ?? .empty
+                    return LiveActivityAttributes.LiveActivityItem(rawValue: string) ?? .empty
                 }
             }
         }
@@ -62,7 +62,8 @@ extension LiveActivityAttributes.ContentState {
         chart: [GlucoseData],
         settings: FreeAPSSettings,
         determination: DeterminationData?,
-        override: OverrideData?
+        override: OverrideData?,
+        widgetItems: [LiveActivityAttributes.LiveActivityItem]?
     ) {
         let glucose = bg.glucose
         let formattedBG = Self.formatGlucose(Int(glucose), units: units, forceSign: false)
@@ -94,8 +95,8 @@ extension LiveActivityAttributes.ContentState {
         let trendString = bg.direction?.symbol as? String
         let change = Self.calculateChange(chart: chart, units: units)
 
-        let itemOrder = UserDefaults.standard
-            .loadLiveActivityOrderFromUserDefaults() ?? LiveActivityAttributes.ItemOrder.defaultOrders
+//        let widgetItems = UserDefaults.standard
+//            .loadLiveActivityOrderFromUserDefaults() ?? LiveActivityAttributes.LiveActivityItem.defaultItems
 
         let detailedState: LiveActivityAttributes.ContentAdditionalState?
 
@@ -117,11 +118,7 @@ extension LiveActivityAttributes.ContentState {
                 overrideDate: override?.date ?? Date(),
                 overrideDuration: override?.duration ?? 0,
                 overrideTarget: override?.target ?? 0,
-                itemOrder: itemOrder,
-                showCOB: settings.showCOB,
-                showIOB: settings.showIOB,
-                showCurrentGlucose: settings.showCurrentGlucose,
-                showUpdatedLabel: settings.showUpdatedLabel
+                widgetItems: widgetItems ?? LiveActivityAttributes.LiveActivityItem.defaultItems
             )
 
         case .simple:

+ 22 - 35
FreeAPS/Sources/Services/LiveActivity/LiveActivityBridge.swift

@@ -44,6 +44,7 @@ import UIKit
     private var latestGlucose: GlucoseData?
     var glucoseFromPersistence: [GlucoseData]?
     var isOverridesActive: OverrideData?
+    var widgetItems: [LiveActivityAttributes.LiveActivityItem]?
 
     let context = CoreDataStack.shared.newTaskContext()
 
@@ -92,22 +93,8 @@ import UIKit
     // TODO: - use a delegate or a custom notification here instead
 
     func settingsDidChange(_: FreeAPSSettings) {
-        guard let latestGlucose = latestGlucose else { return }
-
-        let content = LiveActivityAttributes.ContentState(
-            new: latestGlucose,
-            prev: latestGlucose,
-            units: settings.units,
-            chart: glucoseFromPersistence ?? [],
-            settings: settings,
-            determination: determination,
-            override: isOverridesActive
-        )
-
-        if let content = content {
-            Task {
-                await pushUpdate(content)
-            }
+        Task {
+            await updateContentState()
         }
     }
 
@@ -154,11 +141,13 @@ import UIKit
 
     @objc private func handleLiveActivityOrderChange() {
         Task {
+            self.widgetItems = UserDefaults.standard
+                .loadLiveActivityOrderFromUserDefaults() ?? LiveActivityAttributes.LiveActivityItem.defaultItems
             await self.updateLiveActivityOrder()
         }
     }
 
-    @MainActor private func updateLiveActivityOrder() async {
+    @MainActor  private func updateContentState() async {
         guard let latestGlucose = latestGlucose else { return }
 
         let content = LiveActivityAttributes.ContentState(
@@ -168,11 +157,20 @@ import UIKit
             chart: glucoseFromPersistence ?? [],
             settings: settings,
             determination: determination,
-            override: isOverridesActive
+            override: isOverridesActive,
+            widgetItems: widgetItems
         )
 
         if let content = content {
-            await pushUpdate(content)
+            Task {
+                await pushUpdate(content)
+            }
+        }
+    }
+
+    @MainActor private func updateLiveActivityOrder() async {
+        Task {
+            await updateContentState()
         }
     }
 
@@ -272,21 +270,9 @@ import UIKit
         }
     }
 
-    @MainActor private func pushDeterminationUpdate(_ determination: DeterminationData) async {
-        guard let latestGlucose = latestGlucose else { return }
-
-        let content = LiveActivityAttributes.ContentState(
-            new: latestGlucose,
-            prev: latestGlucose,
-            units: settings.units,
-            chart: glucoseFromPersistence ?? [],
-            settings: settings,
-            determination: determination,
-            override: isOverridesActive
-        )
-
-        if let content = content {
-            await pushUpdate(content)
+    @MainActor private func pushDeterminationUpdate(_: DeterminationData) async {
+        Task {
+            await updateContentState()
         }
     }
 
@@ -336,7 +322,8 @@ extension LiveActivityBridge {
                 chart: glucose,
                 settings: settings,
                 determination: determination,
-                override: isOverridesActive
+                override: isOverridesActive,
+                widgetItems: widgetItems
             )
 
             if let content = content {

+ 26 - 33
LiveActivity/LiveActivity.swift

@@ -235,46 +235,43 @@ struct LiveActivityView: View {
                     }
 
                 HStack {
-                    if detailedViewState.itemOrder.contains(where: { $0 != .empty }) {
-                        ForEach(Array(detailedViewState.itemOrder.enumerated()), id: \.element) { index, widgetItem in
+                    if detailedViewState.widgetItems.contains(where: { $0 != .empty }) {
+                        ForEach(Array(detailedViewState.widgetItems.enumerated()), id: \.element) { index, widgetItem in
                             switch widgetItem {
                             case .currentGlucose:
-                                if detailedViewState.showCurrentGlucose {
-                                    VStack {
-                                        LiveActivityBGLabelView(context: context, additionalState: detailedViewState)
-                                        HStack {
-                                            LiveActivityGlucoseDeltaLabelView(
-                                                context: context,
-                                                glucoseColor: .primary,
-                                                isDetailed: true
-                                            )
-                                            if !context.isStale, let direction = context.state.direction {
-                                                Text(direction).font(.headline)
-                                            }
+                                VStack {
+                                    LiveActivityBGLabelView(context: context, additionalState: detailedViewState)
+                                    HStack {
+                                        LiveActivityGlucoseDeltaLabelView(
+                                            context: context,
+                                            glucoseColor: .primary,
+                                            isDetailed: true
+                                        )
+                                        if !context.isStale, let direction = context.state.direction {
+                                            Text(direction).font(.headline)
                                         }
                                     }
                                 }
                             case .iob:
-                                if detailedViewState.showIOB {
-                                    LiveActivityIOBLabelView(context: context, additionalState: detailedViewState)
-                                }
+                                LiveActivityIOBLabelView(context: context, additionalState: detailedViewState)
                             case .cob:
-                                if detailedViewState.showCOB {
-                                    LiveActivityCOBLabelView(context: context, additionalState: detailedViewState)
-                                }
+                                LiveActivityCOBLabelView(context: context, additionalState: detailedViewState)
                             case .updatedLabel:
-                                if detailedViewState.showUpdatedLabel {
-                                    LiveActivityUpdatedLabelView(context: context, isDetailedLayout: true)
-                                }
+                                LiveActivityUpdatedLabelView(context: context, isDetailedLayout: true)
                             case .empty:
                                 Text("").frame(width: 50, height: 50)
                             }
 
-                            // Find the next non-empty widget for the divider check
-                            if index < detailedViewState.itemOrder.count - 1 {
-                                let nextNonEmptyIndex = detailedViewState.itemOrder[(index + 1)...].firstIndex { $0 != .empty }
-                                if let nextIndex = nextNonEmptyIndex, nextIndex > index {
-                                    Divider().foregroundStyle(.primary).fontWeight(.bold).frame(width: 10)
+                            /// Check if the next item is also non-empty to determine if a divider should be shown
+                            if index < detailedViewState.widgetItems.count - 1 {
+                                let currentItem = detailedViewState.widgetItems[index]
+                                let nextItem = detailedViewState.widgetItems[index + 1]
+
+                                if currentItem != .empty, nextItem != .empty {
+                                    Divider()
+                                        .foregroundStyle(.primary)
+                                        .fontWeight(.bold)
+                                        .frame(width: 10)
                                 }
                             }
                         }
@@ -757,11 +754,7 @@ private extension LiveActivityAttributes.ContentState {
         overrideDate: Date().addingTimeInterval(-3600),
         overrideDuration: 120,
         overrideTarget: 150,
-        itemOrder: LiveActivityAttributes.ItemOrder.defaultOrders,
-        showCOB: true,
-        showIOB: true,
-        showCurrentGlucose: true,
-        showUpdatedLabel: true
+        widgetItems: LiveActivityAttributes.LiveActivityItem.defaultItems
     )
 
     // 0 is the widest digit. Use this to get an upper bound on text width.