Fuel Savings: MPG and fill-up are sliders, not typed fields

The two Fuel Savings figures and the in-list fill-up control were text
fields. A typed figure could sit outside the slider's own bounds, so the
control and the number it claimed to show could disagree, and the decimal
pad needed a Done button to escape.

- Settings: "Average fuel economy" and "Typical fill-up" are now sliders
  with a read-out ("45 MPG", "£40" / "40 L") in place of the field. The
  warning copy reads "Set a realistic..." rather than "Enter...".
- FuelSavingsAdjustmentView (shared by the Stations Worth-the-Drive header
  and the Favourites tab) drops its text field and gains the same read-out;
  the typed-value machinery and the -focusFillAmount QA hook go with it.
- Slider bounds live in FuelSavingsCalculator (fillAmountSliderRange/Step,
  mpgSliderRange/Step) so the Settings control and the in-list control can
  never offer different ranges, and the fill-up slider range stays inside
  the calculator's validity ceiling (asserted by test).
- Two tests pin those invariants: every slider position is a valid amount,
  and both MPG bounds are valid MPG values. 155 tests, 0 failures.
- Comments that described the removed fields were updated; the keyboard
  Done-bar plumbing is kept (no numeric field remains in the app, so it can
  no longer fire) rather than deleted, so any field added later still has an
  escape route.

Verified on the simulator: Settings shows "Average fuel economy / 45 MPG"
with no field, and the Worth-the-Drive fill-up control shows the unit picker
with a "£40" read-out and a slider. The Settings "Typical fill-up" row sits
below the fold on every simulator available here (and synthetic input cannot
scroll it), so those pixels are unverified.
This commit is contained in:
FuelBoard Contributor
2026-10-11 17:41:53 +01:00
parent d0a89d97d5
commit cf3abb3fa7
5 changed files with 116 additions and 65 deletions
+24
View File
@@ -224,6 +224,30 @@ enum FuelSavingsCalculator {
}
}
/// Bounds for every fill-up SLIDER (Settings and the in-list adjustment
/// share them, so the two controls can never offer different ranges). The
/// validity ceiling above is deliberately wider, so a stored outlier is
/// displayed rather than destroyed by the control that shows it.
static func fillAmountSliderRange(for unit: FuelSavingsFillUnit) -> ClosedRange<Double> {
switch unit {
case .pounds: return 10...100
case .litres: return 10...80
}
}
static func fillAmountSliderStep(for unit: FuelSavingsFillUnit) -> Double {
switch unit {
case .pounds: return 5
case .litres: return 1
}
}
/// Bounds for the average-MPG slider. The validity bounds (5...200) are
/// wide enough for any stored figure but far too wide to fine-tune by
/// touch; every real-world UK car sits inside this range.
static let mpgSliderRange: ClosedRange<Double> = 10...100
static let mpgSliderStep: Double = 1
static func isValidMPG(_ mpg: Double) -> Bool {
mpg.isFinite && mpg >= minimumMPG && mpg <= maximumMPG
}