Tied cheapest stations become notification action buttons

When several stations share the cheapest price within the radius (within
0.01p), the alert registers a dynamic UNNotificationCategory with up to
4 action buttons (brand + distance, nearest first) and taps open
directions to the chosen station. Shared FuelStore.tiedStations helper
used by both the live geofence path and the Settings real-data test;
35 tests pass.
This commit is contained in:
FuelBoard Contributor
2026-08-12 10:48:08 +01:00
parent cbe01f4219
commit 1f50d7dcf4
3 changed files with 173 additions and 13 deletions
+16
View File
@@ -257,6 +257,22 @@ struct FuelStore {
// defaults-first for stations (keychain may hold a legacy small set from
// older builds; the full country dump always wins).
/// Stations from `stations` tied with `price` for `fuel` (within 0.01p),
/// sorted nearest-first from `lat`/`lng`. Used to offer multiple
/// cheapest-station choices in an alert notification.
static func tiedStations(
in stations: [FuelStation],
fuel: FuelType,
price: Double,
fromLat lat: Double, lng: Double
) -> [FuelStation] {
stations
.filter { abs(($0.prices[fuel] ?? .infinity) - price) < 0.01 }
.sorted { lhs, rhs in
lhs.distanceKM(to: lat, lng2: lng) < rhs.distanceKM(to: lat, lng2: lng)
}
}
static func loadStations() -> [FuelStation] {
if let defaults = UserDefaults(suiteName: appGroupSuite),
let data = defaults.data(forKey: stationsKey),