Two things the listing row was saying twice, or too loosely.
- The verdict capsule used a Label, and a Label lays its icon and title out
across the width it is given: in a listing row that left 22pt of empty space
between the symbol and "Save £1.07 after travel". It is now an HStack with
an explicit 3pt spacing (5pt in the detail sheet), so the text sits beside its
icon and the capsule background hugs the pair. Measured on the same row: the
capsule text moved x 412 -> 341 and the pill 270-831 -> 270-691.
- The address line printed the station name a second time. The official Fuel
Finder address field usually opens with the station's own name ("CHIDSWELL
SERVICE STATION, LEEDS ROAD, DEWSBURY, WF12 7QW" for "Jet Chidswell"): 14% of
the dump's addresses start with the exact name, and 13% also end with the
postcode the row appended again. StationAddressLine (new, in Shared/, so the
row and the detail sheet share one rule) drops a leading repeat of the name
and writes the postcode exactly once.
The rules are deliberately conservative: a leading segment carrying a house
number is a real street address and is left alone ("41 ANNACLOY RD ANNACLOY"),
and a partial-word match ("Jet" against "JETSON FILLING STATION") never cuts
into a word. 14 new tests (169 total, 0 failures) pin the shapes found in the
real dump as well as the examples above.
Verified on the simulator: the first listing row's second line went from
"CHIDSWELL SERVICE STA..." to "LEEDS ROAD, DEWSBURY...", and the detail sheet
reads "Sainsbury's Halifax / WADE STREET, HX1 1SB".
126 lines
5.7 KiB
Swift
126 lines
5.7 KiB
Swift
import SwiftUI
|
|
import MapKit
|
|
import UIKit
|
|
|
|
/// Detail sheet for a tapped station (when Settings → Tap station = More info).
|
|
/// Shows a small map preview, the station name, address, distance from the
|
|
/// current location, and a Directions button that opens Apple Maps — the same
|
|
/// destination a direct tap would have opened.
|
|
struct StationDetailView: View {
|
|
let station: FuelStation
|
|
let location: Coordinate?
|
|
let distanceUnit: DistanceUnit
|
|
var fuelSavings: FuelSavingsAvailability? = nil
|
|
var fuelSavingsAmount: FuelSavingsFillAmount = FuelSavingsSettings.defaultPreferredAmount
|
|
var savingsBaselineStationName: String? = nil
|
|
/// Whether this station is starred for the fuel currently being viewed, and
|
|
/// the toggle that flips it. Passed from the list that opened the sheet, so
|
|
/// the star here and the star on the row are the same fuel-scoped
|
|
/// favourite and cannot drift apart.
|
|
var isFavourite: Bool = false
|
|
var onToggleFavourite: (() -> Void)? = nil
|
|
@Environment(\.dismiss) private var dismiss
|
|
@State private var showingReportIssueConfirmation = false
|
|
|
|
private let reportIssueURL = URL(string: "https://www.gov.uk/guidance/report-an-error-in-fuel-prices-or-forecourt-details")!
|
|
|
|
private var stationCoordinate: CLLocationCoordinate2D {
|
|
CLLocationCoordinate2D(latitude: station.lat, longitude: station.lng)
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
List {
|
|
Section {
|
|
Map(position: .constant(.region(MKCoordinateRegion(
|
|
center: stationCoordinate,
|
|
span: MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02)
|
|
)))) {
|
|
Marker(station.name, coordinate: stationCoordinate)
|
|
.tint(.red)
|
|
}
|
|
.frame(height: 180)
|
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
|
.allowsHitTesting(false)
|
|
.listRowInsets(EdgeInsets())
|
|
}
|
|
Section {
|
|
LabeledContent("Name", value: station.name)
|
|
LabeledContent("Address", value: StationAddressLine.display(address: station.address,
|
|
postcode: station.postcode,
|
|
name: station.name))
|
|
if let location {
|
|
let km = FuelStore.displayDistanceKM(
|
|
station: station, userLat: location.lat, userLng: location.lng
|
|
)
|
|
LabeledContent("Distance", value: distanceUnit.format(km))
|
|
.monospacedDigit()
|
|
}
|
|
ForEach(StationNotice.notices(for: station)) { notice in
|
|
Label(notice.title, systemImage: notice.symbolName)
|
|
.font(.subheadline.weight(.semibold))
|
|
.foregroundStyle(.orange)
|
|
.padding(.horizontal, 10)
|
|
.padding(.vertical, 6)
|
|
.background(Capsule().fill(Color.orange.opacity(0.14)))
|
|
}
|
|
}
|
|
Section {
|
|
FuelSavingsSummaryView(
|
|
availability: fuelSavings,
|
|
amount: fuelSavingsAmount,
|
|
baselineStationName: savingsBaselineStationName,
|
|
distanceUnit: distanceUnit
|
|
)
|
|
} header: {
|
|
Text("Worth the drive?")
|
|
}
|
|
|
|
Section {
|
|
Button {
|
|
if let url = station.mapsDirectionsURL {
|
|
UIApplication.shared.open(url)
|
|
}
|
|
} label: {
|
|
Label("Directions", systemImage: "arrow.triangle.turn.up.right.diamond.fill")
|
|
}
|
|
Button(role: .destructive) {
|
|
showingReportIssueConfirmation = true
|
|
} label: {
|
|
Label("Report issue", systemImage: "exclamationmark.bubble.fill")
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle(station.name)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.alert("Report an error?", isPresented: $showingReportIssueConfirmation) {
|
|
Button("Cancel", role: .cancel) { }
|
|
Button("Report") {
|
|
UIApplication.shared.open(reportIssueURL)
|
|
}
|
|
} message: {
|
|
Text("Are you sure you want to report an error in fuel prices or forecourt details? This will open in your chosen browser.")
|
|
}
|
|
.toolbar {
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
Button("Done") { dismiss() }
|
|
}
|
|
ToolbarItem(placement: .confirmationAction) {
|
|
Button {
|
|
onToggleFavourite?()
|
|
} label: {
|
|
Image(systemName: isFavourite ? "star.fill" : "star")
|
|
}
|
|
.tint(isFavourite ? Color.yellow : nil)
|
|
.disabled(onToggleFavourite == nil)
|
|
.accessibilityLabel(
|
|
isFavourite
|
|
? String(localized: "Remove from favourites", comment: "Unstar a station from the More info sheet")
|
|
: String(localized: "Add to favourites", comment: "Star a station from the More info sheet")
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|