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:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user