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,
|
||||
|
||||
@@ -48,6 +48,7 @@ enum LiveActivityManager {
|
||||
}
|
||||
|
||||
let state = FuelBoardLiveActivityAttributes.ContentState(
|
||||
fuel: fuel,
|
||||
stationID: best.id,
|
||||
stationName: best.name,
|
||||
brand: best.brand,
|
||||
@@ -57,7 +58,7 @@ enum LiveActivityManager {
|
||||
lng: best.lng,
|
||||
updatedAt: Date()
|
||||
)
|
||||
let attributes = FuelBoardLiveActivityAttributes(fuel: fuel)
|
||||
let attributes = FuelBoardLiveActivityAttributes()
|
||||
|
||||
if let current {
|
||||
// Near the 8 h cap? End and re-request so the pill keeps living.
|
||||
|
||||
@@ -13,9 +13,13 @@ import WidgetKit
|
||||
struct SettingsView: View {
|
||||
@Binding var distanceUnit: DistanceUnit
|
||||
/// Whether the "cheapest nearby" Live Activity is shown on the Lock Screen
|
||||
/// / Dynamic Island. Mirrors the app list's TOP badge (selected fuel +
|
||||
/// distance radius) and re-updates as the user drives.
|
||||
/// / Dynamic Island. Tracks its OWN fuel + radius (below) — independent of
|
||||
/// the Stations tab.
|
||||
@Binding var liveActivityEnabled: Bool
|
||||
/// Fuel the Live Activity tracks (independent of the Stations tab).
|
||||
@Binding var liveActivityFuel: FuelType
|
||||
/// Search radius (miles, 5/10/15) the Live Activity uses.
|
||||
@Binding var liveActivityRadiusMiles: Int
|
||||
/// The fuel + radius currently configured for alerts (mirrors the Alerts
|
||||
/// tab) so the test notification matches what real alerts will say.
|
||||
var alertsFuel: FuelType = .e10
|
||||
@@ -72,10 +76,26 @@ struct SettingsView: View {
|
||||
|
||||
Section {
|
||||
Toggle("Live Activity", isOn: $liveActivityEnabled)
|
||||
Picker("Fuel", selection: $liveActivityFuel) {
|
||||
ForEach(FuelType.allCases) { fuel in
|
||||
Text(fuel.displayName).tag(fuel)
|
||||
}
|
||||
}
|
||||
.onChange(of: liveActivityFuel) { _, newValue in
|
||||
FuelStore.saveLiveActivityFuel(newValue)
|
||||
}
|
||||
Picker("Distance", selection: $liveActivityRadiusMiles) {
|
||||
ForEach(FuelStore.stationRadiusOptions, id: \.self) { miles in
|
||||
Text("\(miles) \(distanceUnit.label)").tag(miles)
|
||||
}
|
||||
}
|
||||
.onChange(of: liveActivityRadiusMiles) { _, newValue in
|
||||
FuelStore.saveLiveActivityRadiusMiles(newValue)
|
||||
}
|
||||
} header: {
|
||||
Text("Live Activity")
|
||||
} footer: {
|
||||
Text("Shows the cheapest station for your selected fuel within your chosen distance on the Lock Screen and Dynamic Island. Updates as you drive; tap to open directions. Live Activities can be disabled in System Settings → Live Activities.")
|
||||
Text("Shows the cheapest station for the fuel and distance you pick here on the Lock Screen and Dynamic Island — independent of the Stations tab. Updates as you drive; tap to open directions. Live Activities can be disabled in System Settings → Live Activities.")
|
||||
}
|
||||
.onChange(of: liveActivityEnabled) { _, newValue in
|
||||
FuelStore.saveLiveActivityEnabled(newValue)
|
||||
|
||||
Reference in New Issue
Block a user