diff --git a/FuelBoard/FavouritesView.swift b/FuelBoard/FavouritesView.swift index f1ddd58..03e7551 100644 --- a/FuelBoard/FavouritesView.swift +++ b/FuelBoard/FavouritesView.swift @@ -21,8 +21,8 @@ struct FavouritesView: View { /// still never touches the Settings default. let fuelSavingsSettings: FuelSavingsSettings @Binding var fuelSavingsAmount: FuelSavingsFillAmount - /// Estimated saving for a favourite, against the nearest eligible station — - /// the same baseline and definition the Stations list uses. + /// Estimated saving for a favourite, against the closest eligible station by + /// journey distance — the same baseline and definition the Stations list uses. var savingsForStation: (FuelStation) -> FuelSavingsAvailability? = { _ in nil } var journeyDiagnosticsForStation: (FuelStation) -> FuelSavingsJourneyDiagnostics? = { _ in nil } var onToggleFavourite: (FuelStation, FuelType) -> Void = { _, _ in } @@ -149,7 +149,7 @@ struct FavouritesView: View { referencePricePencePerLitre: cheapestPrice ) } footer: { - Text(String(localized: "Savings below are estimated against the nearest station with a price for this fuel — the same baseline as the Stations list.", comment: "Favourites fuel-savings explanation")) + Text(String(localized: "Savings below are estimated against the closest eligible station by journey distance — the same baseline as the Stations list.", comment: "Favourites fuel-savings explanation")) } } diff --git a/FuelBoard/FuelSavingsViews.swift b/FuelBoard/FuelSavingsViews.swift index a9f1318..077021c 100644 --- a/FuelBoard/FuelSavingsViews.swift +++ b/FuelBoard/FuelSavingsViews.swift @@ -104,7 +104,6 @@ struct FuelSavingsSummaryView: View { .font(.caption2) .foregroundStyle(.secondary) .lineLimit(1) - .minimumScaleFactor(0.75) .layoutPriority(1) .accessibilityLabel("Comparison: \(comparisonLabel(for: result))") } @@ -131,8 +130,16 @@ struct FuelSavingsSummaryView: View { // room for. The old shape led with a status word + headline that // matched neither the listing nor each other. VStack(alignment: .leading, spacing: 10) { - capsule(for: result, compact: false) - .accessibilityLabel(accessibilityHeadline(for: result)) + HStack(alignment: .firstTextBaseline, spacing: 6) { + capsule(for: result, compact: false) + .accessibilityLabel(accessibilityHeadline(for: result)) + Text(comparisonLabel(for: result)) + .font(.subheadline) + .foregroundStyle(.secondary) + .lineLimit(1) + .layoutPriority(1) + .accessibilityLabel("Comparison: \(comparisonLabel(for: result))") + } LabeledContent("Your fill-up", value: amountText) LabeledContent("Fuel you'll receive", value: String(format: "%.2f litres", result.fillLitres)) .monospacedDigit() @@ -147,11 +154,11 @@ struct FuelSavingsSummaryView: View { .accessibilityLabel(spokenExtraTravel(for: result, fallback: extraTravel)) } if result.status == .baseline { - Text("Your closest station with a price for this fuel — every other saving is measured against it.") + Text("Your closest eligible station by journey distance is the baseline — every other saving is measured against it.") .font(.caption) .foregroundStyle(.secondary) } else { - Text("Compared with \(baselineStationName ?? "your nearest station").") + Text("Compared with \(baselineStationName ?? "your closest station").") .font(.caption) .foregroundStyle(.secondary) LabeledContent( @@ -247,7 +254,6 @@ struct FuelSavingsSummaryView: View { .accessibilityHidden(true) Text(result.capsuleHeadline()) .lineLimit(1) - .minimumScaleFactor(0.8) } .font(compact ? .caption.weight(.semibold) : .headline) .foregroundStyle(capsuleColor(for: result.status)) diff --git a/FuelBoard/HowBestValueSheet.swift b/FuelBoard/HowBestValueSheet.swift index 644f178..283e30b 100644 --- a/FuelBoard/HowBestValueSheet.swift +++ b/FuelBoard/HowBestValueSheet.swift @@ -14,7 +14,7 @@ struct HowBestValueSheet: View { List { Section { VStack(alignment: .leading, spacing: 10) { - Text("Best Value compares each station with the closest one. It works out what you could save at the pump, then takes off the fuel used for the extra return journey.") + Text("Best Value compares each station with the closest eligible 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.") Text("Your fill-up amount and MPG are used to show whether you could save overall.") Text("Results are marked “Approx.” until road distances are available.") .foregroundStyle(.secondary) diff --git a/FuelBoard/OnboardingView.swift b/FuelBoard/OnboardingView.swift index ae9ed39..67fbe27 100644 --- a/FuelBoard/OnboardingView.swift +++ b/FuelBoard/OnboardingView.swift @@ -156,7 +156,7 @@ struct OnboardingView: View { permissionStatusLabel( granted: prompter.locationGranted, denied: prompter.locationDenied, - deniedText: String(localized: "Location was denied. You can still browse all stations, but \"nearest\" sorting needs it.", comment: "Onboarding location denied text") + deniedText: String(localized: "Location was denied. You can still browse all stations, but \"closest\" sorting needs it.", comment: "Onboarding location denied text") ) .padding(.top, 24) diff --git a/FuelBoard/SettingsView.swift b/FuelBoard/SettingsView.swift index 08d4492..a508a4f 100644 --- a/FuelBoard/SettingsView.swift +++ b/FuelBoard/SettingsView.swift @@ -285,7 +285,7 @@ struct SettingsView: View { } header: { Text("Debug") } footer: { - Text("The first button applies the real criteria — cheapest \(alertsFuel.displayName.lowercased()) station within \(distanceUnit.format(alertsRadiusKM)) of you — and sends the actual station's name, price and coordinates. The second fires with no criteria at all (nearest seller), still carrying a real station, just to verify a notification appears and tapping it opens directions. Cheapest in range mirrors the app list (selected fuel + distance); the in-range count mirrors the alert radius.") + Text("The first button applies the real criteria — cheapest \(alertsFuel.displayName.lowercased()) station within \(distanceUnit.format(alertsRadiusKM)) of you — and sends the actual station's name, price and coordinates. The second fires with no criteria at all (closest seller), still carrying a real station, just to verify a notification appears and tapping it opens directions. Cheapest in range mirrors the app list (selected fuel + distance); the in-range count mirrors the alert radius.") } .onAppear { onRefreshDebugStatus() } diff --git a/FuelBoard/StationsView.swift b/FuelBoard/StationsView.swift index b44b3a3..df7b604 100644 --- a/FuelBoard/StationsView.swift +++ b/FuelBoard/StationsView.swift @@ -67,7 +67,7 @@ struct StationsView: View { } if location != nil { if sortMode == .closest { - return "\(mode) \(fuel) stations — nearest first, best value within \(miles) \(unit) · \(ratio) stations updated" + return "\(mode) \(fuel) stations — closest first, best value within \(miles) \(unit) · \(ratio) stations updated" } return "\(mode) \(fuel) within \(miles) \(unit) — \(ratio) stations updated · \(tapHint)" } @@ -93,7 +93,7 @@ struct StationsView: View { } .pickerStyle(.segmented) // In Closest mode the whole country is the pool — the - // radius is meaningless ("nearest" must never return an + // radius is meaningless ("closest" must never return an // empty state), so the picker is disabled but its value is // kept for when the user switches back to Cheapest. .disabled(sortMode == .closest) diff --git a/FuelBoard/WidgetMockScreen.swift b/FuelBoard/WidgetMockScreen.swift index d1d6577..0093b8d 100644 --- a/FuelBoard/WidgetMockScreen.swift +++ b/FuelBoard/WidgetMockScreen.swift @@ -94,7 +94,8 @@ struct WidgetMockScreen: View { isFavourites: false, location: location, locationSource: location != nil ? "live" : "none", - unit: FuelStore.loadDistanceUnit() + unit: FuelStore.loadDistanceUnit(), + bestValueResult: nil ) } } diff --git a/FuelBoard/en.lproj/Localizable.strings b/FuelBoard/en.lproj/Localizable.strings index e5445e4..32c392c 100644 --- a/FuelBoard/en.lproj/Localizable.strings +++ b/FuelBoard/en.lproj/Localizable.strings @@ -12,7 +12,7 @@ "TOP" = "TOP"; /* Stations tab */ -"Closest %@ stations — nearest first, best value within %lld %@ · %lld stations" = "Closest %@ stations — nearest first, best value within %lld %@ · %lld stations"; +"Closest %@ stations — closest first, best value within %lld %@ · %lld stations" = "Closest %@ stations — closest first, best value within %lld %@ · %lld stations"; "Cheapest %@ within %lld %@ — %lld stations · tap a station for directions." = "Cheapest %@ within %lld %@ — %lld stations · tap a station for directions."; "%@ %@ — tap a station for directions." = "%@ %@ — tap a station for directions."; "Fuel type" = "Fuel type"; @@ -81,7 +81,7 @@ "Test alert notification (real data)" = "Test alert notification (real data)"; "Send plain test notification" = "Send plain test notification"; "Debug" = "Debug"; -"The first button applies the real criteria — cheapest %@ station within %@ of you — and sends the actual station's name, price and coordinates. The second fires with no criteria at all (nearest seller), still carrying a real station, just to verify a notification appears and tapping it opens directions. Cheapest in range mirrors the app list (selected fuel + distance); the in-range count mirrors the alert radius." = "The first button applies the real criteria — cheapest %@ station within %@ of you — and sends the actual station's name, price and coordinates. The second fires with no criteria at all (nearest seller), still carrying a real station, just to verify a notification appears and tapping it opens directions. Cheapest in range mirrors the app list (selected fuel + distance); the in-range count mirrors the alert radius."; +"The first button applies the real criteria — cheapest %@ station within %@ of you — and sends the actual station's name, price and coordinates. The second fires with no criteria at all (closest seller), still carrying a real station, just to verify a notification appears and tapping it opens directions. Cheapest in range mirrors the app list (selected fuel + distance); the in-range count mirrors the alert radius." = "The first button applies the real criteria — cheapest %@ station within %@ of you — and sends the actual station's name, price and coordinates. The second fires with no criteria at all (closest seller), still carrying a real station, just to verify a notification appears and tapping it opens directions. Cheapest in range mirrors the app list (selected fuel + distance); the in-range count mirrors the alert radius."; "Widget Diagnostics" = "Widget Diagnostics"; "Each beacon is written by the widget extension at the end of every timeline entry for that intent type (keychain, so it survives free-SideStore installs). A missing SMALL beacon after adding the small widget means its timeline never reaches the provider. Installed widgets come from WidgetCenter." = "Each beacon is written by the widget extension at the end of every timeline entry for that intent type (keychain, so it survives free-SideStore installs). A missing SMALL beacon after adding the small widget means its timeline never reaches the provider. Installed widgets come from WidgetCenter."; "SMALL: %@" = "SMALL: %@"; @@ -139,7 +139,7 @@ "Connection shows the source of the current prices (CSV mirror or API). Data updated is the latest price change reported by the GOV.UK server itself. Prices use the UK Fuel Finder dataset (Open Government Licence) and refresh up to twice a day." = "Connection shows the source of the current prices (CSV mirror or API). Data updated is the latest price change reported by the GOV.UK server itself. Prices use the UK Fuel Finder dataset (Open Government Licence) and refresh up to twice a day."; "Prices near you" = "Prices near you"; "FuelBoard uses your location to show prices around you and rank stations by distance. Your position never leaves the device." = "FuelBoard uses your location to show prices around you and rank stations by distance. Your position never leaves the device."; -"Location was denied. You can still browse all stations, but \"nearest\" sorting needs it." = "Location was denied. You can still browse all stations, but \"nearest\" sorting needs it."; +"Location was denied. You can still browse all stations, but \"closest\" sorting needs it." = "Location was denied. You can still browse all stations, but \"closest\" sorting needs it."; "Allowed" = "Allowed"; "The system prompt will appear next." = "The system prompt will appear next."; "FuelBoard can notify you when you're approaching the cheapest station in your alert radius — even with the app closed. You can switch this off in the Alerts tab." = "FuelBoard can notify you when you're approaching the cheapest station in your alert radius — even with the app closed. You can switch this off in the Alerts tab."; diff --git a/FuelBoardTests/Tests/FuelBoardSharedTests/FuelSavingsEstimateTests.swift b/FuelBoardTests/Tests/FuelBoardSharedTests/FuelSavingsEstimateTests.swift index e42e450..28241dc 100644 --- a/FuelBoardTests/Tests/FuelBoardSharedTests/FuelSavingsEstimateTests.swift +++ b/FuelBoardTests/Tests/FuelBoardSharedTests/FuelSavingsEstimateTests.swift @@ -457,15 +457,15 @@ final class FuelSavingsEstimateTests: XCTestCase { func testCompactComparisonLabelUsesGenericNearestStationWording() { XCTAssertEqual( FuelSavingsFormat.comparisonLabel(status: .worthTheDrive), - "vs nearest station" + "vs closest station" ) XCTAssertEqual( FuelSavingsFormat.comparisonLabel(status: .notWorthTheDrive), - "vs nearest station" + "vs closest station" ) XCTAssertEqual( FuelSavingsFormat.comparisonLabel(status: .breakEven), - "vs nearest station" + "vs closest station" ) XCTAssertEqual( FuelSavingsFormat.comparisonLabel(status: .baseline), @@ -505,7 +505,7 @@ final class FuelSavingsEstimateTests: XCTestCase { netSavingGBP: 0, status: .baseline ) - XCTAssertEqual(baseline.capsuleHeadline(), "Closest station · your baseline") + XCTAssertEqual(baseline.capsuleHeadline(), "Closest station") let saving = FuelSavingsResult( fillLitres: 30, diff --git a/FuelBoardWidgets/FuelPriceWidget.swift b/FuelBoardWidgets/FuelPriceWidget.swift index ca7a5e2..b0ef840 100644 --- a/FuelBoardWidgets/FuelPriceWidget.swift +++ b/FuelBoardWidgets/FuelPriceWidget.swift @@ -95,7 +95,8 @@ struct FuelPriceTimelineProvider FuelSavingsJourney? = { station in + if let meters = FuelStore.roadJourneyMeters(for: station, userLat: origin.lat, userLng: origin.lng) { + let confidence: JourneyConfidence = FuelStore.hasMeasuredReturnRoadDistance( + for: station, userLat: origin.lat, userLng: origin.lng + ) ? .confirmed : .estimated + return FuelSavingsJourney( + miles: meters / FuelSavingsCalculator.metresPerMile, + basis: .roadRoute, + confidence: confidence + ) + } + return FuelSavingsJourney( + miles: FuelStore.displayDistanceKM(station: station, userLat: origin.lat, userLng: origin.lng) / + FuelSavingsCalculator.kilometresPerMile * 2, + basis: .straightLine, + confidence: .estimated + ) + } + let settings = FuelStore.loadFuelSavingsSettings() + guard settings.isConfigured else { + ordered = filtered.sorted { $0.prices[fuel]! < $1.prices[fuel]! } + break + } + let amount = settings.preferredAmount + let baseline = FuelSavingsEstimator.baselineStation(filtered, fuel: fuel, journeyMiles: journey) + let ranked = FuelSavingsEstimator.ranked( + filtered, + fuel: fuel, + baseline: baseline, + settings: settings, + amount: amount, + journeyMiles: journey + ) + ordered = ranked + if let first = ranked.first, let baseline { + let baselineJourney = journey(baseline) + let result = FuelSavingsEstimator.availability( + station: first, + fuel: fuel, + baseline: baseline, + settings: settings, + amount: amount, + journey: journey(first), + baselineJourney: baselineJourney + ) + bestValueResult = result?.result + } + case .cheapest: ordered = filtered.sorted { lhs, rhs in let lPrice = lhs.prices[fuel]! let rPrice = rhs.prices[fuel]! @@ -295,7 +348,7 @@ struct FuelPriceTimelineProvider String { - status == .baseline ? "your baseline" : "vs nearest station" + status == .baseline ? "your baseline" : "vs closest station" } /// VoiceOver form of `extraTravelLabel`. The abbreviation and the unit suffix @@ -222,13 +222,11 @@ extension FuelSavingsResult { headline().replacingOccurrences(of: "Approx. ", with: "Approximately ") } - /// Row capsule copy: the headline, plus what the baseline row IS. Without the - /// suffix the baseline capsule just repeated the status word above it - /// ("Closest station" twice) and said nothing about the saving being measured - /// against it. + /// 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 { - let headline = headline(compact: true) - return status == .baseline ? "\(headline) · your baseline" : headline + headline(compact: true) } }