- New Distance picker in Edit Widget (5/10/15 miles), independent of the app's distance filter; used for both the relay fetch radius and the strict in-widget filter. - Brand text is now title-cased via sanitizedStationTitle (relay sends all-caps brands like SHELL/TESCO/MORRISONS). - Prices now show as £1.399 (monospaced) matching the app, instead of 139.9p. - Directions deep-link (mapsDirectionsURL) already per-row on medium and whole-widget on small; unchanged. 35 tests pass.
71 lines
2.0 KiB
Swift
71 lines
2.0 KiB
Swift
import AppIntents
|
|
import Foundation
|
|
|
|
// Per-widget configuration intent (iOS 17+). Every widget instance carries
|
|
// its OWN fuel + sort choices, edited directly on the home screen (long-press
|
|
// → Edit Widget), independent of what the app has selected. This is what
|
|
// allows several FuelBoard widgets to show different fuels/orderings side by
|
|
// side.
|
|
|
|
enum WidgetFuel: String, AppEnum, CaseIterable, Codable {
|
|
case e10
|
|
case e5
|
|
case diesel
|
|
|
|
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Fuel"
|
|
|
|
static var caseDisplayRepresentations: [WidgetFuel: DisplayRepresentation] = [
|
|
.e10: "Unleaded",
|
|
.e5: "Premium",
|
|
.diesel: "Diesel",
|
|
]
|
|
}
|
|
|
|
enum WidgetSort: String, AppEnum, CaseIterable, Codable {
|
|
case cheapest
|
|
case closest
|
|
|
|
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Sort by"
|
|
|
|
static var caseDisplayRepresentations: [WidgetSort: DisplayRepresentation] = [
|
|
.cheapest: "Cheapest",
|
|
.closest: "Closest",
|
|
]
|
|
}
|
|
|
|
enum WidgetDistance: String, AppEnum, CaseIterable, Codable {
|
|
case five
|
|
case ten
|
|
case fifteen
|
|
|
|
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Distance"
|
|
|
|
static var caseDisplayRepresentations: [WidgetDistance: DisplayRepresentation] = [
|
|
.five: "5 miles",
|
|
.ten: "10 miles",
|
|
.fifteen: "15 miles",
|
|
]
|
|
|
|
var miles: Int {
|
|
switch self {
|
|
case .five: return 5
|
|
case .ten: return 10
|
|
case .fifteen: return 15
|
|
}
|
|
}
|
|
}
|
|
|
|
struct FuelBoardWidgetConfigurationIntent: WidgetConfigurationIntent {
|
|
static var title: LocalizedStringResource = "Fuel & Sort"
|
|
static var description = IntentDescription("Which fuel, ordering and search radius this widget shows.")
|
|
|
|
@Parameter(title: "Fuel", default: .e10)
|
|
var fuel: WidgetFuel
|
|
|
|
@Parameter(title: "Sort by", default: .cheapest)
|
|
var sort: WidgetSort
|
|
|
|
@Parameter(title: "Distance", default: .five)
|
|
var distance: WidgetDistance
|
|
}
|