Skip to content

Combine critical/warning sliders into one range slider (Settings + Home)#128

Merged
almothafar merged 1 commit into
masterfrom
claude/warning-critical-range-slider-bye4qt
Jul 11, 2026
Merged

Combine critical/warning sliders into one range slider (Settings + Home)#128
almothafar merged 1 commit into
masterfrom
claude/warning-critical-range-slider-bye4qt

Conversation

@almothafar

Copy link
Copy Markdown
Owner

Closes #126.

Replaces the two separate warning/critical SeekBarPreferences with a single two-thumb Material RangeSliderleft thumb = critical, right thumb = warning — shown both in Settings and as an in-fly control on the home screen.

What changed

New

  • ui/preference/BatteryRangeSliderHelper.java — single source of truth for bounds (10–50), integer step, 5% minimum thumb separation, defaults (critical 20 / warning 40), and the N% label formatter. Also the clampPair(…) logic that keeps any stored/corrupt pair inside bounds and correctly ordered.
  • ui/preference/BatteryRangeSliderPreference.java — a non-persistent Preference hosting the slider. It writes each thumb to the existing key_critical_battery_level / key_warn_battery_level keys, so BatteryLevelReceiver and the gauge read the same values with no logic change.
  • res/layout/preference_battery_range_slider.xml — title + slider + colored end captions.

Changed

  • res/xml/pref_general.xml — the two SeekBarPreferences → the new preference.
  • ui/fragment/GenericPreferenceFragment.java — removed the now-dead battery-level cross-field validation/summary code (the slider's minSeparation enforces critical < warning structurally). Temperature-threshold handling is untouched.
  • res/layout/activity_main.xml + ui/MainActivity.java — in-fly RangeSlider on the portrait home screen. Persists on release, refreshes the gauge live, and re-syncs from preferences on resume so Settings and Home stay in agreement. (Landscape omitted — the details fragment fills the width there.)
  • Strings for the captions/title in EN + AR; removed the two unused validation error strings.

Design decisions (from #126)

  • Range 10–50, step 1, min separation 5 — union of the old bands, "not 0–100".
  • Neutral thumbs + colored captions: stock RangeSlider can't color thumbs individually, so the red Critical / amber Warning captions carry the color coding (both colors already in colors.xml).
  • Value display: floating bubble while dragging plus always-on captions that update live.

Testing

  • Added BatteryRangeSliderHelperTest — a parameterized test for the representative clamp cases plus an exhaustive sweep asserting every input yields an in-range, ≥5-apart, correctly-ordered pair (matches the repo's boundary-test style).
  • Verified the clamp math independently over an exhaustive input sweep; validated all changed XML for well-formedness.
  • Note: this environment has no Android SDK, so the full Gradle build/instrumentation runs in CI rather than locally.

Notes

  • Time range was raised in discussion — it already exists as the quiet-hours window (start/end TimePickerPreferences). No change made there; flagged only for completeness.

🤖 Generated with Claude Code


Generated by Claude Code

Replace the two separate warning/critical SeekBarPreferences with a single
two-thumb Material RangeSlider — left thumb = critical, right thumb = warning —
shown both in Settings and as an in-fly control on the home screen.

- New BatteryRangeSliderPreference (non-persistent) writes each thumb to the
  existing key_critical_battery_level / key_warn_battery_level keys, so the
  receiver and gauge read the same values unchanged.
- Shared BatteryRangeSliderHelper holds the bounds (10–50), integer step,
  5% minimum thumb separation, defaults, and the "N%" label formatter, used by
  both the preference and the home slider as the single source of truth.
- The minimum separation enforces "critical < warning" structurally, retiring
  the old cross-field Snackbar validation and its error strings.
- Neutral thumbs with colored, always-on captions (red Critical / amber
  Warning) plus the floating value bubble while dragging.
- Home slider persists on release and refreshes the gauge live; it re-syncs
  from preferences on resume so Settings and Home stay in agreement.
- Add EN/AR strings and a parameterized unit test for the clamp invariant.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QYVSSGe1as68rQUyUVLhDH
@almothafar almothafar merged commit 91bbdde into master Jul 11, 2026
2 checks passed
@almothafar almothafar deleted the claude/warning-critical-range-slider-bye4qt branch July 11, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Combine critical + warning battery-level sliders into one range slider (Settings + Home)

2 participants