Combine critical/warning sliders into one range slider (Settings + Home)#128
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #126.
Replaces the two separate warning/critical
SeekBarPreferences with a single two-thumb MaterialRangeSlider— left 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 theN%label formatter. Also theclampPair(…)logic that keeps any stored/corrupt pair inside bounds and correctly ordered.ui/preference/BatteryRangeSliderPreference.java— a non-persistentPreferencehosting the slider. It writes each thumb to the existingkey_critical_battery_level/key_warn_battery_levelkeys, soBatteryLevelReceiverand 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 twoSeekBarPreferences → the new preference.ui/fragment/GenericPreferenceFragment.java— removed the now-dead battery-level cross-field validation/summary code (the slider'sminSeparationenforcescritical < warningstructurally). Temperature-threshold handling is untouched.res/layout/activity_main.xml+ui/MainActivity.java— in-flyRangeSlideron 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.)Design decisions (from #126)
RangeSlidercan't color thumbs individually, so the red Critical / amber Warning captions carry the color coding (both colors already incolors.xml).Testing
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).Notes
TimePickerPreferences). No change made there; flagged only for completeness.🤖 Generated with Claude Code
Generated by Claude Code