Live Activity: own fuel + distance config, independent of Stations tab
- Settings → Live Activity now has Fuel and Distance pickers (5/10/15, unit-aware) stored under fuelboard.liveActivityFuel / liveActivityRadiusMiles - LiveActivityManager uses these instead of the Stations-tab selectedFuel / stationLimit; Stations changes no longer re-target the pill - Fuel moved from Activity attributes into ContentState so changing fuel in Settings updates the RUNNING activity in place (no end+restart needed) - Stations tab stays a pure data-interrogation + favourites surface
This commit is contained in:
@@ -15,6 +15,8 @@ struct ContentView: View {
|
||||
@State private var alertsRadius: Double = FuelStore.loadAlertsRadius()
|
||||
@State private var alertsFuel: FuelType = FuelStore.loadAlertsFuel()
|
||||
@State private var liveActivityEnabled: Bool = FuelStore.loadLiveActivityEnabled()
|
||||
@State private var liveActivityFuel: FuelType = FuelStore.loadLiveActivityFuel()
|
||||
@State private var liveActivityRadiusMiles: Int = FuelStore.loadLiveActivityRadiusMiles()
|
||||
@State private var location: Coordinate? = {
|
||||
if let loc = FuelStore.loadLocation() { return Coordinate(lat: loc.lat, lng: loc.lng) }
|
||||
return nil
|
||||
@@ -251,7 +253,6 @@ struct ContentView: View {
|
||||
.onChange(of: selectedFuel) { _, _ in
|
||||
// No re-fetch needed — one response carries E5/E10/DIESEL prices.
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
updateLiveActivity()
|
||||
}
|
||||
.onChange(of: stationLimit) { _, newValue in
|
||||
// Distance filter is LOCAL math now — the cache holds the full-UK
|
||||
@@ -260,7 +261,6 @@ struct ContentView: View {
|
||||
// next render.
|
||||
FuelStore.saveStationLimit(newValue)
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
updateLiveActivity()
|
||||
}
|
||||
.onChange(of: alertsEnabled) { _, newValue in
|
||||
FuelStore.saveAlertsEnabled(newValue)
|
||||
@@ -289,6 +289,16 @@ struct ContentView: View {
|
||||
FuelStore.saveLiveActivityEnabled(newValue)
|
||||
updateLiveActivity()
|
||||
}
|
||||
.onChange(of: liveActivityFuel) { _, newValue in
|
||||
// The pill tracks its OWN fuel — independent of the Stations tab.
|
||||
FuelStore.saveLiveActivityFuel(newValue)
|
||||
updateLiveActivity()
|
||||
}
|
||||
.onChange(of: liveActivityRadiusMiles) { _, newValue in
|
||||
// Same for its own radius (miles, converted at use).
|
||||
FuelStore.saveLiveActivityRadiusMiles(newValue)
|
||||
updateLiveActivity()
|
||||
}
|
||||
.onChange(of: distanceUnit) { _, _ in
|
||||
// Distance unit changes the radius — mirror the new radius in the
|
||||
// Live Activity immediately.
|
||||
@@ -298,13 +308,13 @@ struct ContentView: View {
|
||||
|
||||
/// Pushes the current best-in-radius station into the Live Activity.
|
||||
/// No-op (or ends the activity) when the toggle is off or there's no
|
||||
/// location/data yet. Mirrors the app list's TOP badge: selected fuel +
|
||||
/// chosen distance radius, cheapest then nearest on ties.
|
||||
/// location/data yet. Uses the Live Activity's OWN fuel + radius (set in
|
||||
/// Settings) — independent of the Stations-tab fuel/distance.
|
||||
private func updateLiveActivity() {
|
||||
LiveActivityManager.update(
|
||||
stations: stations,
|
||||
fuel: selectedFuel,
|
||||
radiusKM: distanceUnit.toKM(Double(stationLimit)),
|
||||
fuel: liveActivityFuel,
|
||||
radiusKM: distanceUnit.toKM(Double(liveActivityRadiusMiles)),
|
||||
location: location,
|
||||
enabled: liveActivityEnabled
|
||||
)
|
||||
@@ -316,6 +326,8 @@ struct ContentView: View {
|
||||
SettingsView(
|
||||
distanceUnit: $distanceUnit,
|
||||
liveActivityEnabled: $liveActivityEnabled,
|
||||
liveActivityFuel: $liveActivityFuel,
|
||||
liveActivityRadiusMiles: $liveActivityRadiusMiles,
|
||||
alertsFuel: alertsFuel,
|
||||
alertsRadiusKM: alertsRadius,
|
||||
testAlertResult: monitor.lastTestResult,
|
||||
|
||||
Reference in New Issue
Block a user