Skip to content

Commit

Permalink
fix slider
Browse files Browse the repository at this point in the history
  • Loading branch information
brahmkshatriya committed Dec 21, 2024
1 parent 6f0b600 commit 0a7e09b
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MaterialSliderPreference(
slider.valueFrom = min.toFloat()
val max = if (allowOverride) max(to, current) else to
slider.valueTo = max.toFloat()
slider.value = max(min(current, min), max).toFloat()
slider.value = min(max(current, min), max).toFloat()
slider.stepSize = steps?.toFloat() ?: 1f

slider.addOnChangeListener { _, value, byUser ->
Expand Down Expand Up @@ -76,12 +76,13 @@ class MaterialSliderPreference(

dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val newMaxValue = editText?.text?.toString()?.toIntOrNull()
if (newMaxValue != null && newMaxValue > from) {
if (newMaxValue != null && (allowOverride || (newMaxValue in from..to))) {
slider.valueTo = newMaxValue.toFloat()
slider.value = newMaxValue.toFloat()
dialog.dismiss()
} else {
editText?.error = context.getString(R.string.error)
editText?.error = context.getString(R.string.error) +
if (!allowOverride) ": $from - $to" else ""
}
}

Expand Down

0 comments on commit 0a7e09b

Please sign in to comment.