Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab93f6286a | ||
|
|
6edab35400 | ||
|
|
244f9be640 | ||
|
|
c46a7748e6 | ||
|
|
6cbb083208 | ||
|
|
c331f3d663 | ||
|
|
7aa2485994 | ||
|
|
c6e252d194 | ||
|
|
7aaaffa1c5 | ||
|
|
7111ce38af | ||
|
|
ff6cbbe07d | ||
|
|
f261b0b10a | ||
|
|
1b6184c035 | ||
|
|
6a9b5df4f1 | ||
|
|
1cd4d86a69 |
+18
@@ -106,6 +106,24 @@ Status: TODO / IN PROGRESS / DONE / BLOCKED.
|
||||
scene (CPListTemplate) for navigation deep-links.
|
||||
- [ ] **Alert region tuning** — make alert trigger radius + dedup window
|
||||
user-configurable (currently fixed 300 m trigger / 1 per station per hour).
|
||||
- [ ] **Restore Best Value proximity alerts after fixing evaluation parity** —
|
||||
the option is intentionally removed from the Alerts tab and legacy selections
|
||||
fall back to `Cheapest station` until this is implemented. Root cause: the live
|
||||
geofence path calculates journeys from the entered station, making that station
|
||||
its own zero-saving baseline and therefore unable to clear any positive minimum
|
||||
saving, while Test alert calculates from the user's location and can pass.
|
||||
Future implementation must obtain a fresh user fix on region entry; fetch,
|
||||
radius-filter, choose the closest eligible baseline and calculate every journey
|
||||
from that user location; then notify only when the entered station is the best
|
||||
qualifying candidate. Real and Test alerts must call one shared pure evaluator.
|
||||
Apply one disclosed qualification rule everywhere (real alert, Test alert and
|
||||
BEST VALUE badge): remove the live path's hidden extra £0.50 estimate margin,
|
||||
compare the same penny-rounded amount shown to the user while retaining raw
|
||||
precision for ranking, and pass the current threshold explicitly into station
|
||||
rows instead of reading persistence per row. Regression coverage: entered
|
||||
station can qualify, a better nearby candidate blocks it, real/Test parity,
|
||||
exact and display-rounding boundaries, estimated/confirmed parity, immediate
|
||||
threshold changes, and below-threshold rejection.
|
||||
- [ ] **Price-drop alerts: threshold control + Check now** — keep the current
|
||||
cache-first / 12 h refresh policy, but add a per-alert sensitivity control
|
||||
for favourite price-drop alerts instead of a fetch-frequency slider. Scope:
|
||||
|
||||
@@ -533,7 +533,7 @@
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Config/WatchApp.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 27;
|
||||
CURRENT_PROJECT_VERSION = 29;
|
||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
@@ -599,7 +599,7 @@
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Config/WatchApp.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 27;
|
||||
CURRENT_PROJECT_VERSION = 29;
|
||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
@@ -663,7 +663,7 @@
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 27;
|
||||
CURRENT_PROJECT_VERSION = 29;
|
||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
@@ -728,7 +728,7 @@
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 27;
|
||||
CURRENT_PROJECT_VERSION = 29;
|
||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
@@ -826,7 +826,7 @@
|
||||
CODE_SIGN_ENTITLEMENTS = Config/App.entitlements;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 27;
|
||||
CURRENT_PROJECT_VERSION = 29;
|
||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||
GENERATE_INFOPLIST_FILE = NO;
|
||||
INFOPLIST_FILE = "Config/App-Info.plist";
|
||||
@@ -851,7 +851,7 @@
|
||||
CODE_SIGN_ENTITLEMENTS = Config/App.entitlements;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 27;
|
||||
CURRENT_PROJECT_VERSION = 29;
|
||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||
GENERATE_INFOPLIST_FILE = NO;
|
||||
INFOPLIST_FILE = "Config/App-Info.plist";
|
||||
@@ -875,7 +875,7 @@
|
||||
APPLICATION_EXTENSION_API_ONLY = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Config/Widget.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 27;
|
||||
CURRENT_PROJECT_VERSION = 29;
|
||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||
GENERATE_INFOPLIST_FILE = NO;
|
||||
INFOPLIST_FILE = "Config/Widget-Info.plist";
|
||||
@@ -900,7 +900,7 @@
|
||||
APPLICATION_EXTENSION_API_ONLY = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Config/Widget.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 27;
|
||||
CURRENT_PROJECT_VERSION = 29;
|
||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||
GENERATE_INFOPLIST_FILE = NO;
|
||||
INFOPLIST_FILE = "Config/Widget-Info.plist";
|
||||
|
||||
+130
-82
@@ -6,18 +6,12 @@ import SwiftUI
|
||||
/// versa). The Live Activity section also lives here — it mirrors this page's
|
||||
/// shape (toggle + fuel + distance) so the two "notify me while driving"
|
||||
/// surfaces sit together. Geofence plumbing (count, 18-limit) lives in
|
||||
/// Settings → Debug; the user-facing page keeps a plain-language explainer
|
||||
/// plus a 0-stations hint.
|
||||
/// Settings → Debug; the user-facing page keeps short descriptions of the
|
||||
/// cheapest-station rule and radius, plus a 0-stations hint.
|
||||
struct AlertsView: View {
|
||||
@Binding var enabled: Bool
|
||||
@Binding var radius: Double // stored in km (monitor + storage)
|
||||
@Binding var fuel: FuelType // the fuel alerts monitor for
|
||||
@Binding var alertMode: AlertMode
|
||||
/// Read-only here: the threshold is edited in Settings → Fuel Savings, where
|
||||
/// the fill size and MPG that decide the saving live. Read back so the
|
||||
/// alert's own rule is visible without leaving the tab.
|
||||
let bestValueThresholdGBP: Double
|
||||
let bestValueConfigured: Bool
|
||||
@Binding var favouriteDropEnabled: Bool
|
||||
@Binding var favouriteDropFuel: FuelType
|
||||
/// Whether alerts mirror the Stations-tab search distance (capped at 8 mi).
|
||||
@@ -55,31 +49,29 @@ struct AlertsView: View {
|
||||
return String(format: String(localized: "%lld %@", comment: "Distance label"), shown, distanceUnit.label(for: Double(shown)))
|
||||
}
|
||||
|
||||
/// Situational guidance for the currently-selected alert radius, shown
|
||||
/// under the picker so users know what each choice is best for. Labels
|
||||
/// mirror the picker row text (unit-aware) and explain the trade-off:
|
||||
/// smaller radii ping more often but later; larger radii ping rarely in
|
||||
/// town but earlier from afar.
|
||||
private var alertRadiusGuidance: String {
|
||||
/// The distance the geofence actually caps "Follow search" at, in miles
|
||||
/// (FuelStore stores the cap in km so the monitor and storage are unit-free).
|
||||
private var followSearchCapMiles: Int {
|
||||
Int((FuelStore.alertFollowCapKM / FuelSavingsCalculator.kilometresPerMile).rounded())
|
||||
}
|
||||
|
||||
/// The radius the selected option really monitors, stated in the user's
|
||||
/// unit — e.g. "Get alerts when you're within 2 miles of a matching
|
||||
/// station." "Follow search" mirrors the Stations-tab distance, which the
|
||||
/// geofence caps; said plainly, and only when the search distance really
|
||||
/// exceeds the cap, so the sentence never contradicts the picker row.
|
||||
private var alertRadiusDescription: String {
|
||||
switch alertChoice.wrappedValue {
|
||||
case .followSearch:
|
||||
return String(localized: "Set-and-forget: alerts behave exactly like the Stations-tab search distance (capped at 8 miles for reliable geofencing).", comment: "Alert radius guidance for following search distance")
|
||||
case .fixed(let value):
|
||||
let optionLabel = String(format: String(localized: "%lld %@", comment: "Distance label"), value, distanceUnit.label(for: Double(value)))
|
||||
let body: String
|
||||
switch value {
|
||||
case 1:
|
||||
body = String(localized: "Town driving. Fires most often — you're rarely inside the circle for long, so pings are meaningful. Best for stop-start local trips.", comment: "Alert radius guidance")
|
||||
case 2:
|
||||
body = String(localized: "City or suburb commute. Slightly earlier heads-up than the smallest option; still fires regularly around town.", comment: "Alert radius guidance")
|
||||
case 3:
|
||||
body = String(localized: "Mixed driving. Middle ground: heads-up a few minutes out, still works in most towns.", comment: "Alert radius guidance")
|
||||
case 5:
|
||||
body = String(localized: "A-roads and motorway exits. Wide early warning for longer trips — but in town it rarely fires, because you're usually already inside the circle.", comment: "Alert radius guidance")
|
||||
default:
|
||||
body = String(localized: "Long-distance journeys. Maximum reach: a ping when a cheap station is coming up from far out. In town this essentially never fires.", comment: "Alert radius guidance")
|
||||
let capped = stationLimit > followSearchCapMiles
|
||||
let label = distanceLabel(forMiles: capped ? followSearchCapMiles : stationLimit)
|
||||
if capped {
|
||||
return String(format: String(localized: "Get alerts when you're within %@ of a matching station (your search distance is capped for reliable alerts).", comment: "Proximity alert radius description, follow search capped"), label)
|
||||
}
|
||||
return String(format: String(localized: "%@ — %@", comment: "Alert radius guidance with option label"), optionLabel, body)
|
||||
return String(format: String(localized: "Get alerts when you're within %@ of a matching station.", comment: "Proximity alert radius description"), label)
|
||||
case .fixed(let value):
|
||||
let label = String(format: String(localized: "%lld %@", comment: "Distance label"), value, distanceUnit.label(for: Double(value)))
|
||||
return String(format: String(localized: "Get alerts when you're within %@ of a matching station.", comment: "Proximity alert radius description"), label)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,71 +128,110 @@ struct AlertsView: View {
|
||||
)
|
||||
}
|
||||
|
||||
/// The radius currently selected, in the user's unit — shown by the disabled
|
||||
/// row in place of the picker.
|
||||
private var alertRadiusValueLabel: String {
|
||||
switch alertChoice.wrappedValue {
|
||||
case .followSearch:
|
||||
return String(format: String(localized: "Follow search (%@)", comment: "Follow current station search distance option"), searchInUnitLabel)
|
||||
case .fixed(let value):
|
||||
return String(format: String(localized: "%lld %@", comment: "Distance label"), value, distanceUnit.label(for: Double(value)))
|
||||
}
|
||||
}
|
||||
|
||||
private var laDistanceValueLabel: String {
|
||||
switch laChoice.wrappedValue {
|
||||
case .followSearch:
|
||||
return String(format: String(localized: "Follow search (%@)", comment: "Follow current station search distance option"), searchInUnitLabel)
|
||||
case .fixed(let miles):
|
||||
return distanceLabel(forMiles: miles)
|
||||
}
|
||||
}
|
||||
|
||||
/// An option row that belongs to a toggle. When the toggle is off the control
|
||||
/// is replaced by a static value row. The enclosing dependent group applies
|
||||
/// FuelBoard's shared disabled interaction and appearance once.
|
||||
@ViewBuilder
|
||||
private func optionRow<Content: View>(_ title: String,
|
||||
value: String,
|
||||
isEnabled: Bool,
|
||||
@ViewBuilder picker: () -> Content) -> some View {
|
||||
if isEnabled {
|
||||
picker()
|
||||
} else {
|
||||
HStack {
|
||||
Text(title)
|
||||
Spacer()
|
||||
Text(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
List {
|
||||
Section {
|
||||
Toggle(String(localized: "Cheapest favourite", comment: "Favourite price-drop alert toggle"), isOn: $favouriteDropEnabled)
|
||||
Picker(String(localized: "Fuel", comment: "Fuel picker title"), selection: $favouriteDropFuel) {
|
||||
ForEach(FuelType.allCases) { fuel in
|
||||
Text(fuel.displayName).tag(fuel)
|
||||
Group {
|
||||
optionRow(String(localized: "Fuel", comment: "Fuel picker title"),
|
||||
value: favouriteDropFuel.displayName,
|
||||
isEnabled: favouriteDropEnabled) {
|
||||
Picker(String(localized: "Fuel", comment: "Fuel picker title"), selection: $favouriteDropFuel) {
|
||||
ForEach(FuelType.allCases) { fuel in
|
||||
Text(fuel.displayName).tag(fuel)
|
||||
}
|
||||
}
|
||||
}
|
||||
Button(String(localized: "Check now", comment: "Manual favourite price-drop check button"), action: onCheckFavouriteDropNow)
|
||||
Text(String(localized: "Get notified when a different favourite becomes the cheapest, or your cheapest favourite drops in price.", comment: "Favourite price alerts section description"))
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Button(String(localized: "Check now", comment: "Manual favourite price-drop check button"), action: onCheckFavouriteDropNow)
|
||||
.disabled(!favouriteDropEnabled)
|
||||
.fuelBoardDisabledState(isEnabled: favouriteDropEnabled)
|
||||
} header: {
|
||||
Text(String(localized: "Price-drop alerts", comment: "Favourite price-drop alerts section title"))
|
||||
} footer: {
|
||||
Text(String(localized: "Watches your cheapest saved favourite for the fuel you pick here. FuelBoard alerts when a different favourite becomes the cheapest, or when your current cheapest favourite drops by at least 1.0p. This is separate from the nearby-geofence alert, so you can monitor favourites without extra location noise.", comment: "Favourite price-drop alerts section footer"))
|
||||
Text(String(localized: "Favourite price alerts", comment: "Favourite price alerts section title"))
|
||||
}
|
||||
|
||||
Section {
|
||||
Toggle(String(localized: "Cheapest station", comment: "Proximity alert toggle"), isOn: $enabled)
|
||||
Picker(String(localized: "Alert type", comment: "Proximity alert type picker title"), selection: $alertMode) {
|
||||
ForEach(AlertMode.allCases.filter { mode in mode != .bestValue || bestValueConfigured }) { mode in
|
||||
Text(mode.displayName).tag(mode)
|
||||
}
|
||||
}
|
||||
if !bestValueConfigured {
|
||||
Text(String(localized: "Set up Best Value first so Best Value alerts can account for your fill size, MPG and travel cost.", comment: "Best Value alert unavailable hint"))
|
||||
.font(.caption)
|
||||
Group {
|
||||
Text(String(localized: "Get notified when you're near one of the cheapest stations for your chosen fuel.", comment: "Cheapest station proximity alert description"))
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Picker(String(localized: "Fuel", comment: "Fuel picker title"), selection: $fuel) {
|
||||
ForEach(FuelType.allCases) { fuel in
|
||||
Text(fuel.displayName).tag(fuel)
|
||||
optionRow(String(localized: "Fuel", comment: "Fuel picker title"),
|
||||
value: fuel.displayName,
|
||||
isEnabled: enabled) {
|
||||
Picker(String(localized: "Fuel", comment: "Fuel picker title"), selection: $fuel) {
|
||||
ForEach(FuelType.allCases) { fuel in
|
||||
Text(fuel.displayName).tag(fuel)
|
||||
}
|
||||
}
|
||||
}
|
||||
optionRow(String(localized: "Radius", comment: "Alert radius picker title"),
|
||||
value: alertRadiusValueLabel,
|
||||
isEnabled: enabled) {
|
||||
Picker(String(localized: "Radius", comment: "Alert radius picker title"), selection: alertChoice) {
|
||||
Text(String(format: String(localized: "Follow search (%@)", comment: "Follow current station search distance option"), searchInUnitLabel)).tag(AlertRadiusChoice.followSearch)
|
||||
ForEach(FuelStore.alertRadiusOptions, id: \.self) { value in
|
||||
Text(String(format: String(localized: "%lld %@", comment: "Distance label"), value, distanceUnit.label(for: Double(value)))).tag(AlertRadiusChoice.fixed(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
Picker(String(localized: "Radius", comment: "Alert radius picker title"), selection: alertChoice) {
|
||||
Text(String(format: String(localized: "Follow search (%@)", comment: "Follow current station search distance option"), searchInUnitLabel)).tag(AlertRadiusChoice.followSearch)
|
||||
ForEach(FuelStore.alertRadiusOptions, id: \.self) { value in
|
||||
Text(String(format: String(localized: "%lld %@", comment: "Distance label"), value, distanceUnit.label(for: Double(value)))).tag(AlertRadiusChoice.fixed(value))
|
||||
}
|
||||
}
|
||||
Text(alertRadiusGuidance)
|
||||
.font(.caption)
|
||||
Text(alertRadiusDescription)
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
if alertMode == .bestValue {
|
||||
// The threshold is edited in Settings → Fuel Savings: it
|
||||
// labels station rows BEST VALUE as well as gating this
|
||||
// alert, so it lives with the fill size and MPG that
|
||||
// produce the saving. Read back here, not offered twice.
|
||||
Text(String(format: String(localized: "Minimum saving %@ — change in Settings, Fuel Savings.", comment: "Best Value alert threshold read-back"), FuelSavingsFormat.money(bestValueThresholdGBP)))
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
if enabled && monitoredCount == 0 {
|
||||
Text(String(localized: "No stations monitored yet — open the Stations tab to load prices first.", comment: "No monitored stations hint"))
|
||||
.font(.caption)
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Text(String(localized: "Background alerts depend on when your iPhone allows them; each station alerts at most once an hour.", comment: "Proximity alerts background limitation note"))
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.fuelBoardDisabledState(isEnabled: enabled)
|
||||
} header: {
|
||||
Text(String(localized: "Proximity alerts", comment: "Proximity alerts section title"))
|
||||
} footer: {
|
||||
let modeDescription = alertMode == .bestValue
|
||||
? String(format: String(localized: "When you approach the Best Value station within the radius, FuelBoard sends a notification if it could leave you at least %@ better off after extra return travel. Nearby stations selling %@ are watched — favourites get priority — and each station alerts at most once per hour.", comment: "Best Value proximity alerts section footer"), FuelSavingsFormat.money(bestValueThresholdGBP), fuel.displayName.lowercased())
|
||||
: String(format: String(localized: "When you approach a station that is the cheapest within the radius, FuelBoard sends a notification — even with the app closed. Nearby stations selling %@ are watched — favourites get priority — and each station alerts at most once per hour. Follow search mirrors the Stations-tab distance, capped at 8 miles for reliable geofencing. Smaller radii ping more often but later; larger radii ping rarely in town but earlier from afar.", comment: "Proximity alerts section footer"), fuel.displayName.lowercased())
|
||||
Text(modeDescription)
|
||||
}
|
||||
|
||||
if enabled, let lastAlert {
|
||||
@@ -212,21 +243,38 @@ struct AlertsView: View {
|
||||
|
||||
Section {
|
||||
Toggle(String(localized: "Cheapest station", comment: "Live Activity toggle"), isOn: $liveActivityEnabled)
|
||||
Picker(String(localized: "Fuel", comment: "Fuel picker title"), selection: $liveActivityFuel) {
|
||||
ForEach(FuelType.allCases) { fuel in
|
||||
Text(fuel.displayName).tag(fuel)
|
||||
Group {
|
||||
optionRow(String(localized: "Fuel", comment: "Fuel picker title"),
|
||||
value: liveActivityFuel.displayName,
|
||||
isEnabled: liveActivityEnabled) {
|
||||
Picker(String(localized: "Fuel", comment: "Fuel picker title"), selection: $liveActivityFuel) {
|
||||
ForEach(FuelType.allCases) { fuel in
|
||||
Text(fuel.displayName).tag(fuel)
|
||||
}
|
||||
}
|
||||
}
|
||||
Picker(String(localized: "Distance", comment: "Distance picker title"), selection: laChoice) {
|
||||
Text(String(format: String(localized: "Follow search (%@)", comment: "Follow current station search distance option"), searchInUnitLabel)).tag(LADistanceChoice.followSearch)
|
||||
ForEach(FuelStore.stationRadiusOptions, id: \.self) { miles in
|
||||
Text(distanceLabel(forMiles: miles)).tag(LADistanceChoice.fixed(miles))
|
||||
optionRow(String(localized: "Distance", comment: "Distance picker title"),
|
||||
value: laDistanceValueLabel,
|
||||
isEnabled: liveActivityEnabled) {
|
||||
Picker(String(localized: "Distance", comment: "Distance picker title"), selection: laChoice) {
|
||||
Text(String(format: String(localized: "Follow search (%@)", comment: "Follow current station search distance option"), searchInUnitLabel)).tag(LADistanceChoice.followSearch)
|
||||
ForEach(FuelStore.stationRadiusOptions, id: \.self) { miles in
|
||||
Text(distanceLabel(forMiles: miles)).tag(LADistanceChoice.fixed(miles))
|
||||
}
|
||||
}
|
||||
}
|
||||
if liveActivityFollowsSearch {
|
||||
Text(String(localized: "Uses the same distance as your station search.", comment: "Live Activity distance description, follow search"))
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Text(String(localized: "See the cheapest nearby station on your Lock Screen and Dynamic Island, with updates as you travel.", comment: "Live Activity section description"))
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.fuelBoardDisabledState(isEnabled: liveActivityEnabled)
|
||||
} header: {
|
||||
Text(String(localized: "Live Activity", comment: "Live Activity section title"))
|
||||
} footer: {
|
||||
Text(String(localized: "Shows the cheapest station for the fuel and distance you pick here on the Lock Screen and Dynamic Island — independent of the Stations tab (choose Follow search to mirror its distance instead). Updates as you drive; tap to open directions. Live Activities can be disabled in System Settings → Live Activities.", comment: "Live Activity section footer"))
|
||||
}
|
||||
}
|
||||
.navigationTitle(String(localized: "Alerts", comment: "Alerts tab title"))
|
||||
|
||||
+51
-93
@@ -37,7 +37,6 @@ struct ContentView: View {
|
||||
@State private var alertsEnabled: Bool = FuelStore.loadAlertsEnabled()
|
||||
@State private var alertsRadius: Double = FuelStore.loadAlertsRadius()
|
||||
@State private var alertsFuel: FuelType = FuelStore.loadAlertsFuel()
|
||||
@State private var alertsMode: AlertMode = FuelStore.loadAlertsMode()
|
||||
@State private var alertsBestValueThresholdGBP: Double = FuelStore.loadAlertsBestValueThresholdGBP()
|
||||
@State private var favouriteDropAlertsEnabled: Bool = FuelStore.loadFavouriteDropAlertsEnabled()
|
||||
@State private var favouriteDropAlertsFuel: FuelType = FuelStore.loadFavouriteDropAlertsFuel()
|
||||
@@ -152,23 +151,13 @@ struct ContentView: View {
|
||||
FuelStore.effectiveAlertsRadiusKM(followsSearch: alertsFollowsSearch, manualKM: alertsRadius)
|
||||
}
|
||||
|
||||
private var effectiveAlertsMode: AlertMode {
|
||||
(alertsMode == .bestValue && !fuelSavingsSettings.isConfigured) ? .cheapest : alertsMode
|
||||
}
|
||||
|
||||
private func ensureBestValueAlertModeIsAvailable() {
|
||||
guard alertsMode == .bestValue, !fuelSavingsSettings.isConfigured else { return }
|
||||
alertsMode = .cheapest
|
||||
FuelStore.saveAlertsMode(.cheapest)
|
||||
}
|
||||
|
||||
private func updateAlertMonitor(fuel overrideFuel: FuelType? = nil) {
|
||||
monitor.update(
|
||||
stations: stations,
|
||||
favourites: refreshedFavourites,
|
||||
fuel: overrideFuel ?? alertsFuel,
|
||||
radiusKM: effectiveAlertsRadiusKM,
|
||||
alertMode: effectiveAlertsMode,
|
||||
alertMode: .cheapest,
|
||||
bestValueThresholdGBP: alertsBestValueThresholdGBP,
|
||||
fuelSavingsSettings: fuelSavingsSettings,
|
||||
fuelSavingsAmount: sessionFuelSavingsAmount
|
||||
@@ -1154,7 +1143,6 @@ struct ContentView: View {
|
||||
// or the choice wouldn't take effect until the next launch.
|
||||
fuelSavingsSettings = FuelStore.loadFuelSavingsSettings()
|
||||
sessionFuelSavingsAmount = fuelSavingsSettings.preferredAmount
|
||||
ensureBestValueAlertModeIsAvailable()
|
||||
locationManager.startForegroundTracking()
|
||||
installLocationUpdateHook()
|
||||
ensureBackgroundMotionTrackingIfNeeded()
|
||||
@@ -1174,7 +1162,6 @@ struct ContentView: View {
|
||||
#if DEBUG
|
||||
print("FB-SAVINGS settings changed: enabled=\(old.enabled)->\(new.enabled) configured=\(new.isConfigured)")
|
||||
#endif
|
||||
ensureBestValueAlertModeIsAvailable()
|
||||
updateAlertMonitor()
|
||||
}
|
||||
.onChange(of: sessionFuelSavingsAmount) { _, _ in
|
||||
@@ -1257,16 +1244,6 @@ struct ContentView: View {
|
||||
FuelStore.saveAlertsFuel(newValue)
|
||||
updateAlertMonitor(fuel: newValue)
|
||||
}
|
||||
.onChange(of: alertsMode) { _, newValue in
|
||||
if newValue == .bestValue, !fuelSavingsSettings.isConfigured {
|
||||
alertsMode = .cheapest
|
||||
FuelStore.saveAlertsMode(.cheapest)
|
||||
updateAlertMonitor()
|
||||
return
|
||||
}
|
||||
FuelStore.saveAlertsMode(newValue)
|
||||
updateAlertMonitor()
|
||||
}
|
||||
.onChange(of: alertsBestValueThresholdGBP) { _, newValue in
|
||||
FuelStore.saveAlertsBestValueThresholdGBP(newValue)
|
||||
updateAlertMonitor()
|
||||
@@ -1609,9 +1586,6 @@ struct ContentView: View {
|
||||
enabled: $alertsEnabled,
|
||||
radius: $alertsRadius,
|
||||
fuel: $alertsFuel,
|
||||
alertMode: $alertsMode,
|
||||
bestValueThresholdGBP: alertsBestValueThresholdGBP,
|
||||
bestValueConfigured: fuelSavingsSettings.isConfigured,
|
||||
favouriteDropEnabled: $favouriteDropAlertsEnabled,
|
||||
favouriteDropFuel: $favouriteDropAlertsFuel,
|
||||
followsSearch: $alertsFollowsSearch,
|
||||
@@ -1846,8 +1820,8 @@ struct StationRow: View {
|
||||
/// styles. The mockup's divider sits at ~53% of its row; this is that ratio,
|
||||
/// held per row rather than derived from the row's text — the point is that
|
||||
/// the hairline, the price axis and the star cannot move as the list scrolls.
|
||||
/// The price column takes the remainder, and its savings capsule scales down
|
||||
/// instead of widening the column and dragging the hairline with it.
|
||||
/// The price column takes the remainder, and its listing verdict wraps
|
||||
/// vertically instead of widening the column and dragging the hairline.
|
||||
///
|
||||
/// One value for both price styles: the star used to sit at the end of the
|
||||
/// price line and hold ~28pt of the price column, so the wide form `£1.58⁷/L`
|
||||
@@ -1857,11 +1831,6 @@ struct StationRow: View {
|
||||
/// in pounds & pence, and names keep the same room in both styles.
|
||||
private static let leftSectionShare: CGFloat = 0.52
|
||||
|
||||
/// The comparison label sits beside the capsule only where the row is wide
|
||||
/// enough for both (regular width). On an iPhone the mockup's canvas is
|
||||
/// wider than the whole screen, so the label drops under the capsule rather
|
||||
/// than starving the station name.
|
||||
@Environment(\.horizontalSizeClass) private var sizeClass
|
||||
|
||||
private var ragColor: Color {
|
||||
guard let price = station.prices[fuel], let baselinePrice else { return .gray }
|
||||
@@ -1972,14 +1941,18 @@ struct StationRow: View {
|
||||
|
||||
// Name, full address, distance
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
// The name WRAPS instead of truncating: the row is tall
|
||||
// enough now, and a name cut to "Z A Service Stat…" cannot
|
||||
// be told apart from the station next door. Baseline
|
||||
// alignment keeps the notice symbols on the name's FIRST
|
||||
// line instead of floating beside a two-line name.
|
||||
// The name wraps, capped at THREE lines. The row is tall
|
||||
// enough for a two-line name, but an unbounded wrap let one
|
||||
// very long forecourt name set the height of the whole row —
|
||||
// the excessive row heights this refinement removes. Past
|
||||
// three lines the name ellipsises; the full name is always
|
||||
// in Station Details. Baseline alignment keeps the notice
|
||||
// symbols on the name's FIRST line instead of floating
|
||||
// beside a two-line name.
|
||||
HStack(alignment: .firstTextBaseline, spacing: 6) {
|
||||
Text(station.name)
|
||||
.font(.headline)
|
||||
.lineLimit(3)
|
||||
.multilineTextAlignment(.leading)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
ForEach(StationNotice.notices(for: station)) { notice in
|
||||
@@ -2050,29 +2023,33 @@ struct StationRow: View {
|
||||
if let badge = recommendationBadge {
|
||||
badgeCapsule(badge)
|
||||
}
|
||||
// Price line: the status dot and the price, leading-aligned on
|
||||
// the column's one axis. The star no longer ends this line — it
|
||||
// sits under the station logo — so this whole column width now
|
||||
// belongs to the price, which is what lets the wide pounds &
|
||||
// pence form (£1.58⁷/L) render at full size rather than being
|
||||
// scaled down or truncated.
|
||||
if let price = station.prices[fuel] {
|
||||
HStack(spacing: 5) {
|
||||
Circle()
|
||||
.fill(ragColor)
|
||||
.frame(width: 8, height: 8)
|
||||
FuelStore.priceTextAttributed(price, style: priceDisplayStyle,
|
||||
size: priceSize, weight: .bold)
|
||||
.lineLimit(1)
|
||||
.minimumScaleFactor(0.8)
|
||||
// The price and its verdict capsule are ONE vertically grouped
|
||||
// element: 5pt binds them as "this price, this outcome", while
|
||||
// the badge keeps the column's full 12pt above so the three
|
||||
// lines do not read as equals.
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
// Price line: the status dot and the price, leading-aligned
|
||||
// on the column's one axis. The star no longer ends this
|
||||
// line — it sits under the station logo — so this whole
|
||||
// column width now belongs to the price, which is what lets
|
||||
// the wide pounds & pence form (£1.58⁷/L) render at full
|
||||
// size rather than being scaled down or truncated.
|
||||
if let price = station.prices[fuel] {
|
||||
HStack(spacing: 5) {
|
||||
PriceRatingDot(color: ragColor)
|
||||
FuelStore.priceTextAttributed(price, style: priceDisplayStyle,
|
||||
size: priceSize, weight: .bold)
|
||||
.lineLimit(1)
|
||||
.minimumScaleFactor(0.8)
|
||||
}
|
||||
// The visible "+1.8p vs cheapest" line is gone with the
|
||||
// redesign, so the comparison rides on the price's label.
|
||||
.accessibilityElement(children: .ignore)
|
||||
.accessibilityLabel(priceSpokenLabel(price))
|
||||
}
|
||||
if let result = fuelSavings?.result {
|
||||
savingsCapsule(result)
|
||||
}
|
||||
// The visible "+1.8p vs cheapest" line is gone with the
|
||||
// redesign, so the comparison rides on the price's label.
|
||||
.accessibilityElement(children: .ignore)
|
||||
.accessibilityLabel(priceSpokenLabel(price))
|
||||
}
|
||||
if let result = fuelSavings?.result {
|
||||
savingsCapsule(result)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
@@ -2093,46 +2070,27 @@ struct StationRow: View {
|
||||
Button {
|
||||
onToggleFavourite()
|
||||
} label: {
|
||||
Image(systemName: isFavourite ? "star.fill" : "star")
|
||||
.foregroundStyle(isFavourite ? .yellow : .secondary)
|
||||
FavouriteStarGlyph(isFavourite: isFavourite)
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
}
|
||||
|
||||
/// The savings capsule plus the comparison it is measured against. The
|
||||
/// capsule itself is the shared verdict view, so a row, the detail sheet and
|
||||
/// the compact summary cannot drift apart. The comparison label sits UNDER
|
||||
/// the capsule, trailing-aligned with it, at every width — beside it, a long
|
||||
/// verdict pushed the caption off the row and the pair no longer read as one
|
||||
/// statement.
|
||||
@ViewBuilder
|
||||
/// The listing's verdict capsule — ONE component for every status, so the
|
||||
/// baseline's "Closest station" pill carries the same soft blue fill, white
|
||||
/// text and shape rules as Saves, Costs and Break even. The detail sheet
|
||||
/// keeps `FuelSavingsCapsule` to itself, unchanged.
|
||||
private func savingsCapsule(_ result: FuelSavingsResult) -> some View {
|
||||
VStack(alignment: .trailing, spacing: 2) {
|
||||
FuelSavingsCapsule(result: result)
|
||||
Text(FuelSavingsFormat.comparisonLabel(status: result.status))
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
// Same narrow column as the capsule above it, so the same floor:
|
||||
// scaled copy, not a trimmed "vs closest st…".
|
||||
.minimumScaleFactor(0.7)
|
||||
.multilineTextAlignment(.trailing)
|
||||
}
|
||||
ListingFuelSavingsCapsule(result: result)
|
||||
}
|
||||
|
||||
/// One recommendation badge, above the price it annotates. Tinted rather
|
||||
/// than the mockup's solid fill, like every other badge and capsule in the
|
||||
/// app: coloured text keeps its contrast in both appearances, at every
|
||||
/// Dynamic Type size, without introducing a colour outside the palette.
|
||||
/// One recommendation badge, above the price it annotates. Badges stay
|
||||
/// TINTED with coloured text — unlike the verdict capsules, which are filled
|
||||
/// with white text: a badge annotates the price rather than reporting an
|
||||
/// outcome, so it should stay quieter than the pill beneath it. Tinted text
|
||||
/// also keeps its contrast in both appearances at every Dynamic Type size
|
||||
/// without introducing a colour outside the palette.
|
||||
private func badgeCapsule(_ badge: StationRecommendationBadge) -> some View {
|
||||
Text(badge.title)
|
||||
.font(.caption2.bold())
|
||||
.foregroundStyle(badge.tint)
|
||||
.padding(.horizontal, 7)
|
||||
.padding(.vertical, 3)
|
||||
.background(Capsule().fill(badge.tint.opacity(0.15)))
|
||||
.lineLimit(1)
|
||||
.fixedSize()
|
||||
StationLabelBadge(label: badge.title, color: badge.tint)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,14 @@ struct FavouritesView: View {
|
||||
/// Trends sheet (price history chart) presentation state.
|
||||
@State private var showTrends = false
|
||||
|
||||
/// The Key (legend) sheet — the same sheet the Stations tab presents, opened
|
||||
/// from the info button beside Edit.
|
||||
@State private var showKey = false
|
||||
/// The Key sheet's two nested sheets, owned here because its rows set them
|
||||
/// (same arrangement as StationsView, so the QA hooks behave identically).
|
||||
@State private var showBestValueInfo = false
|
||||
@State private var showImportantInformation = false
|
||||
|
||||
/// Station picked for the More-info sheet (tap action = showDetails).
|
||||
@State private var detailStation: FuelStation?
|
||||
|
||||
@@ -69,6 +77,15 @@ struct FavouritesView: View {
|
||||
}
|
||||
private var cheapestPrice: Double? { cheapest?.prices[activeFuel] }
|
||||
|
||||
/// The baseline note is useful only when at least one visible favourite has
|
||||
/// an actual savings comparison. An unavailable result (for example, while
|
||||
/// location is missing) must not leave an orphaned explanation below the list.
|
||||
private var showsSavingsComparisonExplanation: Bool {
|
||||
fuelSavingsSettings.isConfigured && ordered.contains { station in
|
||||
savingsForStation(station)?.result != nil
|
||||
}
|
||||
}
|
||||
|
||||
/// IDs favourited for the active fuel — the star state on each row.
|
||||
private var activeFuelFavouriteIDs: Set<String> {
|
||||
Set(favourites.filter { $0.fuel == activeFuel }.map(\.station.id))
|
||||
@@ -145,8 +162,15 @@ struct FavouritesView: View {
|
||||
if fuelSavingsSettings.isConfigured {
|
||||
Section {
|
||||
FuelSavingsAdjustmentView(amount: $fuelSavingsAmount)
|
||||
} footer: {
|
||||
Text(String(localized: "Savings below are estimated against the closest station by journey distance — the same baseline as the Stations list.", comment: "Favourites fuel-savings explanation"))
|
||||
}
|
||||
}
|
||||
|
||||
if showsSavingsComparisonExplanation {
|
||||
Section {
|
||||
Text(String(localized: "Price colours show pump price competitiveness. Savings compare with your closest station, including journey costs.", comment: "Station listing price and savings explanation"))
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +195,12 @@ struct FavouritesView: View {
|
||||
} header: {
|
||||
Text(String(format: String(localized: "%@ favourites", comment: "Favourites section title for fuel type"), activeFuel.displayName))
|
||||
} footer: {
|
||||
Text(String(localized: "The first station is the favourite used in single widgets. Tap Edit, then drag to reorder.", comment: "Favourites reorder explanation"))
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text(String(localized: "The first station is the favourite used in single widgets. Tap Edit, then drag to reorder.", comment: "Favourites reorder explanation"))
|
||||
}
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
if let cheapest = cheapest {
|
||||
@@ -185,8 +214,8 @@ struct FavouritesView: View {
|
||||
}
|
||||
.navigationTitle(String(localized: "Favourites", comment: "Favourites tab title"))
|
||||
.toolbar {
|
||||
if !favourites.isEmpty {
|
||||
ToolbarItemGroup(placement: .topBarTrailing) {
|
||||
ToolbarItemGroup(placement: .topBarTrailing) {
|
||||
if !favourites.isEmpty {
|
||||
Button {
|
||||
showTrends = true
|
||||
} label: {
|
||||
@@ -195,8 +224,25 @@ struct FavouritesView: View {
|
||||
}
|
||||
EditButton()
|
||||
}
|
||||
// Same button and same slot as the Stations tab: last in the
|
||||
// group, so it sits to the right of Edit. Shown even with no
|
||||
// favourites — the legend explains the prices and labels, which
|
||||
// matter before anything is starred.
|
||||
Button {
|
||||
showKey = true
|
||||
} label: {
|
||||
Image(systemName: "info.circle")
|
||||
}
|
||||
.accessibilityLabel(String(localized: "Key", comment: "Key button accessibility label"))
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showKey) {
|
||||
KeySheetView(
|
||||
fuelTint: activeFuel.tintColor,
|
||||
showBestValueInfo: $showBestValueInfo,
|
||||
showImportantInformation: $showImportantInformation
|
||||
)
|
||||
}
|
||||
.sheet(isPresented: $showTrends) {
|
||||
TrendsView(
|
||||
favourites: favourites,
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Applies FuelBoard's shared unavailable appearance and native interaction state
|
||||
/// to a complete dependent row or group. Apply it once at the highest dependent
|
||||
/// container so labels, values, icons, descriptions and controls fade together.
|
||||
extension View {
|
||||
func fuelBoardDisabledState(isEnabled: Bool) -> some View {
|
||||
disabled(!isEnabled)
|
||||
.allowsHitTesting(isEnabled)
|
||||
.opacity(isEnabled ? 1 : 0.5)
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import SwiftUI
|
||||
struct FuelSavingsAdjustmentView: View {
|
||||
@Binding var amount: FuelSavingsFillAmount
|
||||
|
||||
@State private var unitChangeNotice: String?
|
||||
@State private var showingComparisonHelp = false
|
||||
|
||||
private var range: ClosedRange<Double> {
|
||||
FuelSavingsCalculator.fillAmountSliderRange(for: amount.unit)
|
||||
@@ -26,8 +26,33 @@ struct FuelSavingsAdjustmentView: View {
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("How much are you filling up?")
|
||||
.font(.subheadline.weight(.semibold))
|
||||
HStack {
|
||||
Text("How much fuel?")
|
||||
.font(.subheadline.weight(.semibold))
|
||||
Spacer()
|
||||
Button {
|
||||
showingComparisonHelp = true
|
||||
} label: {
|
||||
Image(systemName: "info.circle")
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.foregroundStyle(.secondary)
|
||||
.accessibilityLabel("About comparison modes")
|
||||
.popover(isPresented: $showingComparisonHelp) {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Comparison modes")
|
||||
.font(.headline)
|
||||
Text("£: Compare how much fuel your budget buys at each station.")
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
Text("Litres: Compare the cost of buying the same amount of fuel.")
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
.font(.footnote)
|
||||
.frame(width: 280, alignment: .leading)
|
||||
.padding()
|
||||
.presentationCompactAdaptation(.popover)
|
||||
}
|
||||
}
|
||||
Picker("Fill-up unit", selection: unitBinding) {
|
||||
ForEach(FuelSavingsFillUnit.allCases) { unit in
|
||||
Text(unit.displayName).tag(unit)
|
||||
@@ -42,17 +67,9 @@ struct FuelSavingsAdjustmentView: View {
|
||||
.monospacedDigit()
|
||||
.frame(width: 72, alignment: .trailing)
|
||||
}
|
||||
Text("Changes the estimate for this session only — your Settings default stays unchanged.")
|
||||
Text("Adjust your fill-up amount for this visit. Your default won’t change.")
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.secondary)
|
||||
Text("£ compares the litres your budget buys at each station; Litres compares one fixed quantity.")
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.secondary)
|
||||
if let unitChangeNotice {
|
||||
Text(unitChangeNotice)
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.orange)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,10 +78,9 @@ struct FuelSavingsAdjustmentView: View {
|
||||
get: { amount.unit },
|
||||
set: { newUnit in
|
||||
guard newUnit != amount.unit else { return }
|
||||
// No one litre figure equals a budget at every candidate price.
|
||||
// A unit change starts a new, explicitly labelled comparison.
|
||||
// No one litre figure equals a budget at every candidate price,
|
||||
// so switching modes starts from that mode's configured default.
|
||||
amount = FuelSavingsCalculator.newComparisonAmount(afterSwitching: amount, to: newUnit)
|
||||
unitChangeNotice = "New comparison basis — adjust the \(newUnit.displayName) amount to your intended fill-up."
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -77,8 +93,8 @@ struct FuelSavingsAdjustmentView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// The colour-coded verdict capsule shared by the station listing rows, the
|
||||
/// detail sheet and the compact summary.
|
||||
/// The colour-coded monetary verdict capsule used by the detail sheet and other
|
||||
/// full financial summaries. Listing rows use `ListingFuelSavingsCapsule`.
|
||||
///
|
||||
/// An HStack with an explicit spacing, NOT a Label: given the width to spare,
|
||||
/// a Label lays its icon and title out across the row and leaves a visible gap
|
||||
@@ -93,7 +109,7 @@ struct FuelSavingsCapsule: View {
|
||||
HStack(spacing: compact ? 3 : 5) {
|
||||
Image(systemName: Self.symbol(for: result.status))
|
||||
.accessibilityHidden(true)
|
||||
Text(result.capsuleHeadline())
|
||||
Text(compact ? result.capsuleHeadline() : result.detailCapsuleHeadline())
|
||||
.lineLimit(1)
|
||||
// Measured on a 393pt screen: the capsule is handed ~101pt, of
|
||||
// which the icon, its spacing and the 8pt padding either side
|
||||
@@ -129,4 +145,157 @@ struct FuelSavingsCapsule: View {
|
||||
case .baseline: return "location.circle.fill"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The station listing's verdict capsule: the words on the first line, the figure
|
||||
/// on its own line beneath, and "(approx.)" on a third when the journey is an
|
||||
/// estimate.
|
||||
///
|
||||
/// Stations and Favourites share `StationRow`, so both render this. The detail
|
||||
/// sheet keeps `FuelSavingsCapsule`'s colour-coded monetary verdict on one line;
|
||||
/// the Key sheet's legend renders this with `showsAmount: false` so it never
|
||||
/// displays an invented figure.
|
||||
struct ListingFuelSavingsCapsule: View {
|
||||
let result: FuelSavingsResult
|
||||
/// Station rows carry the figure; the Key sheet's legend shows the wording only.
|
||||
var showsAmount: Bool = true
|
||||
|
||||
/// The height the text actually drew, so the shape can follow the drawn line
|
||||
/// count rather than the data's. See `drawnLineCount`.
|
||||
@State private var textHeight: CGFloat = 0
|
||||
/// One caption line's height, scaled with Dynamic Type, to divide that by.
|
||||
@ScaledMetric(relativeTo: .caption) private var captionLineHeight: CGFloat = 14
|
||||
|
||||
private var verdict: FuelSavingsResult.ListingVerdict {
|
||||
result.listingVerdict(showsAmount: showsAmount)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 3) {
|
||||
Image(systemName: symbol)
|
||||
.accessibilityHidden(true)
|
||||
// One Text per line, not a "\n" inside one string: each line keeps its
|
||||
// own localisation key and the amount can be monospaced on its own.
|
||||
// Left-aligned: the word and its figure share a left edge, so the
|
||||
// block reads as a column rather than a ragged centre.
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
Text(verdict.headline)
|
||||
if let amount = verdict.amount {
|
||||
Text(amount)
|
||||
.monospacedDigit()
|
||||
}
|
||||
if let qualifier = verdict.qualifier {
|
||||
Text(qualifier)
|
||||
}
|
||||
}
|
||||
.multilineTextAlignment(.leading)
|
||||
// Never compress or truncate: the capsule wraps and the row grows taller.
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.background(
|
||||
GeometryReader { proxy in
|
||||
Color.clear
|
||||
.preference(key: CapsuleTextHeightKey.self,
|
||||
value: proxy.size.height)
|
||||
}
|
||||
)
|
||||
}
|
||||
// White on the muted fill. These capsules carry a figure the eye is asked
|
||||
// to read at a glance, which is why they are the only filled-and-white
|
||||
// surfaces in the app; every badge stays tinted with coloured text.
|
||||
.font(.caption.weight(.semibold))
|
||||
.foregroundStyle(.white)
|
||||
.padding(.horizontal, 8)
|
||||
.padding(.vertical, 4)
|
||||
// Saves and Costs share one minimum width, so their trailing edges line
|
||||
// up down the list whatever the figure's length. Break even and Closest
|
||||
// station carry no figure and keep their natural width.
|
||||
.frame(minWidth: minimumWidth, alignment: .leading)
|
||||
.background(shape.fill(fill))
|
||||
.accessibilityElement(children: .combine)
|
||||
.accessibilityLabel(verdict.spokenText)
|
||||
.onPreferenceChange(CapsuleTextHeightKey.self) { textHeight = $0 }
|
||||
}
|
||||
|
||||
/// Saves and Costs only — the two verdicts that carry a figure. See the
|
||||
/// frame above: 84pt is the width the widest common amount needs
|
||||
/// ("£123.45 more"), so shorter figures pad rather than shrink the pill.
|
||||
private var minimumWidth: CGFloat {
|
||||
switch result.status {
|
||||
case .worthTheDrive, .notWorthTheDrive: return 84
|
||||
case .breakEven, .baseline: return 0
|
||||
}
|
||||
}
|
||||
|
||||
private var fill: Color {
|
||||
ListingCapsuleFill.color(for: result.status)
|
||||
}
|
||||
|
||||
/// How many lines the text DREW, not how many the verdict declares.
|
||||
/// "Closest station" is one declared line that wraps to two in the row's
|
||||
/// narrow column, and the shape has to follow what is on screen or the pill's
|
||||
/// semicircular ends crowd the text they are wrapping. Falls back to the
|
||||
/// declared count on the first layout pass, before there is a height.
|
||||
private var drawnLineCount: Int {
|
||||
guard textHeight > 0, captionLineHeight > 0 else { return verdict.lines.count }
|
||||
return max(1, Int((textHeight / captionLineHeight).rounded()))
|
||||
}
|
||||
|
||||
/// One line keeps the capsule. Two or more switch to a rounded rect: a pill's
|
||||
/// semicircular ends crowd the text corners at that height, while an 8pt
|
||||
/// radius does not. Keyed to the DRAWN line count, so a wrapped "Closest
|
||||
/// station" gets the same rounded rect as a figure pushed onto its own line.
|
||||
private var shape: AnyShape {
|
||||
drawnLineCount > 1
|
||||
? AnyShape(RoundedRectangle(cornerRadius: 8))
|
||||
: AnyShape(Capsule())
|
||||
}
|
||||
|
||||
private var symbol: String {
|
||||
switch result.status {
|
||||
case .worthTheDrive: return "checkmark.circle"
|
||||
case .notWorthTheDrive: return "arrow.up.circle"
|
||||
case .breakEven: return "equal.circle"
|
||||
case .baseline: return "location.circle"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Carries the drawn height of a capsule's text block up to `drawnLineCount`.
|
||||
private struct CapsuleTextHeightKey: PreferenceKey {
|
||||
static let defaultValue: CGFloat = 0
|
||||
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
|
||||
value = max(value, nextValue())
|
||||
}
|
||||
}
|
||||
|
||||
/// The station listing's verdict-capsule fills: muted semantic colours carrying
|
||||
/// white text and icon.
|
||||
///
|
||||
/// Muted AND fixed, deliberately not the translucent tints used elsewhere in the
|
||||
/// app: white text on a 15% tint over a white row measures ~1.8:1 and is
|
||||
/// unreadable. Each tone below sits at a relative luminance of ~0.18 — the band
|
||||
/// where white text clears 4.5:1 AND the pill still separates ~3:1 from BOTH a
|
||||
/// white row and the dark card fill — so one value each works in both
|
||||
/// appearances without a dynamic colour.
|
||||
///
|
||||
/// The saturated palette colours cannot carry white text at all: measured
|
||||
/// white-on-fill is 2.2:1 for `systemGreen`, 3.6:1 for `systemRed` and 4.0:1 for
|
||||
/// `systemBlue`, every one of them below the 4.5:1 a caption needs. Muting is
|
||||
/// therefore a contrast requirement here, not only the mockup's taste.
|
||||
enum ListingCapsuleFill {
|
||||
// Trailing comments record, per colour: white-on-fill / fill-vs-white-row /
|
||||
// fill-vs-dark-row, measured rather than estimated.
|
||||
static let saves = Color(red: 0x45 / 255, green: 0x82 / 255, blue: 0x5E / 255) // 4.56 / 4.56 / 3.06
|
||||
static let costs = Color(red: 0xA9 / 255, green: 0x63 / 255, blue: 0x5B / 255) // 4.54 / 4.54 / 3.07
|
||||
static let breakEven = Color(red: 0x70 / 255, green: 0x70 / 255, blue: 0x70 / 255) // 4.95 / 4.95 / 2.81
|
||||
static let closest = Color(red: 0x58 / 255, green: 0x78 / 255, blue: 0x9D / 255) // 4.52 / 4.52 / 3.09
|
||||
|
||||
static func color(for status: FuelSavingsStatus) -> Color {
|
||||
switch status {
|
||||
case .worthTheDrive: return saves
|
||||
case .notWorthTheDrive: return costs
|
||||
case .breakEven: return breakEven
|
||||
case .baseline: return closest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ struct HowBestValueRow: View {
|
||||
var body: some View {
|
||||
Button(action: action) {
|
||||
HStack(spacing: 8) {
|
||||
Text("How Best Value works")
|
||||
Text(KeySheetContent.helpTitle)
|
||||
Spacer(minLength: 8)
|
||||
Image(systemName: "chevron.forward")
|
||||
.font(.footnote.weight(.semibold))
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
import SwiftUI
|
||||
|
||||
/// "Important information" — FuelBoard's prices, availability, savings, journey
|
||||
/// and liability disclaimer as ONE reusable sheet.
|
||||
///
|
||||
/// The disclaimer is shown from more than one place, so the copy and its layout
|
||||
/// live here once: a host adds an `ImportantInformationRow` (or the
|
||||
/// `.importantInformationSheet(isPresented:)` modifier) and the wording can
|
||||
/// never drift between entry points.
|
||||
///
|
||||
/// One `Section` per topic, so every heading gets its own card: an accent
|
||||
/// symbol beside a semibold title, with the secondary-coloured description
|
||||
/// beneath. First host: the Stations tab's Key sheet (a row at the bottom). Copy
|
||||
/// lives in `Localizable.strings`, keyed by the English source string, so the web
|
||||
/// copy editor covers it.
|
||||
struct ImportantInformationSheet: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
/// Width of the symbol column that every heading's icon sits in.
|
||||
///
|
||||
/// Symbols have wildly different ink widths — `car.side` is ~34 pt wide at
|
||||
/// this size while `info.circle` is ~20 pt — so without a shared column each
|
||||
/// heading's TEXT would start at a different x (measured: 180 px vs 233 px
|
||||
/// at 3x), which is exactly the inconsistent alignment the brief rules out.
|
||||
/// `@ScaledMetric` keeps the column in step with the icon font, so it still
|
||||
/// can't overrun at large Dynamic Type sizes.
|
||||
@ScaledMetric(relativeTo: .title3) private var iconSlot: CGFloat = 34
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
List {
|
||||
Section {
|
||||
paragraphs(
|
||||
"FuelBoard uses fuel price information published through the UK Government's fuel price data scheme. Prices are supplied by retailers and may change or differ from those displayed in the app.",
|
||||
"While we aim to provide accurate, up-to-date information, we cannot guarantee that displayed prices reflect those currently available at the pump."
|
||||
)
|
||||
} header: {
|
||||
heading("Fuel Prices", systemImage: "sterlingsign.circle")
|
||||
}
|
||||
|
||||
Section {
|
||||
paragraphs(
|
||||
"A displayed fuel price does not guarantee availability. Stations may temporarily run out of fuel, have pumps out of service, be closed or no longer offer a particular fuel type.",
|
||||
"We recommend checking availability before making a special journey."
|
||||
)
|
||||
} header: {
|
||||
heading("Fuel Availability", systemImage: "fuelpump.fill")
|
||||
}
|
||||
|
||||
Section {
|
||||
paragraphs(
|
||||
"Savings and Best Value recommendations are estimates based on available fuel prices, your selected fill-up amount, estimated travel costs and other relevant settings.",
|
||||
"Actual savings may vary depending on fuel consumption, driving conditions, routes and current pump prices. A Best Value recommendation does not guarantee the lowest overall cost."
|
||||
)
|
||||
} header: {
|
||||
heading("Savings & Best Value", systemImage: "arrow.down.circle")
|
||||
}
|
||||
|
||||
Section {
|
||||
paragraphs(
|
||||
"Travel distances, journey times and associated fuel costs are estimates. Where actual road distances are unavailable, approximate distances may be used.",
|
||||
"Actual journeys may differ due to traffic, road conditions, diversions and individual driving habits."
|
||||
)
|
||||
} header: {
|
||||
heading("Journey Estimates", systemImage: "car.side")
|
||||
}
|
||||
|
||||
Section {
|
||||
paragraphs(
|
||||
"Fuel prices and availability can change without notice. Always check the current price and fuel availability before making a special journey or filling up."
|
||||
)
|
||||
} header: {
|
||||
heading("Before You Travel", systemImage: "checkmark.circle")
|
||||
}
|
||||
|
||||
Section {
|
||||
paragraphs(
|
||||
"FuelBoard provides information to help you compare fuel prices and make informed decisions. We cannot guarantee the accuracy, completeness or availability of fuel price information, savings estimates or recommendations.",
|
||||
"FuelBoard accepts no responsibility for additional travel costs, financial losses or decisions made using the information provided."
|
||||
)
|
||||
} header: {
|
||||
heading("Disclaimer", systemImage: "info.circle")
|
||||
}
|
||||
}
|
||||
// The brief asks for ~24 pt between topics; the list's own default is
|
||||
// wider and unsettable, this pins it.
|
||||
.listSectionSpacing(.custom(24))
|
||||
.navigationTitle("Important information")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Done") { dismiss() }
|
||||
}
|
||||
}
|
||||
}
|
||||
.presentationDetents([.large])
|
||||
.presentationBackground(Color(UIColor.systemGroupedBackground))
|
||||
}
|
||||
|
||||
/// A section heading: accent symbol + semibold title, laid out horizontally
|
||||
/// and vertically centred, with the symbol at a consistent size in every
|
||||
/// section.
|
||||
///
|
||||
/// `.title3` is 20 pt at the default Dynamic Type size — inside the 18–20 pt
|
||||
/// brief — and still scales with the user's text size, so the symbols stay in
|
||||
/// proportion to the headings rather than drifting apart on large sizes.
|
||||
///
|
||||
/// The symbol is decorative (the heading text already carries the meaning),
|
||||
/// so it is hidden from VoiceOver to stop it being announced as a stray glyph.
|
||||
private func heading(_ title: String, systemImage: String) -> some View {
|
||||
HStack(alignment: .center, spacing: 8) {
|
||||
Image(systemName: systemImage)
|
||||
.font(.title3)
|
||||
.foregroundStyle(Color.accentColor)
|
||||
// Same-width column for every symbol, so all six headings'
|
||||
// text starts at one x regardless of how wide the glyph is.
|
||||
.frame(width: iconSlot)
|
||||
.accessibilityHidden(true)
|
||||
Text(LocalizedStringKey(title))
|
||||
.font(.headline)
|
||||
// `Color.primary`, not `.primary`: the bare ShapeStyle resolves
|
||||
// against the List header's own secondary style and comes out
|
||||
// grey — measured (152,152,159), i.e. identical to the body text,
|
||||
// which throws away the heading/description hierarchy.
|
||||
.foregroundStyle(Color.primary)
|
||||
// Let a long heading wrap instead of truncating on a narrow
|
||||
// device or at a large text size.
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
}
|
||||
|
||||
/// A card's paragraphs, stacked as prose rather than as separate `List` rows
|
||||
/// so the card reads as one statement and the list draws no hairline between
|
||||
/// a topic's own sentences.
|
||||
///
|
||||
/// `LocalizedStringKey` is what makes a `String` parameter localisable —
|
||||
/// `Text(someString)` would render verbatim and the copy editor could never
|
||||
/// reach it.
|
||||
@ViewBuilder
|
||||
private func paragraphs(_ lines: String...) -> some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
ForEach(Array(lines.enumerated()), id: \.offset) { _, line in
|
||||
Text(LocalizedStringKey(line))
|
||||
}
|
||||
}
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
/// The row that opens `ImportantInformationSheet`. Reusable: drop it in any
|
||||
/// `List` section.
|
||||
///
|
||||
/// `.buttonStyle(.plain)` keeps it from becoming a row-wide tap target that
|
||||
/// could swallow a neighbouring control (see the two-buttons-in-one-row rule).
|
||||
struct ImportantInformationRow: View {
|
||||
let action: () -> Void
|
||||
|
||||
var body: some View {
|
||||
Button(action: action) {
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: "info.circle")
|
||||
Text("Important information")
|
||||
Spacer(minLength: 8)
|
||||
Image(systemName: "chevron.forward")
|
||||
.font(.footnote.weight(.semibold))
|
||||
.foregroundStyle(.tertiary)
|
||||
}
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
/// Presents the shared "Important information" disclaimer. One call site per
|
||||
/// surface — the sheet itself is never duplicated.
|
||||
func importantInformationSheet(isPresented: Binding<Bool>) -> some View {
|
||||
sheet(isPresented: isPresented) { ImportantInformationSheet() }
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
/// QA hook support: `-showImportantInfo` opens the Key sheet and then the
|
||||
/// disclaimer on top of it, so the copy can be screenshotted without a tap
|
||||
/// (simctl has no tap command) — the same chained pattern as
|
||||
/// `-showBestValueInfo`. The disclaimer's `.sheet` lives inside the Key sheet's
|
||||
/// content, so it cannot present while the Key sheet is shut.
|
||||
enum ImportantInformationQA {
|
||||
static var isRequested: Bool {
|
||||
ProcessInfo.processInfo.arguments.contains("-showImportantInfo")
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -82,6 +82,9 @@ struct SettingsView: View {
|
||||
@State private var fillUpDraft: Double?
|
||||
@State private var versionTapCount = 0
|
||||
@State private var lastVersionTap = Date.distantPast
|
||||
/// The shared "Important information" disclaimer sheet, opened from the row
|
||||
/// at the bottom of the tab.
|
||||
@State private var showImportantInformation = false
|
||||
/// Widget diagnostics: the extension's last makeEntry beacon PER intent
|
||||
/// type (keychain) + the installed-widget inventory from WidgetCenter.
|
||||
@State private var smallWidgetDiag: String?
|
||||
@@ -198,7 +201,7 @@ struct SettingsView: View {
|
||||
.foregroundStyle(.orange)
|
||||
}
|
||||
}
|
||||
.disabled(!fuelSavingsSettings.enabled)
|
||||
.fuelBoardDisabledState(isEnabled: fuelSavingsSettings.enabled)
|
||||
} header: {
|
||||
Text("Fuel Savings")
|
||||
} footer: {
|
||||
@@ -582,7 +585,7 @@ struct SettingsView: View {
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(tipStore.purchaseInProgress)
|
||||
.fuelBoardDisabledState(isEnabled: !tipStore.purchaseInProgress)
|
||||
}
|
||||
}
|
||||
.listRowBackground(Color.clear)
|
||||
@@ -607,11 +610,16 @@ struct SettingsView: View {
|
||||
Text("About")
|
||||
}
|
||||
|
||||
Section {
|
||||
ImportantInformationRow { showImportantInformation = true }
|
||||
}
|
||||
|
||||
}
|
||||
// Numeric entry must be escapable: `.decimalPad` has no Return key.
|
||||
.keyboardDoneButton { focusedSavingsField = nil }
|
||||
.scrollDismissesKeyboard(.interactively)
|
||||
.navigationTitle("Settings")
|
||||
.importantInformationSheet(isPresented: $showImportantInformation)
|
||||
.onAppear {
|
||||
Task { await tipStore.load() }
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ struct BestValueDetailCard: View {
|
||||
Spacer(minLength: 8)
|
||||
VStack(alignment: .trailing, spacing: 4) {
|
||||
FuelSavingsCapsule(result: result, compact: false)
|
||||
.accessibilityLabel(result.spokenHeadline())
|
||||
.accessibilityLabel(result.detailCapsuleSpokenHeadline())
|
||||
comparison(result)
|
||||
}
|
||||
}
|
||||
|
||||
+269
-115
@@ -1,6 +1,94 @@
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
|
||||
/// The "Key" legend: price ratings, savings capsules, station labels, the
|
||||
/// favourite glyph, then the two deeper explanations. One sheet for both list
|
||||
/// tabs — Stations opens it from the info button in the navigation bar,
|
||||
/// Favourites from the button beside Edit — so the legend cannot drift between
|
||||
/// them.
|
||||
///
|
||||
/// Dismisses through the environment rather than the presenting view's state, and
|
||||
/// takes the two nested-sheet flags as bindings, so each tab keeps owning its own
|
||||
/// QA launch-argument hooks.
|
||||
struct KeySheetView: View {
|
||||
/// The selected fuel's colour. `KeyStationLabelIndicator` draws its pump badge
|
||||
/// in it, so the legend matches the rows the reader is looking at.
|
||||
let fuelTint: Color
|
||||
@Binding var showBestValueInfo: Bool
|
||||
@Binding var showImportantInformation: Bool
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
List {
|
||||
Section {
|
||||
KeySheetDescriptionRow(item: KeySheetContent.priceRatings[0]) {
|
||||
KeyPriceRatingIndicator(item: KeySheetContent.priceRatings[0], color: .green)
|
||||
}
|
||||
KeySheetDescriptionRow(item: KeySheetContent.priceRatings[1]) {
|
||||
KeyPriceRatingIndicator(item: KeySheetContent.priceRatings[1], color: .orange)
|
||||
}
|
||||
KeySheetDescriptionRow(item: KeySheetContent.priceRatings[2]) {
|
||||
KeyPriceRatingIndicator(item: KeySheetContent.priceRatings[2], color: .red)
|
||||
}
|
||||
} header: {
|
||||
Text("Price ratings")
|
||||
}
|
||||
|
||||
Section {
|
||||
ForEach(KeySheetContent.savings, id: \.label) { item in
|
||||
KeySheetDescriptionRow(item: item) {
|
||||
KeySavingsCapsule(label: item.label)
|
||||
}
|
||||
}
|
||||
} header: {
|
||||
Text("Savings")
|
||||
}
|
||||
|
||||
Section {
|
||||
ForEach(KeySheetContent.stationLabels, id: \.label) { item in
|
||||
KeySheetDescriptionRow(item: item) {
|
||||
KeyStationLabelIndicator(label: item.label, fuelColor: fuelTint)
|
||||
}
|
||||
}
|
||||
} header: {
|
||||
Text("Station labels")
|
||||
}
|
||||
|
||||
Section {
|
||||
KeySheetDescriptionRow(item: KeySheetContent.favourite) {
|
||||
FavouriteStarGlyph(isFavourite: true)
|
||||
}
|
||||
} header: {
|
||||
Text("Favourites")
|
||||
}
|
||||
|
||||
Section {
|
||||
HowBestValueRow { showBestValueInfo = true }
|
||||
}
|
||||
|
||||
Section {
|
||||
ImportantInformationRow { showImportantInformation = true }
|
||||
}
|
||||
}
|
||||
.navigationTitle("Key")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Done") { dismiss() }
|
||||
}
|
||||
}
|
||||
// Nested sheet: the Key sheet stays behind the explanation.
|
||||
.sheet(isPresented: $showBestValueInfo) { HowBestValueSheet() }
|
||||
// Nested sheet: the Key sheet stays behind the disclaimer.
|
||||
.importantInformationSheet(isPresented: $showImportantInformation)
|
||||
}
|
||||
.presentationDetents([.fraction(0.6), .large])
|
||||
.presentationBackground(Color(UIColor.systemGroupedBackground))
|
||||
}
|
||||
}
|
||||
|
||||
/// Stations tab — the main list with fuel picker, distance filter, sort, pagination.
|
||||
struct StationsView: View {
|
||||
let stations: [FuelStation]
|
||||
@@ -39,6 +127,11 @@ struct StationsView: View {
|
||||
/// the Key sheet and from the More info sheet.
|
||||
@State private var showBestValueInfo = false
|
||||
|
||||
/// The shared "Important information" disclaimer sheet. It lives at the
|
||||
/// bottom of the Key sheet here; the same sheet is reused wherever else the
|
||||
/// disclaimer is needed.
|
||||
@State private var showImportantInformation = false
|
||||
|
||||
/// Station picked for the More-info sheet (tap action = showDetails).
|
||||
@State private var detailStation: FuelStation?
|
||||
|
||||
@@ -123,6 +216,13 @@ struct StationsView: View {
|
||||
FuelSavingsAdjustmentView(amount: $fuelSavingsAmount)
|
||||
}
|
||||
|
||||
if fuelSavingsSettings.isConfigured && !stations.isEmpty {
|
||||
Text(String(localized: "Price colours show pump price competitiveness. Savings compare with your closest station, including journey costs.", comment: "Station listing price and savings explanation"))
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
|
||||
if isLoading && stations.isEmpty {
|
||||
HStack(spacing: 10) {
|
||||
ProgressView()
|
||||
@@ -216,6 +316,17 @@ struct StationsView: View {
|
||||
showBestValueInfo = true
|
||||
}
|
||||
}
|
||||
// QA hook: `-showImportantInfo` opens the Key sheet and then the
|
||||
// shared disclaimer on top of it, so the copy can be
|
||||
// screenshotted without a tap. Same chained requirement as
|
||||
// `-showBestValueInfo` above.
|
||||
if ImportantInformationQA.isRequested {
|
||||
showKey = true
|
||||
Task { @MainActor in
|
||||
try? await Task.sleep(nanoseconds: 1_200_000_000)
|
||||
showImportantInformation = true
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: .fuelBoardOpenBestValueSettings)) { _ in
|
||||
@@ -273,87 +384,15 @@ struct StationsView: View {
|
||||
)
|
||||
}
|
||||
|
||||
/// The legend sheet, shared with the Favourites tab. Only the fuel differs:
|
||||
/// its colour tints the station-label row, so the legend matches the rows the
|
||||
/// reader is actually looking at.
|
||||
private var keySheet: some View {
|
||||
NavigationStack {
|
||||
List {
|
||||
Section {
|
||||
VStack(spacing: 10) {
|
||||
keyCard(
|
||||
icon: "checkmark.circle.fill", color: .green,
|
||||
title: "Good price", blurb: "Within 1.5p of the cheapest",
|
||||
threshold: "0–1.5p")
|
||||
keyCard(
|
||||
icon: "equal.circle.fill", color: .orange,
|
||||
title: "Okay", blurb: "More than 1.5p, up to 4p above the cheapest",
|
||||
threshold: ">1.5–4p")
|
||||
keyCard(
|
||||
icon: "exclamationmark.circle.fill", color: .red,
|
||||
title: "Pricey", blurb: "More than 4p above the cheapest",
|
||||
threshold: ">4p")
|
||||
Rectangle()
|
||||
.fill(Color(.separator))
|
||||
.frame(height: 0.5)
|
||||
.padding(.vertical, 2)
|
||||
HStack(spacing: 12) {
|
||||
Text("TOP")
|
||||
.font(.caption2.bold())
|
||||
.padding(.horizontal, 7)
|
||||
.padding(.vertical, 3)
|
||||
.background(Capsule().fill(.blue.opacity(0.16)))
|
||||
.foregroundStyle(.blue)
|
||||
Text("Top result for the current sort")
|
||||
.font(.subheadline.weight(.semibold))
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding(.horizontal, 14)
|
||||
.padding(.vertical, 12)
|
||||
.keyCardFill(color: .blue)
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: "star.fill")
|
||||
.font(.title3)
|
||||
.foregroundStyle(.yellow)
|
||||
.frame(width: 34)
|
||||
Text("Star a station to add it to Favourites")
|
||||
.font(.subheadline.weight(.semibold))
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding(.horizontal, 14)
|
||||
.padding(.vertical, 12)
|
||||
.keyCardFill(color: .yellow)
|
||||
Text("Price differences are shown in pence per litre (p/litre). Colours match each station's rating on the list.")
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.top, 4)
|
||||
}
|
||||
.listRowBackground(Color.clear)
|
||||
.listRowInsets(EdgeInsets(top: 4, leading: 16, bottom: 4, trailing: 16))
|
||||
}
|
||||
|
||||
// The explanation is its own sheet now, opened from this
|
||||
// row. Gated exactly like the More info row and the Best
|
||||
// Value card itself: `isConfigured` is the same condition
|
||||
// `savingsForStation` uses, so the row appears and
|
||||
// disappears with the feature.
|
||||
if fuelSavingsSettings.isConfigured {
|
||||
Section {
|
||||
HowBestValueRow { showBestValueInfo = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Key")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Done") { showKey = false }
|
||||
}
|
||||
}
|
||||
// Nested sheet: the Key sheet stays behind the explanation.
|
||||
.sheet(isPresented: $showBestValueInfo) { HowBestValueSheet() }
|
||||
}
|
||||
.presentationDetents([.fraction(0.6)])
|
||||
.presentationBackground(Color(UIColor.systemGroupedBackground))
|
||||
KeySheetView(
|
||||
fuelTint: selectedFuel.tintColor,
|
||||
showBestValueInfo: $showBestValueInfo,
|
||||
showImportantInformation: $showImportantInformation
|
||||
)
|
||||
}
|
||||
|
||||
private func stationRow(_ station: FuelStation) -> some View {
|
||||
@@ -381,45 +420,160 @@ struct StationsView: View {
|
||||
return modes
|
||||
}
|
||||
|
||||
/// One price-rating card for the Key sheet: accent icon, title + blurb,
|
||||
/// and the rating threshold in the accent colour (mirrors the tip cards).
|
||||
private func keyCard(icon: String, color: Color, title: String, blurb: String, threshold: String) -> some View {
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: icon)
|
||||
.font(.title3)
|
||||
.foregroundStyle(color)
|
||||
.frame(width: 34)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(LocalizedStringKey(title)).font(.headline)
|
||||
Text(LocalizedStringKey(blurb))
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
Spacer(minLength: 8)
|
||||
HStack(spacing: 6) {
|
||||
Circle().fill(color).frame(width: 10, height: 10)
|
||||
Text(threshold)
|
||||
.font(.headline.weight(.bold))
|
||||
.foregroundStyle(color)
|
||||
.monospacedDigit()
|
||||
}
|
||||
}
|
||||
|
||||
/// The station list's real RAG dot, paired with the rating name. The range lives
|
||||
/// in the aligned description column rather than as a separate trailing value.
|
||||
private struct KeyPriceRatingIndicator: View {
|
||||
let item: KeySheetContent.Item
|
||||
let color: Color
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 5) {
|
||||
PriceRatingDot(color: color)
|
||||
Text(LocalizedStringKey(item.label))
|
||||
.font(.caption.weight(.semibold))
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
.padding(.horizontal, 14)
|
||||
.padding(.vertical, 10)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.keyCardFill(color: color)
|
||||
}
|
||||
}
|
||||
|
||||
/// Card background shared by the Key sheet cards — subtle accent tint over
|
||||
/// the grouped background, matching the tip-section card style.
|
||||
private extension View {
|
||||
func keyCardFill(color: Color) -> some View {
|
||||
background(
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.fill(Color(.secondarySystemGroupedBackground))
|
||||
.overlay(RoundedRectangle(cornerRadius: 12).fill(color.opacity(0.08)))
|
||||
/// Every Key section shares this one two-column row. The scaled first-column
|
||||
/// width keeps every description on the same leading axis while preserving the
|
||||
/// inline layout at accessibility sizes; descriptions own the flexible column
|
||||
/// and grow vertically without truncating.
|
||||
private struct KeySheetDescriptionRow<Indicator: View>: View {
|
||||
private let indicatorColumnWidth: CGFloat = 128
|
||||
|
||||
let item: KeySheetContent.Item
|
||||
@ViewBuilder let indicator: Indicator
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .top, spacing: 12) {
|
||||
indicator
|
||||
.frame(width: indicatorColumnWidth, alignment: .leading)
|
||||
description
|
||||
}
|
||||
.padding(.vertical, 3)
|
||||
.accessibilityElement(children: .ignore)
|
||||
.accessibilityLabel("\(item.label). \(item.description)")
|
||||
}
|
||||
|
||||
private var description: some View {
|
||||
Text(LocalizedStringKey(item.description))
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
|
||||
/// Uses the same listing capsule component as real station rows, with neutral
|
||||
/// fixture numbers: only the verdict is visible in this compact variant.
|
||||
private struct KeySavingsCapsule: View {
|
||||
let label: String
|
||||
|
||||
private var status: FuelSavingsStatus {
|
||||
switch label {
|
||||
case "Saves": return .worthTheDrive
|
||||
case "Costs more": return .notWorthTheDrive
|
||||
default: return .breakEven
|
||||
}
|
||||
}
|
||||
|
||||
private var result: FuelSavingsResult {
|
||||
let netSaving = status == .worthTheDrive ? 1.0 : (status == .notWorthTheDrive ? -1.0 : 0)
|
||||
return FuelSavingsResult(
|
||||
fillLitres: 30,
|
||||
grossSavingGBP: netSaving,
|
||||
extraDrivingCostGBP: 0,
|
||||
extraDistanceMiles: 0,
|
||||
netSavingGBP: netSaving,
|
||||
status: status,
|
||||
journeyConfidence: .confirmed
|
||||
)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
// The legend demonstrates the wording, not a figure: `result` above is a
|
||||
// placeholder verdict, and its £1.00 must never reach the screen.
|
||||
ListingFuelSavingsCapsule(result: result, showsAmount: false)
|
||||
}
|
||||
}
|
||||
|
||||
/// Shared RAG dot used beside live station prices and in the Key.
|
||||
struct PriceRatingDot: View {
|
||||
let color: Color
|
||||
|
||||
var body: some View {
|
||||
Circle()
|
||||
.fill(color)
|
||||
.frame(width: 8, height: 8)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
|
||||
/// Shared favourite glyph used by station rows and the Key.
|
||||
struct FavouriteStarGlyph: View {
|
||||
let isFavourite: Bool
|
||||
|
||||
var body: some View {
|
||||
Image(systemName: isFavourite ? "star.fill" : "star")
|
||||
.foregroundStyle(isFavourite ? .yellow : .secondary)
|
||||
}
|
||||
}
|
||||
|
||||
/// Shared station-label capsule. `StationRow` uses the same view for its live
|
||||
/// BEST VALUE/CHEAPEST badge, so the Key cannot drift from the listing style.
|
||||
struct StationLabelBadge: View {
|
||||
let label: String
|
||||
let color: Color
|
||||
|
||||
var body: some View {
|
||||
Text(LocalizedStringKey(label))
|
||||
.font(.caption2.bold())
|
||||
.foregroundStyle(color)
|
||||
.padding(.horizontal, 7)
|
||||
.padding(.vertical, 3)
|
||||
.background(Capsule().fill(color.opacity(0.15)))
|
||||
.fixedSize(horizontal: true, vertical: false)
|
||||
}
|
||||
}
|
||||
|
||||
private struct KeyStationLabelIndicator: View {
|
||||
let label: String
|
||||
let fuelColor: Color
|
||||
|
||||
var body: some View {
|
||||
switch label {
|
||||
case "BEST VALUE":
|
||||
StationLabelBadge(label: label, color: .green)
|
||||
case "CHEAPEST":
|
||||
StationLabelBadge(label: label, color: .blue)
|
||||
case "CLOSEST":
|
||||
// The listing's own capsule, so the Key demonstrates the same soft
|
||||
// blue fill and white text the listing shows. `FuelSavingsCapsule`
|
||||
// remains the detail sheet's alone.
|
||||
ListingFuelSavingsCapsule(result: baselineResult)
|
||||
default:
|
||||
Text("TOP")
|
||||
.font(.caption2.bold())
|
||||
.padding(.horizontal, 4)
|
||||
.padding(.vertical, 2)
|
||||
.background(fuelColor.opacity(0.18), in: Capsule())
|
||||
.fixedSize(horizontal: true, vertical: false)
|
||||
}
|
||||
}
|
||||
|
||||
private var baselineResult: FuelSavingsResult {
|
||||
FuelSavingsResult(
|
||||
fillLitres: 30,
|
||||
grossSavingGBP: 0,
|
||||
extraDrivingCostGBP: 0,
|
||||
extraDistanceMiles: 0,
|
||||
netSavingGBP: 0,
|
||||
status: .baseline,
|
||||
journeyConfidence: .confirmed
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,32 @@
|
||||
"Show %lld more (%lld remaining)" = "Show %lld more (%lld remaining)";
|
||||
"All %lld stations shown" = "All %lld stations shown";
|
||||
"Key" = "Key";
|
||||
"Price ratings" = "Price ratings";
|
||||
"Good price" = "Good price";
|
||||
"Within 1.5p of the cheapest" = "Within 1.5p of the cheapest";
|
||||
"Within 1.5p/L of the cheapest." = "Within 1.5p/L of the cheapest.";
|
||||
"Okay" = "Okay";
|
||||
"More than 1.5p, up to 4p above the cheapest" = "More than 1.5p, up to 4p above the cheapest";
|
||||
"More than 1.5p/L, up to 4p/L above the cheapest." = "More than 1.5p/L, up to 4p/L above the cheapest.";
|
||||
"Pricey" = "Pricey";
|
||||
"More than 4p above the cheapest" = "More than 4p above the cheapest";
|
||||
"Top result for the current sort" = "Top result for the current sort";
|
||||
"Star a station to add it to Favourites" = "Star a station to add it to Favourites";
|
||||
"More than 4p/L above the cheapest." = "More than 4p/L above the cheapest.";
|
||||
"Savings" = "Savings";
|
||||
"Saves" = "Saves";
|
||||
"You’ll save money compared with your closest station, including travel costs." = "You’ll save money compared with your closest station, including travel costs.";
|
||||
"Break even" = "Break even";
|
||||
"The saving or extra cost is negligible." = "The saving or extra cost is negligible.";
|
||||
"Costs more" = "Costs more";
|
||||
"Filling up here costs more than at your closest station, including travel." = "Filling up here costs more than at your closest station, including travel.";
|
||||
/* Station listing verdict capsule: the words above the figure */
|
||||
"Costs" = "Costs";
|
||||
"(approx.)" = "(approx.)";
|
||||
"%@ more" = "%@ more";
|
||||
"Station labels" = "Station labels";
|
||||
"CLOSEST" = "CLOSEST";
|
||||
"Meets your minimum saving after travel costs." = "Meets your minimum saving after travel costs.";
|
||||
"The lowest fuel price per litre within your selected range." = "The lowest fuel price per litre within your selected range.";
|
||||
"The nearest station by journey distance." = "The nearest station by journey distance.";
|
||||
"The cheapest station in your Favourites for the selected fuel." = "The cheapest station in your Favourites for the selected fuel.";
|
||||
"Star a station to save it to your Favourites." = "Star a station to save it to your Favourites.";
|
||||
"How does Best Value work?" = "How does Best Value work?";
|
||||
/* Star button in the More info sheet heading (accessibility labels) */
|
||||
"Add to favourites" = "Add to favourites";
|
||||
"Remove from favourites" = "Remove from favourites";
|
||||
@@ -41,7 +59,7 @@
|
||||
"Best Value compares each station with the closest station by journey distance. It works out what you could save at the pump, then takes off the fuel used for the extra return journey." = "Best Value compares each station with the closest station by journey distance. It works out what you could save at the pump, then takes off the fuel used for the extra return journey.";
|
||||
"With a £ budget you spend that amount at each station; the litres differ by station. Savings compare those litres with the same quantity at your closest station, then deduct extra journey fuel. You do not receive cash back." = "With a £ budget you spend that amount at each station; the litres differ by station. Savings compare those litres with the same quantity at your closest station, then deduct extra journey fuel. You do not receive cash back.";
|
||||
"Your closest station by journey distance is the baseline — every other saving is measured against it." = "Your closest station by journey distance is the baseline — every other saving is measured against it.";
|
||||
"Savings below are estimated against the closest station by journey distance — the same baseline as the Stations list." = "Savings below are estimated against the closest station by journey distance — the same baseline as the Stations list.";
|
||||
"Price colours show pump price competitiveness. Savings compare with your closest station, including journey costs." = "Price colours show pump price competitiveness. Savings compare with your closest station, including journey costs.";
|
||||
"Your fill-up amount and MPG are used to show whether you could save overall." = "Your fill-up amount and MPG are used to show whether you could save overall.";
|
||||
"Results are marked “Approx.” until road distances are available." = "Results are marked “Approx.” until road distances are available.";
|
||||
|
||||
@@ -58,11 +76,9 @@
|
||||
"Radius" = "Radius";
|
||||
"%lld %@" = "%lld %@";
|
||||
"Follow search (%@)" = "Follow search (%@)";
|
||||
"When you approach a station that is the cheapest within the radius, FuelBoard sends a notification — even with the app closed. Nearby stations selling %@ are watched — favourites get priority — and each station alerts at most once per hour. Follow search mirrors the Stations-tab distance, capped at 8 miles for reliable geofencing." = "When you approach a station that is the cheapest within the radius, FuelBoard sends a notification — even with the app closed. Nearby stations selling %@ are watched — favourites get priority — and each station alerts at most once per hour. Follow search mirrors the Stations-tab distance, capped at 8 miles for reliable geofencing.";
|
||||
"No stations monitored yet — open the Stations tab to load prices first." = "No stations monitored yet — open the Stations tab to load prices first.";
|
||||
"Last alert" = "Last alert";
|
||||
"Live Activity" = "Live Activity";
|
||||
"Shows the cheapest station for the fuel and distance you pick here on the Lock Screen and Dynamic Island — independent of the Stations tab (choose Follow search to mirror its distance instead). Updates as you drive; tap to open directions. Live Activities can be disabled in System Settings → Live Activities." = "Shows the cheapest station for the fuel and distance you pick here on the Lock Screen and Dynamic Island — independent of the Stations tab (choose Follow search to mirror its distance instead). Updates as you drive; tap to open directions. Live Activities can be disabled in System Settings → Live Activities.";
|
||||
|
||||
/* Settings tab */
|
||||
"Units" = "Units";
|
||||
@@ -214,8 +230,6 @@
|
||||
/* Alerts and favourites localisation pass */
|
||||
"Cheapest favourite" = "Cheapest favourite";
|
||||
"Check now" = "Check now";
|
||||
"Price-drop alerts" = "Price-drop alerts";
|
||||
"Watches your cheapest saved favourite for the fuel you pick here. FuelBoard alerts when a different favourite becomes the cheapest, or when your current cheapest favourite drops by at least 1.0p. This is separate from the nearby-geofence alert, so you can monitor favourites without extra location noise." = "Watches your cheapest saved favourite for the fuel you pick here. FuelBoard alerts when a different favourite becomes the cheapest, or when your current cheapest favourite drops by at least 1.0p. This is separate from the nearby-geofence alert, so you can monitor favourites without extra location noise.";
|
||||
"Cheapest station" = "Cheapest station";
|
||||
"Alert type" = "Alert type";
|
||||
"Best Value" = "Best Value";
|
||||
@@ -224,19 +238,15 @@
|
||||
"Minimum saving %@ — change in Settings, Fuel Savings." = "Minimum saving %@ — change in Settings, Fuel Savings.";
|
||||
"Set up Best Value first so FuelBoard can account for your fill size, MPG and travel cost." = "Set up Best Value first so FuelBoard can account for your fill size, MPG and travel cost.";
|
||||
"Set up Best Value first so Best Value alerts can account for your fill size, MPG and travel cost." = "Set up Best Value first so Best Value alerts can account for your fill size, MPG and travel cost.";
|
||||
"When you approach the Best Value station within the radius, FuelBoard sends a notification if it could leave you at least %@ better off after extra return travel. Nearby stations selling %@ are watched — favourites get priority — and each station alerts at most once per hour." = "When you approach the Best Value station within the radius, FuelBoard sends a notification if it could leave you at least %@ better off after extra return travel. Nearby stations selling %@ are watched — favourites get priority — and each station alerts at most once per hour.";
|
||||
"Proximity alerts" = "Proximity alerts";
|
||||
"When you approach a station that is the cheapest within the radius, FuelBoard sends a notification — even with the app closed. Nearby stations selling %@ are watched — favourites get priority — and each station alerts at most once per hour. Follow search mirrors the Stations-tab distance, capped at 8 miles for reliable geofencing. Smaller radii ping more often but later; larger radii ping rarely in town but earlier from afar." = "When you approach a station that is the cheapest within the radius, FuelBoard sends a notification — even with the app closed. Nearby stations selling %@ are watched — favourites get priority — and each station alerts at most once per hour. Follow search mirrors the Stations-tab distance, capped at 8 miles for reliable geofencing. Smaller radii ping more often but later; larger radii ping rarely in town but earlier from afar.";
|
||||
"Set-and-forget: alerts behave exactly like the Stations-tab search distance (capped at 8 miles for reliable geofencing)." = "Set-and-forget: alerts behave exactly like the Stations-tab search distance (capped at 8 miles for reliable geofencing).";
|
||||
"Town driving. Fires most often — you're rarely inside the circle for long, so pings are meaningful. Best for stop-start local trips." = "Town driving. Fires most often — you're rarely inside the circle for long, so pings are meaningful. Best for stop-start local trips.";
|
||||
"City or suburb commute. Slightly earlier heads-up than the smallest option; still fires regularly around town." = "City or suburb commute. Slightly earlier heads-up than the smallest option; still fires regularly around town.";
|
||||
"Mixed driving. Middle ground: heads-up a few minutes out, still works in most towns." = "Mixed driving. Middle ground: heads-up a few minutes out, still works in most towns.";
|
||||
"A-roads and motorway exits. Wide early warning for longer trips — but in town it rarely fires, because you're usually already inside the circle." = "A-roads and motorway exits. Wide early warning for longer trips — but in town it rarely fires, because you're usually already inside the circle.";
|
||||
"Long-distance journeys. Maximum reach: a ping when a cheap station is coming up from far out. In town this essentially never fires." = "Long-distance journeys. Maximum reach: a ping when a cheap station is coming up from far out. In town this essentially never fires.";
|
||||
"%@ — %@" = "%@ — %@";
|
||||
|
||||
/* Best Value calculation and station price age */
|
||||
"£ compares the litres your budget buys at each station; Litres compares one fixed quantity." = "£ compares the litres your budget buys at each station; Litres compares one fixed quantity.";
|
||||
"How much fuel?" = "How much fuel?";
|
||||
"Adjust your fill-up amount for this visit. Your default won’t change." = "Adjust your fill-up amount for this visit. Your default won’t change.";
|
||||
"About comparison modes" = "About comparison modes";
|
||||
"Comparison modes" = "Comparison modes";
|
||||
"£: Compare how much fuel your budget buys at each station." = "£: Compare how much fuel your budget buys at each station.";
|
||||
"Litres: Compare the cost of buying the same amount of fuel." = "Litres: Compare the cost of buying the same amount of fuel.";
|
||||
"You pay the selected budget here. The saving compares the same litres at your closest station; litres differ between stations, and this is not a refund." = "You pay the selected budget here. The saving compares the same litres at your closest station; litres differ between stations, and this is not a refund.";
|
||||
"Best Value unavailable · location needed" = "Best Value unavailable · location needed";
|
||||
"your order" = "your order";
|
||||
@@ -246,3 +256,34 @@
|
||||
"May be outdated" = "May be outdated";
|
||||
"Fuel you'll receive" = "Fuel you'll receive";
|
||||
"Compared with your closest station." = "Compared with your closest station.";
|
||||
|
||||
/* Alerts tab — refined copy (sections, descriptions, limitations) */
|
||||
"Favourite price alerts" = "Favourite price alerts";
|
||||
"Get notified when a different favourite becomes the cheapest, or your cheapest favourite drops in price." = "Get notified when a different favourite becomes the cheapest, or your cheapest favourite drops in price.";
|
||||
"Get notified when you're near one of the cheapest stations for your chosen fuel." = "Get notified when you're near one of the cheapest stations for your chosen fuel.";
|
||||
"Get notified when you're near a station that could save you money after travel costs." = "Get notified when you're near a station that could save you money after travel costs.";
|
||||
"Get alerts when you're within %@ of a matching station." = "Get alerts when you're within %@ of a matching station.";
|
||||
"Get alerts when you're within %@ of a matching station (your search distance is capped for reliable alerts)." = "Get alerts when you're within %@ of a matching station (your search distance is capped for reliable alerts).";
|
||||
"Uses the same distance as your station search." = "Uses the same distance as your station search.";
|
||||
"See the cheapest nearby station on your Lock Screen and Dynamic Island, with updates as you travel." = "See the cheapest nearby station on your Lock Screen and Dynamic Island, with updates as you travel.";
|
||||
"Background alerts depend on when your iPhone allows them; each station alerts at most once an hour." = "Background alerts depend on when your iPhone allows them; each station alerts at most once an hour.";
|
||||
|
||||
/* Important information — the shared disclaimer sheet (one card per heading) */
|
||||
"Important information" = "Important information";
|
||||
"Fuel Prices" = "Fuel Prices";
|
||||
"FuelBoard uses fuel price information published through the UK Government's fuel price data scheme. Prices are supplied by retailers and may change or differ from those displayed in the app." = "FuelBoard uses fuel price information published through the UK Government's fuel price data scheme. Prices are supplied by retailers and may change or differ from those displayed in the app.";
|
||||
"While we aim to provide accurate, up-to-date information, we cannot guarantee that displayed prices reflect those currently available at the pump." = "While we aim to provide accurate, up-to-date information, we cannot guarantee that displayed prices reflect those currently available at the pump.";
|
||||
"Fuel Availability" = "Fuel Availability";
|
||||
"A displayed fuel price does not guarantee availability. Stations may temporarily run out of fuel, have pumps out of service, be closed or no longer offer a particular fuel type." = "A displayed fuel price does not guarantee availability. Stations may temporarily run out of fuel, have pumps out of service, be closed or no longer offer a particular fuel type.";
|
||||
"We recommend checking availability before making a special journey." = "We recommend checking availability before making a special journey.";
|
||||
"Savings & Best Value" = "Savings & Best Value";
|
||||
"Savings and Best Value recommendations are estimates based on available fuel prices, your selected fill-up amount, estimated travel costs and other relevant settings." = "Savings and Best Value recommendations are estimates based on available fuel prices, your selected fill-up amount, estimated travel costs and other relevant settings.";
|
||||
"Actual savings may vary depending on fuel consumption, driving conditions, routes and current pump prices. A Best Value recommendation does not guarantee the lowest overall cost." = "Actual savings may vary depending on fuel consumption, driving conditions, routes and current pump prices. A Best Value recommendation does not guarantee the lowest overall cost.";
|
||||
"Journey Estimates" = "Journey Estimates";
|
||||
"Travel distances, journey times and associated fuel costs are estimates. Where actual road distances are unavailable, approximate distances may be used." = "Travel distances, journey times and associated fuel costs are estimates. Where actual road distances are unavailable, approximate distances may be used.";
|
||||
"Actual journeys may differ due to traffic, road conditions, diversions and individual driving habits." = "Actual journeys may differ due to traffic, road conditions, diversions and individual driving habits.";
|
||||
"Before You Travel" = "Before You Travel";
|
||||
"Fuel prices and availability can change without notice. Always check the current price and fuel availability before making a special journey or filling up." = "Fuel prices and availability can change without notice. Always check the current price and fuel availability before making a special journey or filling up.";
|
||||
"Disclaimer" = "Disclaimer";
|
||||
"FuelBoard provides information to help you compare fuel prices and make informed decisions. We cannot guarantee the accuracy, completeness or availability of fuel price information, savings estimates or recommendations." = "FuelBoard provides information to help you compare fuel prices and make informed decisions. We cannot guarantee the accuracy, completeness or availability of fuel price information, savings estimates or recommendations.";
|
||||
"FuelBoard accepts no responsibility for additional travel costs, financial losses or decisions made using the information provided." = "FuelBoard accepts no responsibility for additional travel costs, financial losses or decisions made using the information provided.";
|
||||
|
||||
@@ -18,6 +18,70 @@ final class FuelSavingsEstimateTests: XCTestCase {
|
||||
)
|
||||
private let amount = FuelSavingsFillAmount(value: 40, unit: .pounds)
|
||||
|
||||
func testListingCapsulePutsTheFigureOnItsOwnLine() {
|
||||
func result(_ status: FuelSavingsStatus, _ confidence: JourneyConfidence) -> FuelSavingsResult {
|
||||
FuelSavingsResult(
|
||||
fillLitres: 30,
|
||||
grossSavingGBP: status == .notWorthTheDrive ? 0 : 12.50,
|
||||
extraDrivingCostGBP: status == .notWorthTheDrive ? 123.45 : 0,
|
||||
extraDistanceMiles: 2,
|
||||
netSavingGBP: status == .notWorthTheDrive ? -123.45 : 12.50,
|
||||
status: status,
|
||||
journeyConfidence: confidence
|
||||
)
|
||||
}
|
||||
|
||||
// The figure takes its own line, so the capsule's shape is decided by the
|
||||
// data rather than by how much width the price column hands it.
|
||||
XCTAssertEqual(result(.worthTheDrive, .confirmed).listingVerdict().lines,
|
||||
["Saves", "£12.50"])
|
||||
XCTAssertEqual(result(.worthTheDrive, .estimated).listingVerdict().lines,
|
||||
["Saves", "£12.50", "(approx.)"])
|
||||
XCTAssertEqual(result(.notWorthTheDrive, .confirmed).listingVerdict().lines,
|
||||
["Costs", "£123.45 more"])
|
||||
XCTAssertEqual(result(.notWorthTheDrive, .estimated).listingVerdict().lines,
|
||||
["Costs", "£123.45 more", "(approx.)"])
|
||||
|
||||
// Break even carries no figure — ±£0.05 is noise — so it stays one line
|
||||
// when confirmed and gains a second only for the estimate qualifier.
|
||||
XCTAssertEqual(result(.breakEven, .confirmed).listingVerdict().lines, ["Break even"])
|
||||
XCTAssertEqual(result(.breakEven, .estimated).listingVerdict().lines,
|
||||
["Break even", "(approx.)"])
|
||||
XCTAssertEqual(result(.baseline, .confirmed).listingVerdict().lines, ["Closest station"])
|
||||
|
||||
// The Key sheet's legend demonstrates the wording, never a figure.
|
||||
XCTAssertEqual(
|
||||
result(.notWorthTheDrive, .confirmed).listingVerdict(showsAmount: false).lines,
|
||||
["Costs"]
|
||||
)
|
||||
|
||||
// VoiceOver keeps a single line: a drawn break is a spoken pause.
|
||||
XCTAssertEqual(result(.worthTheDrive, .estimated).listingCapsuleHeadline(),
|
||||
"Saves £12.50 (approx.)")
|
||||
}
|
||||
|
||||
func testDetailCapsulePlacesApproximationAfterTheFinancialResult() {
|
||||
func result(_ status: FuelSavingsStatus, _ confidence: JourneyConfidence) -> FuelSavingsResult {
|
||||
FuelSavingsResult(
|
||||
fillLitres: 30,
|
||||
grossSavingGBP: status == .notWorthTheDrive ? 0 : 2.50,
|
||||
extraDrivingCostGBP: status == .notWorthTheDrive ? 1.20 : 0,
|
||||
extraDistanceMiles: 2,
|
||||
netSavingGBP: status == .notWorthTheDrive ? -1.20 : 2.50,
|
||||
status: status,
|
||||
journeyConfidence: confidence
|
||||
)
|
||||
}
|
||||
|
||||
XCTAssertEqual(result(.worthTheDrive, .estimated).detailCapsuleHeadline(), "Save £2.50 (approx.)")
|
||||
XCTAssertEqual(result(.notWorthTheDrive, .estimated).detailCapsuleHeadline(), "Costs £1.20 more (approx.)")
|
||||
XCTAssertEqual(result(.breakEven, .estimated).detailCapsuleHeadline(), "Break even (approx.)")
|
||||
XCTAssertEqual(result(.worthTheDrive, .confirmed).detailCapsuleHeadline(), "Save £2.50")
|
||||
XCTAssertEqual(result(.notWorthTheDrive, .confirmed).detailCapsuleHeadline(), "Costs £1.20 more")
|
||||
XCTAssertEqual(result(.breakEven, .confirmed).detailCapsuleHeadline(), "Break even")
|
||||
XCTAssertEqual(result(.worthTheDrive, .estimated).detailCapsuleSpokenHeadline(), "Save £2.50 (approximately)")
|
||||
}
|
||||
|
||||
private func station(_ id: String,
|
||||
price: Double?,
|
||||
lat: Double = 51.5,
|
||||
|
||||
@@ -257,3 +257,39 @@ final class StationRecommendationBadgeTests: XCTestCase {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
final class KeySheetContentTests: XCTestCase {
|
||||
func testPriceRatingsExplainTheImplementedRAGBoundaries() {
|
||||
XCTAssertEqual(KeySheetContent.priceRatings, [
|
||||
.init(label: "Good price", description: "Within 1.5p/L of the cheapest."),
|
||||
.init(label: "Okay", description: "More than 1.5p/L, up to 4p/L above the cheapest."),
|
||||
.init(label: "Pricey", description: "More than 4p/L above the cheapest.")
|
||||
])
|
||||
}
|
||||
|
||||
func testSavingsExplainVerdictsWithoutImplyingMinimumSavingQualification() {
|
||||
XCTAssertEqual(KeySheetContent.savings, [
|
||||
.init(label: "Saves", description: "You’ll save money compared with your closest station, including travel costs."),
|
||||
.init(label: "Break even", description: "The saving or extra cost is negligible."),
|
||||
.init(label: "Costs more", description: "Filling up here costs more than at your closest station, including travel.")
|
||||
])
|
||||
XCTAssertFalse(KeySheetContent.savings.contains { $0.label == "Small saving" })
|
||||
}
|
||||
|
||||
func testStationLabelsDescribeTheCurrentQualificationAndRangeRules() {
|
||||
XCTAssertEqual(KeySheetContent.stationLabels, [
|
||||
.init(label: "BEST VALUE", description: "Meets your minimum saving after travel costs."),
|
||||
.init(label: "CHEAPEST", description: "The lowest fuel price per litre within your selected range."),
|
||||
.init(label: "CLOSEST", description: "The nearest station by journey distance."),
|
||||
.init(label: "TOP", description: "The cheapest station in your Favourites for the selected fuel.")
|
||||
])
|
||||
}
|
||||
|
||||
func testFavouriteAndHelpCopyRemainPinned() {
|
||||
XCTAssertEqual(
|
||||
KeySheetContent.favourite,
|
||||
.init(label: "Favourites", description: "Star a station to save it to your Favourites.")
|
||||
)
|
||||
XCTAssertEqual(KeySheetContent.helpTitle, "How does Best Value work?")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,3 +31,12 @@ final class FuelStoreBestValueThresholdTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class FuelStoreAlertModeTests: XCTestCase {
|
||||
func testLegacyBestValueSelectionLoadsAsCheapest() {
|
||||
FuelStore.saveAlertsMode(.bestValue)
|
||||
defer { FuelStore.saveAlertsMode(.cheapest) }
|
||||
|
||||
XCTAssertEqual(FuelStore.loadAlertsMode(), .cheapest)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,12 +236,100 @@ extension FuelSavingsResult {
|
||||
headline().replacingOccurrences(of: "Approx. ", with: "Approximately ")
|
||||
}
|
||||
|
||||
/// Full monetary verdict used by Station Details. Estimated confidence is a
|
||||
/// trailing qualifier so the amount remains the first figure users scan.
|
||||
func detailCapsuleHeadline() -> String {
|
||||
let qualifier = journeyConfidence.isEstimated ? " (approx.)" : ""
|
||||
switch status {
|
||||
case .baseline:
|
||||
return Self.baselineHeadline
|
||||
case .breakEven:
|
||||
return "\(Self.breakEvenHeadline)\(qualifier)"
|
||||
case .worthTheDrive:
|
||||
return "Save \(FuelSavingsFormat.money(netSavingGBP))\(qualifier)"
|
||||
case .notWorthTheDrive:
|
||||
return "Costs \(FuelSavingsFormat.money(abs(netSavingGBP))) more\(qualifier)"
|
||||
}
|
||||
}
|
||||
|
||||
func detailCapsuleSpokenHeadline() -> String {
|
||||
detailCapsuleHeadline().replacingOccurrences(of: "(approx.)", with: "(approximately)")
|
||||
}
|
||||
|
||||
/// Row capsule copy. The baseline relationship is shown as secondary text
|
||||
/// beside the capsule in the station listing and detail summary, so the
|
||||
/// capsule itself contains only the verdict.
|
||||
func capsuleHeadline() -> String {
|
||||
headline(compact: true)
|
||||
}
|
||||
|
||||
/// The station-listing capsule's verdict, split into the lines the capsule
|
||||
/// draws.
|
||||
///
|
||||
/// The amount always takes its OWN line, so where the capsule breaks is
|
||||
/// decided by the data, never by the width it was handed: the figure can
|
||||
/// never straddle two lines, and a taller verdict grows the capsule downward
|
||||
/// instead of widening the row's fixed price column.
|
||||
struct ListingVerdict: Equatable {
|
||||
/// "Saves", "Costs", "Break even" or "Closest station".
|
||||
let headline: String
|
||||
/// "£3.10" / "£1.20 more" — nil when there is no figure to show.
|
||||
let amount: String?
|
||||
/// "(approx.)" when the journey behind the figure was estimated.
|
||||
let qualifier: String?
|
||||
|
||||
var lines: [String] { [headline, amount, qualifier].compactMap { $0 } }
|
||||
|
||||
/// Single-line form, for VoiceOver and tests. A drawn newline is a pause
|
||||
/// in the middle of a phrase when spoken.
|
||||
var spokenText: String { lines.joined(separator: " ") }
|
||||
}
|
||||
|
||||
/// Verdict for the station listing rows — Stations and Favourites share one
|
||||
/// row, so they share this. `showsAmount: false` is the Key sheet's legend,
|
||||
/// which demonstrates the wording without inventing a figure.
|
||||
func listingVerdict(showsAmount: Bool = true) -> ListingVerdict {
|
||||
let qualifier = journeyConfidence.isEstimated ? String(localized: "(approx.)") : nil
|
||||
switch status {
|
||||
case .worthTheDrive:
|
||||
return ListingVerdict(
|
||||
headline: String(localized: "Saves"),
|
||||
amount: showsAmount ? FuelSavingsFormat.money(netSavingGBP) : nil,
|
||||
qualifier: qualifier
|
||||
)
|
||||
case .notWorthTheDrive:
|
||||
return ListingVerdict(
|
||||
headline: String(localized: "Costs"),
|
||||
amount: showsAmount ? Self.amountWithMore(abs(netSavingGBP)) : nil,
|
||||
qualifier: qualifier
|
||||
)
|
||||
case .breakEven:
|
||||
// No figure: ±£0.05 is noise, so this stays a single line unless the
|
||||
// estimate qualifier adds its own.
|
||||
return ListingVerdict(
|
||||
headline: String(localized: "Break even"),
|
||||
amount: nil,
|
||||
qualifier: qualifier
|
||||
)
|
||||
case .baseline:
|
||||
return ListingVerdict(
|
||||
headline: Self.baselineHeadline,
|
||||
amount: nil,
|
||||
qualifier: nil
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// "£1.20 more" — kept as a format string so the copy editor owns the word.
|
||||
private static func amountWithMore(_ value: Double) -> String {
|
||||
String(format: String(localized: "%@ more"), FuelSavingsFormat.money(value))
|
||||
}
|
||||
|
||||
/// One-line verdict for voice and tests; the capsule itself renders
|
||||
/// `listingVerdict()`'s lines separately.
|
||||
func listingCapsuleHeadline() -> String {
|
||||
listingVerdict().spokenText
|
||||
}
|
||||
}
|
||||
|
||||
/// One station's journey distance, plus how it was obtained.
|
||||
@@ -276,6 +364,42 @@ struct FuelSavingsRankedStation: Equatable {
|
||||
let pricePencePerLitre: Double
|
||||
}
|
||||
|
||||
/// The user-facing copy shown by the Stations tab's Key sheet. Keeping the
|
||||
/// descriptions in one Foundation-only model lets tests pin the exact meaning of
|
||||
/// each visual indicator without coupling the wording to SwiftUI layout.
|
||||
enum KeySheetContent {
|
||||
struct Item: Equatable {
|
||||
let label: String
|
||||
let description: String
|
||||
}
|
||||
|
||||
static let priceRatings = [
|
||||
Item(label: "Good price", description: "Within 1.5p/L of the cheapest."),
|
||||
Item(label: "Okay", description: "More than 1.5p/L, up to 4p/L above the cheapest."),
|
||||
Item(label: "Pricey", description: "More than 4p/L above the cheapest.")
|
||||
]
|
||||
|
||||
static let savings = [
|
||||
Item(label: "Saves", description: "You’ll save money compared with your closest station, including travel costs."),
|
||||
Item(label: "Break even", description: "The saving or extra cost is negligible."),
|
||||
Item(label: "Costs more", description: "Filling up here costs more than at your closest station, including travel.")
|
||||
]
|
||||
|
||||
static let stationLabels = [
|
||||
Item(label: "BEST VALUE", description: "Meets your minimum saving after travel costs."),
|
||||
Item(label: "CHEAPEST", description: "The lowest fuel price per litre within your selected range."),
|
||||
Item(label: "CLOSEST", description: "The nearest station by journey distance."),
|
||||
Item(label: "TOP", description: "The cheapest station in your Favourites for the selected fuel.")
|
||||
]
|
||||
|
||||
static let favourite = Item(
|
||||
label: "Favourites",
|
||||
description: "Star a station to save it to your Favourites."
|
||||
)
|
||||
|
||||
static let helpTitle = "How does Best Value work?"
|
||||
}
|
||||
|
||||
/// Which recommendation badge a station listing row shows, if any.
|
||||
///
|
||||
/// Presentation only — no new rules: the BEST VALUE qualification reuses the
|
||||
|
||||
@@ -701,10 +701,12 @@ struct FuelStore {
|
||||
}
|
||||
|
||||
static func loadAlertsMode() -> AlertMode {
|
||||
if let raw = loadString(service: alertsModeKey), let mode = AlertMode(rawValue: raw) {
|
||||
return mode
|
||||
guard let raw = loadString(service: alertsModeKey),
|
||||
let mode = AlertMode(rawValue: raw),
|
||||
mode == .cheapest else {
|
||||
return .cheapest
|
||||
}
|
||||
return .cheapest
|
||||
return mode
|
||||
}
|
||||
|
||||
static func saveAlertsMode(_ mode: AlertMode) {
|
||||
|
||||
Reference in New Issue
Block a user