Browse Source

fix: Correct forecast line colors and visibility in Live Activity widget

- Replace named asset colors (UAM, ZT) with inline RGB values since those assets don't exist in the LiveActivity bundle
- Hide iob forecast line when cob or uam are active, matching phone app behavior
- Add ForecastDisplayTypeKey enum for robust string comparison
Magnus Reintz 1 week ago
parent
commit
6d8be44f2e

+ 8 - 3
LiveActivity/Views/LiveActivityChartView.swift

@@ -9,6 +9,11 @@ import Foundation
 import SwiftUI
 import WidgetKit
 
+private enum ForecastDisplayTypeKey {
+    static let lines = "lines"
+    static let cone = "cone"
+}
+
 struct LiveActivityChartView: View {
     @Environment(\.colorScheme) var colorScheme
     @Environment(\.isWatchOS) var isWatchOS
@@ -98,7 +103,7 @@ struct LiveActivityChartView: View {
             }
 
             if hasForecast, let anchorDate = state.date {
-                if additionalState.forecastDisplayType == "lines" {
+                if additionalState.forecastDisplayType == ForecastDisplayTypeKey.lines {
                     drawForecastLines(anchorDate: anchorDate, isMgdL: isMgdL)
                 } else {
                     drawForecastCone(anchorDate: anchorDate, isMgdL: isMgdL, maxValue: maxValue)
@@ -213,8 +218,8 @@ struct LiveActivityChartView: View {
         let colorMap: [String: Color] = [
             "iob": Color(red: 0.118, green: 0.588, blue: 0.988),
             "cob": Color.orange,
-            "uam": Color("UAM"),
-            "zt": Color("ZT")
+            "uam": Color(red: 0.820, green: 0.169, blue: 0.969),
+            "zt": Color(red: 0.443, green: 0.380, blue: 0.937)
         ]
 
         let points: [(series: String, date: Date, value: Decimal)] = additionalState.forecastLines.flatMap { line in

+ 5 - 0
Trio/Sources/Services/LiveActivity/Data/DataManager.swift

@@ -65,9 +65,14 @@ extension LiveActivityManager {
             var forecastLines = [(type: String, values: [Int])]()
 
             if let forecasts = determination.forecasts {
+                let hasCarbs = forecasts.contains(where: {
+                    ($0.type == "cob" || $0.type == "uam") && !$0.forecastValuesArray.isEmpty
+                })
                 for forecast in forecasts.sorted(by: { ($0.type ?? "") < ($1.type ?? "") }) {
                     let values = forecast.forecastValuesArray.prefix(24).map { Int($0.value) }
                     guard !values.isEmpty else { continue }
+                    // iob is hidden when cob or uam are active (matches phone app behavior)
+                    if forecast.type == "iob", hasCarbs { continue }
                     allForecastValues.append(Array(values))
                     if let type = forecast.type {
                         forecastLines.append((type: type, values: Array(values)))