diff --git a/FuelBoard/ContentView.swift b/FuelBoard/ContentView.swift index 45e0c6e..e343fc2 100644 --- a/FuelBoard/ContentView.swift +++ b/FuelBoard/ContentView.swift @@ -229,6 +229,17 @@ struct StationRow: View { } 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] { Circle() .fill(ragColor) @@ -242,17 +253,6 @@ struct StationRow: View { .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() - } } } diff --git a/Shared/FuelPriceProvider.swift b/Shared/FuelPriceProvider.swift index 3e131a5..b645ce8 100644 --- a/Shared/FuelPriceProvider.swift +++ b/Shared/FuelPriceProvider.swift @@ -50,7 +50,7 @@ struct RelayFuelProvider: FuelPriceProviding { return payload.stations.map { relay in FuelStation( id: relay.id ?? relay.name ?? UUID().uuidString, - name: relay.name ?? "Unknown", + name: (relay.name ?? "Unknown").sanitizedStationTitle, brand: relay.brand ?? "", address: relay.address ?? "", postcode: relay.postcode ?? "", diff --git a/Shared/FuelStore.swift b/Shared/FuelStore.swift index 4495524..b7d2cba 100644 --- a/Shared/FuelStore.swift +++ b/Shared/FuelStore.swift @@ -67,7 +67,7 @@ enum FuelType: String, Codable, CaseIterable, Identifiable { struct FuelStation: Identifiable, Codable, Equatable { let id: String - let name: String + var name: String let brand: String let address: 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 = ["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 struct FuelStore { @@ -212,7 +226,11 @@ struct FuelStore { static func loadFavourites() -> [FuelStation] { if let data = keychainData(service: favouritesKey), 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), let data = defaults.data(forKey: favouritesKey),