Price right-aligned on second row; word-capitalise station titles (keep BP/MFG/ASDA)

This commit is contained in:
FuelBoard Contributor
2026-08-11 15:40:19 +01:00
parent d8f635fb41
commit 75629b39b5
3 changed files with 32 additions and 14 deletions
+11 -11
View File
@@ -229,6 +229,17 @@ struct StationRow: View {
} }
HStack(spacing: 5) { HStack(spacing: 5) {
Text("\(station.address), \(station.postcode)")
.font(.caption)
.foregroundStyle(.secondary)
.lineLimit(1)
Spacer(minLength: 8)
if let location {
Text(String(format: "%.1f km", station.distanceKM(to: location.lat, lng2: location.lng)))
.font(.caption2)
.foregroundStyle(.secondary)
.monospacedDigit()
}
if let price = station.prices[fuel] { if let price = station.prices[fuel] {
Circle() Circle()
.fill(ragColor) .fill(ragColor)
@@ -242,17 +253,6 @@ struct StationRow: View {
.foregroundStyle(ragColor) .foregroundStyle(ragColor)
} }
} }
Text("\(station.address), \(station.postcode)")
.font(.caption)
.foregroundStyle(.secondary)
.lineLimit(1)
Spacer(minLength: 8)
if let location {
Text(String(format: "%.1f km", station.distanceKM(to: location.lat, lng2: location.lng)))
.font(.caption2)
.foregroundStyle(.secondary)
.monospacedDigit()
}
} }
} }
+1 -1
View File
@@ -50,7 +50,7 @@ struct RelayFuelProvider: FuelPriceProviding {
return payload.stations.map { relay in return payload.stations.map { relay in
FuelStation( FuelStation(
id: relay.id ?? relay.name ?? UUID().uuidString, id: relay.id ?? relay.name ?? UUID().uuidString,
name: relay.name ?? "Unknown", name: (relay.name ?? "Unknown").sanitizedStationTitle,
brand: relay.brand ?? "", brand: relay.brand ?? "",
address: relay.address ?? "", address: relay.address ?? "",
postcode: relay.postcode ?? "", postcode: relay.postcode ?? "",
+20 -2
View File
@@ -67,7 +67,7 @@ enum FuelType: String, Codable, CaseIterable, Identifiable {
struct FuelStation: Identifiable, Codable, Equatable { struct FuelStation: Identifiable, Codable, Equatable {
let id: String let id: String
let name: String var name: String
let brand: String let brand: String
let address: String let address: String
let postcode: String let postcode: String
@@ -118,6 +118,20 @@ struct FuelStation: Identifiable, Codable, Equatable {
} }
} }
extension String {
/// Word-capitalises ALL-CAPS titles ("SHELL SALTERHEBBLE" "Shell Salterhebble"),
/// preserving known acronyms (BP, MFG, ASDA). Mixed-case names pass through untouched.
var sanitizedStationTitle: String {
guard self == self.uppercased(), self.rangeOfCharacter(from: .letters) != nil else { return self }
let keepUppercase: Set<String> = ["BP", "MFG", "ASDA", "MOTO"]
return self.split(separator: " ").map { word in
let w = String(word)
if keepUppercase.contains(w.uppercased()) { return w.uppercased() }
return w.prefix(1).uppercased() + w.dropFirst().lowercased()
}.joined(separator: " ")
}
}
// MARK: - Shared store // MARK: - Shared store
struct FuelStore { struct FuelStore {
@@ -212,7 +226,11 @@ struct FuelStore {
static func loadFavourites() -> [FuelStation] { static func loadFavourites() -> [FuelStation] {
if let data = keychainData(service: favouritesKey), if let data = keychainData(service: favouritesKey),
let favs = try? JSONDecoder().decode([FuelStation].self, from: data) { let favs = try? JSONDecoder().decode([FuelStation].self, from: data) {
return favs return favs.map { fav in
var f = fav
f.name = fav.name.sanitizedStationTitle
return f
}
} }
if let defaults = UserDefaults(suiteName: appGroupSuite), if let defaults = UserDefaults(suiteName: appGroupSuite),
let data = defaults.data(forKey: favouritesKey), let data = defaults.data(forKey: favouritesKey),