Alerts show actual station name, distance and price
Both the real alert path and the real-data Settings test now render the notification body as 'Station · 1.2 mi away · 145.9p' — actual haversine distance to the station in the user's unit, not just the radius.
This commit is contained in:
@@ -166,15 +166,19 @@ final class ProximityMonitor: NSObject, ObservableObject, @preconcurrency CLLoca
|
|||||||
private func fireAlert(for station: FuelStation, price: Double) {
|
private func fireAlert(for station: FuelStation, price: Double) {
|
||||||
let brand = station.brand.isEmpty ? station.name : station.brand
|
let brand = station.brand.isEmpty ? station.name : station.brand
|
||||||
let unit = FuelStore.loadDistanceUnit()
|
let unit = FuelStore.loadDistanceUnit()
|
||||||
|
let distanceText: String = {
|
||||||
|
guard let location = FuelStore.loadLocation() else { return unit.format(0) }
|
||||||
|
return unit.format(station.distanceKM(to: location.lat, lng2: location.lng))
|
||||||
|
}()
|
||||||
let content = UNMutableNotificationContent()
|
let content = UNMutableNotificationContent()
|
||||||
content.title = "Cheapest \(fuel.displayName) nearby: \(brand)"
|
content.title = "Cheapest \(fuel.displayName) nearby: \(brand)"
|
||||||
content.body = "\(station.name) is the cheapest within \(unit.format(radiusKM)) at \(String(format: "%.1fp", price)). Tap to open."
|
content.body = "\(station.name) · \(distanceText) away · \(String(format: "%.1fp", price)). Tap to open."
|
||||||
content.sound = .default
|
content.sound = .default
|
||||||
|
|
||||||
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
|
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
|
||||||
UNUserNotificationCenter.current().add(request)
|
UNUserNotificationCenter.current().add(request)
|
||||||
|
|
||||||
lastAlert = "\(brand) · \(String(format: "%.1fp", price)) · \(unit.format(radiusKM)) radius"
|
lastAlert = "\(brand) · \(String(format: "%.1fp", price)) · \(distanceText) away"
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fires a test alert built from REAL data: the cheapest station selling
|
/// Fires a test alert built from REAL data: the cheapest station selling
|
||||||
@@ -197,13 +201,17 @@ final class ProximityMonitor: NSObject, ObservableObject, @preconcurrency CLLoca
|
|||||||
|
|
||||||
if let candidate, let price = candidate.prices[fuel] {
|
if let candidate, let price = candidate.prices[fuel] {
|
||||||
let brand = candidate.brand.isEmpty ? candidate.name : candidate.brand
|
let brand = candidate.brand.isEmpty ? candidate.name : candidate.brand
|
||||||
|
let distanceText: String = {
|
||||||
|
guard let location else { return unit.format(0) }
|
||||||
|
return unit.format(candidate.distanceKM(to: location.lat, lng2: location.lng))
|
||||||
|
}()
|
||||||
let content = UNMutableNotificationContent()
|
let content = UNMutableNotificationContent()
|
||||||
content.title = "Cheapest \(fuel.displayName) nearby: \(brand)"
|
content.title = "Cheapest \(fuel.displayName) nearby: \(brand)"
|
||||||
content.body = "\(candidate.name) is the cheapest within \(unit.format(radiusKM)) at \(String(format: "%.1fp", price)). Tap to open."
|
content.body = "\(candidate.name) · \(distanceText) away · \(String(format: "%.1fp", price)). Tap to open."
|
||||||
content.sound = .default
|
content.sound = .default
|
||||||
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
|
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
|
||||||
UNUserNotificationCenter.current().add(request)
|
UNUserNotificationCenter.current().add(request)
|
||||||
lastTestResult = "\(fuel.displayName) · \(brand) · \(String(format: "%.1fp", price)) · radius \(unit.format(radiusKM))"
|
lastTestResult = "\(fuel.displayName) · \(brand) · \(String(format: "%.1fp", price)) · \(distanceText) away · radius \(unit.format(radiusKM))"
|
||||||
} else {
|
} else {
|
||||||
// No real candidate (no stations loaded yet, or none sell the
|
// No real candidate (no stations loaded yet, or none sell the
|
||||||
// monitored fuel) — still fire so delivery is testable, but say
|
// monitored fuel) — still fire so delivery is testable, but say
|
||||||
|
|||||||
Reference in New Issue
Block a user