Price right-aligned on second row; word-capitalise station titles (keep BP/MFG/ASDA)
This commit is contained in:
+11
-11
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ?? "",
|
||||
|
||||
+20
-2
@@ -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<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
|
||||
|
||||
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),
|
||||
|
||||
Reference in New Issue
Block a user