feat: station tap action toggle (open map vs more info)

Settings → Units gains a Tap station picker: Open map (default,
historic behaviour — tap opens Apple Maps directions) or More info
(tap shows a detail sheet with name, address, distance from current
location, and a Directions button). Applies to Stations and
Favourites tabs; persisted keychain-first as
fuelboard.stationTapAction. Stations footer hint follows the setting.
This commit is contained in:
FuelBoard Contributor
2026-09-14 22:03:20 +01:00
parent ac44cb4ce7
commit cc948dac3a
7 changed files with 148 additions and 7 deletions
+13 -2
View File
@@ -21,6 +21,7 @@ struct ContentView: View {
@State private var stationLimit: Int = FuelStore.loadStationLimit() @State private var stationLimit: Int = FuelStore.loadStationLimit()
@State private var distanceUnit: DistanceUnit = FuelStore.loadDistanceUnit() @State private var distanceUnit: DistanceUnit = FuelStore.loadDistanceUnit()
@State private var priceDisplayStyle: PriceDisplayStyle = FuelStore.loadPriceDisplayStyle() @State private var priceDisplayStyle: PriceDisplayStyle = FuelStore.loadPriceDisplayStyle()
@State private var stationTapAction: StationTapAction = FuelStore.loadStationTapAction()
@State private var favourites: [FavouriteEntry] = FuelStore.loadFavourites() @State private var favourites: [FavouriteEntry] = FuelStore.loadFavourites()
@State private var alertsEnabled: Bool = FuelStore.loadAlertsEnabled() @State private var alertsEnabled: Bool = FuelStore.loadAlertsEnabled()
@State private var alertsRadius: Double = FuelStore.loadAlertsRadius() @State private var alertsRadius: Double = FuelStore.loadAlertsRadius()
@@ -742,6 +743,7 @@ struct ContentView: View {
topStationID: topStationID, topStationID: topStationID,
location: location, location: location,
favouriteIDs: favouriteIDs, favouriteIDs: favouriteIDs,
stationTapAction: stationTapAction,
onToggleFavourite: toggleFavourite, onToggleFavourite: toggleFavourite,
onRefresh: { await refresh(force: true) } onRefresh: { await refresh(force: true) }
) )
@@ -756,6 +758,7 @@ struct ContentView: View {
location: location, location: location,
distanceUnit: distanceUnit, distanceUnit: distanceUnit,
priceDisplayStyle: priceDisplayStyle, priceDisplayStyle: priceDisplayStyle,
stationTapAction: stationTapAction,
onToggleFavourite: toggleFavourite, onToggleFavourite: toggleFavourite,
onReorder: reorderFavourites, onReorder: reorderFavourites,
onHistoryUnavailable: { if dataStatus == .live { dataStatus = .connectionProblem } }, onHistoryUnavailable: { if dataStatus == .live { dataStatus = .connectionProblem } },
@@ -794,6 +797,7 @@ struct ContentView: View {
tipStore: tipStore, tipStore: tipStore,
distanceUnit: $distanceUnit, distanceUnit: $distanceUnit,
priceDisplayStyle: $priceDisplayStyle, priceDisplayStyle: $priceDisplayStyle,
stationTapAction: $stationTapAction,
dataRefreshMode: $dataRefreshMode, dataRefreshMode: $dataRefreshMode,
alertsFuel: alertsFuel, alertsFuel: alertsFuel,
alertsRadiusKM: alertsRadius, alertsRadiusKM: alertsRadius,
@@ -931,7 +935,9 @@ struct StationRow: View {
let baselinePrice: Double? let baselinePrice: Double?
let isTopResult: Bool let isTopResult: Bool
let isFavourite: Bool let isFavourite: Bool
var tapAction: StationTapAction = .openMap
var onToggleFavourite: () -> Void = {} var onToggleFavourite: () -> Void = {}
var onShowDetails: (FuelStation) -> Void = { _ in }
private var ragColor: Color { private var ragColor: Color {
guard let price = station.prices[fuel], let baselinePrice else { return .gray } guard let price = station.prices[fuel], let baselinePrice else { return .gray }
@@ -1030,8 +1036,13 @@ struct StationRow: View {
} }
.contentShape(Rectangle()) .contentShape(Rectangle())
.onTapGesture { .onTapGesture {
if let url = station.mapsDirectionsURL { switch tapAction {
UIApplication.shared.open(url) case .openMap:
if let url = station.mapsDirectionsURL {
UIApplication.shared.open(url)
}
case .showDetails:
onShowDetails(station)
} }
} }
} }
+16 -1
View File
@@ -14,6 +14,7 @@ struct FavouritesView: View {
let location: Coordinate? let location: Coordinate?
let distanceUnit: DistanceUnit let distanceUnit: DistanceUnit
let priceDisplayStyle: PriceDisplayStyle let priceDisplayStyle: PriceDisplayStyle
let stationTapAction: StationTapAction
var onToggleFavourite: (FuelStation, FuelType) -> Void = { _, _ in } var onToggleFavourite: (FuelStation, FuelType) -> Void = { _, _ in }
/// Persists a reordered favourites array (after drag-and-drop). /// Persists a reordered favourites array (after drag-and-drop).
var onReorder: ([FavouriteEntry]) -> Void = { _ in } var onReorder: ([FavouriteEntry]) -> Void = { _ in }
@@ -37,6 +38,9 @@ struct FavouritesView: View {
/// Trends sheet (price history chart) presentation state. /// Trends sheet (price history chart) presentation state.
@State private var showTrends = false @State private var showTrends = false
/// Station picked for the More-info sheet (tap action = showDetails).
@State private var detailStation: FuelStation?
private var activeFuel: FuelType { private var activeFuel: FuelType {
availableFuels.contains(fuel) ? fuel : (availableFuels.first ?? .e10) availableFuels.contains(fuel) ? fuel : (availableFuels.first ?? .e10)
} }
@@ -65,6 +69,7 @@ struct FavouritesView: View {
location: Coordinate?, location: Coordinate?,
distanceUnit: DistanceUnit, distanceUnit: DistanceUnit,
priceDisplayStyle: PriceDisplayStyle, priceDisplayStyle: PriceDisplayStyle,
stationTapAction: StationTapAction,
onToggleFavourite: @escaping (FuelStation, FuelType) -> Void = { _, _ in }, onToggleFavourite: @escaping (FuelStation, FuelType) -> Void = { _, _ in },
onReorder: @escaping ([FavouriteEntry]) -> Void = { _ in }, onReorder: @escaping ([FavouriteEntry]) -> Void = { _ in },
onHistoryUnavailable: (() -> Void)? = nil, onHistoryUnavailable: (() -> Void)? = nil,
@@ -74,6 +79,7 @@ struct FavouritesView: View {
self.location = location self.location = location
self.distanceUnit = distanceUnit self.distanceUnit = distanceUnit
self.priceDisplayStyle = priceDisplayStyle self.priceDisplayStyle = priceDisplayStyle
self.stationTapAction = stationTapAction
self.onToggleFavourite = onToggleFavourite self.onToggleFavourite = onToggleFavourite
self.onReorder = onReorder self.onReorder = onReorder
self.onHistoryUnavailable = onHistoryUnavailable self.onHistoryUnavailable = onHistoryUnavailable
@@ -129,7 +135,9 @@ struct FavouritesView: View {
baselinePrice: cheapestPrice, baselinePrice: cheapestPrice,
isTopResult: index == 0, isTopResult: index == 0,
isFavourite: activeFuelFavouriteIDs.contains(station.id), isFavourite: activeFuelFavouriteIDs.contains(station.id),
onToggleFavourite: { onToggleFavourite(station, activeFuel) } tapAction: stationTapAction,
onToggleFavourite: { onToggleFavourite(station, activeFuel) },
onShowDetails: { detailStation = $0 }
) )
} }
.onMove(perform: moveFavourite) .onMove(perform: moveFavourite)
@@ -171,6 +179,13 @@ struct FavouritesView: View {
onHistoryRecovered: onHistoryRecovered onHistoryRecovered: onHistoryRecovered
) )
} }
.sheet(item: $detailStation) { station in
StationDetailView(
station: station,
location: location,
distanceUnit: distanceUnit
)
}
.onAppear { .onAppear {
#if DEBUG #if DEBUG
// QA hook: launch with `-showTrends` to open the sheet // QA hook: launch with `-showTrends` to open the sheet
+11 -1
View File
@@ -18,6 +18,7 @@ struct SettingsView: View {
@ObservedObject var tipStore: TipStore @ObservedObject var tipStore: TipStore
@Binding var distanceUnit: DistanceUnit @Binding var distanceUnit: DistanceUnit
@Binding var priceDisplayStyle: PriceDisplayStyle @Binding var priceDisplayStyle: PriceDisplayStyle
@Binding var stationTapAction: StationTapAction
@Binding var dataRefreshMode: DataRefreshMode @Binding var dataRefreshMode: DataRefreshMode
/// The fuel + radius currently configured for alerts (mirrors the Alerts /// The fuel + radius currently configured for alerts (mirrors the Alerts
/// tab) so the test notification matches what real alerts will say. /// tab) so the test notification matches what real alerts will say.
@@ -117,10 +118,19 @@ struct SettingsView: View {
WidgetCenter.shared.reloadAllTimelines() WidgetCenter.shared.reloadAllTimelines()
WatchSyncManager.shared.pushSnapshot() WatchSyncManager.shared.pushSnapshot()
} }
Picker("Tap station", selection: $stationTapAction) {
ForEach(StationTapAction.allCases) { action in
Text(action.displayName).tag(action)
}
}
.pickerStyle(.segmented)
.onChange(of: stationTapAction) { _, newValue in
FuelStore.saveStationTapAction(newValue)
}
} header: { } header: {
Text("Units") Text("Units")
} footer: { } footer: {
Text("Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (129.9) or in pounds and pence (£1.29⁹/L).") Text("Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (129.9) or in pounds and pence (£1.29⁹/L). Tapping a station either opens directions straight away or shows its details first.")
} }
Section { Section {
+47
View File
@@ -0,0 +1,47 @@
import SwiftUI
import UIKit
/// Detail sheet for a tapped station (when Settings Tap station = More info).
/// Shows 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
@Environment(\.dismiss) private var dismiss
var body: some View {
NavigationStack {
List {
Section {
LabeledContent("Name", value: station.name)
LabeledContent("Address", value: "\(station.address), \(station.postcode)")
if let location {
let km = FuelStore.displayDistanceKM(
station: station, userLat: location.lat, userLng: location.lng
)
LabeledContent("Distance", value: distanceUnit.format(km))
.monospacedDigit()
}
}
Section {
Button {
if let url = station.mapsDirectionsURL {
UIApplication.shared.open(url)
}
} label: {
Label("Directions", systemImage: "arrow.triangle.turn.up.right.diamond.fill")
}
}
}
.navigationTitle(station.name)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Done") { dismiss() }
}
}
}
}
}
+19 -3
View File
@@ -15,6 +15,7 @@ struct StationsView: View {
let topStationID: String? let topStationID: String?
let location: Coordinate? let location: Coordinate?
let favouriteIDs: Set<String> let favouriteIDs: Set<String>
let stationTapAction: StationTapAction
var onToggleFavourite: (FuelStation, FuelType) -> Void = { _, _ in } var onToggleFavourite: (FuelStation, FuelType) -> Void = { _, _ in }
var onRefresh: () async -> Void = {} var onRefresh: () async -> Void = {}
@@ -29,6 +30,9 @@ struct StationsView: View {
/// info button in the header keeps the list focused on stations. /// info button in the header keeps the list focused on stations.
@State private var showKey = false @State private var showKey = false
/// Station picked for the More-info sheet (tap action = showDetails).
@State private var detailStation: FuelStation?
/// Bottom-of-tab explainer (moved from the top 2026-08-16): mode/radius/ /// Bottom-of-tab explainer (moved from the top 2026-08-16): mode/radius/
/// directions context + "N/TOTAL stations updated". The numerator is the /// directions context + "N/TOTAL stations updated". The numerator is the
/// current list pool; the denominator is the full UK station total from /// current list pool; the denominator is the full UK station total from
@@ -38,6 +42,9 @@ struct StationsView: View {
let unit = distanceUnit.label(for: Double(miles)) let unit = distanceUnit.label(for: Double(miles))
let fuel = selectedFuel.displayName let fuel = selectedFuel.displayName
let mode = sortMode == .closest ? "Closest" : "Cheapest" let mode = sortMode == .closest ? "Closest" : "Cheapest"
let tapHint = stationTapAction == .openMap
? "tap a station for directions."
: "tap a station for details."
let ratio: String let ratio: String
if let total = FuelStore.loadStationCount() { if let total = FuelStore.loadStationCount() {
ratio = "\(totalCount)/\(total)" ratio = "\(totalCount)/\(total)"
@@ -48,9 +55,9 @@ struct StationsView: View {
if sortMode == .closest { if sortMode == .closest {
return "\(mode) \(fuel) stations — nearest first, best value within \(miles) \(unit) · \(ratio) stations updated" return "\(mode) \(fuel) stations — nearest first, best value within \(miles) \(unit) · \(ratio) stations updated"
} }
return "\(mode) \(fuel) within \(miles) \(unit)\(ratio) stations updated · tap a station for directions." return "\(mode) \(fuel) within \(miles) \(unit)\(ratio) stations updated · \(tapHint)"
} }
return "\(mode) \(fuel)\(ratio) stations updated · tap a station for directions." return "\(mode) \(fuel)\(ratio) stations updated · \(tapHint)"
} }
var body: some View { var body: some View {
@@ -126,7 +133,9 @@ struct StationsView: View {
baselinePrice: baselinePrice, baselinePrice: baselinePrice,
isTopResult: station.id == topStationID, isTopResult: station.id == topStationID,
isFavourite: favouriteIDs.contains(station.id), isFavourite: favouriteIDs.contains(station.id),
onToggleFavourite: { onToggleFavourite(station, selectedFuel) } tapAction: stationTapAction,
onToggleFavourite: { onToggleFavourite(station, selectedFuel) },
onShowDetails: { detailStation = $0 }
) )
} }
@@ -260,6 +269,13 @@ struct StationsView: View {
.presentationDetents([.fraction(0.6)]) .presentationDetents([.fraction(0.6)])
.presentationBackground(Color(UIColor.systemGroupedBackground)) .presentationBackground(Color(UIColor.systemGroupedBackground))
} }
.sheet(item: $detailStation) { station in
StationDetailView(
station: station,
location: location,
distanceUnit: distanceUnit
)
}
} }
} }
+7
View File
@@ -56,6 +56,13 @@
"Units" = "Units"; "Units" = "Units";
"Price display" = "Price display"; "Price display" = "Price display";
"Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (129.9) or in pounds and pence (£1.29⁹/L)." = "Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (129.9) or in pounds and pence (£1.29⁹/L)."; "Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (129.9) or in pounds and pence (£1.29⁹/L)." = "Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (129.9) or in pounds and pence (£1.29⁹/L).";
"Tap station" = "Tap station";
"Open map" = "Open map";
"More info" = "More info";
"Name" = "Name";
"Address" = "Address";
"Distance" = "Distance";
"Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (129.9) or in pounds and pence (£1.29⁹/L). Tapping a station either opens directions straight away or shows its details first." = "Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (129.9) or in pounds and pence (£1.29⁹/L). Tapping a station either opens directions straight away or shows its details first.";
"Show introduction" = "Replay onboarding"; "Show introduction" = "Replay onboarding";
"Replay the welcome screen, including the location and notification permission prompts." = "Replay the welcome screen, including the location and notification permission prompts."; "Replay the welcome screen, including the location and notification permission prompts." = "Replay the welcome screen, including the location and notification permission prompts.";
"Test alert notification (real data)" = "Test alert notification (real data)"; "Test alert notification (real data)" = "Test alert notification (real data)";
+35
View File
@@ -208,6 +208,25 @@ enum PriceDisplayStyle: String, Codable, CaseIterable, Identifiable {
} }
} }
// MARK: - Station tap action
/// What happens when a station row is tapped in the Stations/Favourites tabs:
/// open Apple Maps directions immediately (historic behaviour, default), or
/// show a detail sheet (name, address, distance, Directions button).
enum StationTapAction: String, Codable, CaseIterable, Identifiable {
case openMap // tap Apple Maps directions straight away
case showDetails // tap detail sheet, Directions button inside
var id: String { rawValue }
var displayName: String {
switch self {
case .openMap: return "Open map"
case .showDetails: return "More info"
}
}
}
// MARK: - Station model // MARK: - Station model
struct FuelStation: Identifiable, Codable, Equatable { struct FuelStation: Identifiable, Codable, Equatable {
@@ -542,6 +561,22 @@ struct FuelStore {
saveString(style.rawValue, service: priceDisplayStyleKey) saveString(style.rawValue, service: priceDisplayStyleKey)
} }
// MARK: Station tap action open map vs detail sheet. Stored raw value;
// default open map preserves the historic tap behaviour for existing installs.
static let stationTapActionKey = "fuelboard.stationTapAction"
static func loadStationTapAction() -> StationTapAction {
if let raw = loadString(service: stationTapActionKey), let action = StationTapAction(rawValue: raw) {
return action
}
return .openMap
}
static func saveStationTapAction(_ action: StationTapAction) {
saveString(action.rawValue, service: stationTapActionKey)
}
/// Superscript digit glyphs for the pounds & pence format's small raised /// Superscript digit glyphs for the pounds & pence format's small raised
/// third digit (the forecourt style: "£1.29"). /// third digit (the forecourt style: "£1.29").
private static let superscriptDigits: [Character] = ["", "¹", "²", "³", "", "", "", "", "", ""] private static let superscriptDigits: [Character] = ["", "¹", "²", "³", "", "", "", "", "", ""]