|
@@ -16,10 +16,26 @@ class TextSeekBar : ConstraintLayout {
|
|
private var minValue = 0
|
|
private var minValue = 0
|
|
private var initValue = 0
|
|
private var initValue = 0
|
|
|
|
|
|
|
|
+ private val defaultFormatter = object : SeekBarFormatter {
|
|
|
|
+ override fun format(value: Int): String {
|
|
|
|
+ return value.toString()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var formatter = defaultFormatter
|
|
|
|
+ set(value) {
|
|
|
|
+ field = value
|
|
|
|
+ tv_seekBarValue?.text = "${formatter.format(currentValue)}$unit"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ interface SeekBarFormatter {
|
|
|
|
+ fun format(value: Int): String
|
|
|
|
+ }
|
|
|
|
+
|
|
var currentValue = 0
|
|
var currentValue = 0
|
|
set(value) {
|
|
set(value) {
|
|
field = Math.max(Math.min(value, maxValue), minValue)
|
|
field = Math.max(Math.min(value, maxValue), minValue)
|
|
- tv_seekBarValue?.text = "$field$unit"
|
|
|
|
|
|
+ tv_seekBarValue?.text = "${formatter.format(currentValue)}$unit"
|
|
seekBar?.progress = field - minValue
|
|
seekBar?.progress = field - minValue
|
|
}
|
|
}
|
|
var onSeekBarChangeListener: SeekBar.OnSeekBarChangeListener? = null
|
|
var onSeekBarChangeListener: SeekBar.OnSeekBarChangeListener? = null
|