2016-03-08 01:22:56 +01:00
|
|
|
package eu.kanade.tachiyomi.widget
|
|
|
|
|
|
|
|
import android.content.Context
|
2021-11-27 18:48:49 +01:00
|
|
|
import android.text.InputType
|
2016-03-08 01:22:56 +01:00
|
|
|
import android.util.AttributeSet
|
2021-11-27 18:48:49 +01:00
|
|
|
import android.widget.EditText
|
2016-03-08 01:22:56 +01:00
|
|
|
import android.widget.NumberPicker
|
2021-11-27 18:48:49 +01:00
|
|
|
import androidx.core.view.doOnLayout
|
2016-03-08 01:22:56 +01:00
|
|
|
import eu.kanade.tachiyomi.R
|
2021-11-27 18:48:49 +01:00
|
|
|
import eu.kanade.tachiyomi.util.view.findDescendant
|
2016-03-08 01:22:56 +01:00
|
|
|
|
|
|
|
class MinMaxNumberPicker @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
2020-04-25 20:24:45 +02:00
|
|
|
NumberPicker(context, attrs) {
|
2016-03-08 01:22:56 +01:00
|
|
|
|
2021-11-27 18:48:49 +01:00
|
|
|
override fun setDisplayedValues(displayedValues: Array<out String>?) {
|
|
|
|
super.setDisplayedValues(displayedValues)
|
|
|
|
|
|
|
|
// Disable keyboard input when a value that can't be auto-filled with number exists
|
|
|
|
val notNumberValue = displayedValues?.find { it.getOrNull(0)?.digitToIntOrNull() == null }
|
|
|
|
if (notNumberValue != null) {
|
|
|
|
descendantFocusability = FOCUS_BLOCK_DESCENDANTS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 01:22:56 +01:00
|
|
|
init {
|
|
|
|
if (attrs != null) {
|
|
|
|
val ta = context.obtainStyledAttributes(attrs, R.styleable.MinMaxNumberPicker, 0, 0)
|
|
|
|
try {
|
|
|
|
minValue = ta.getInt(R.styleable.MinMaxNumberPicker_min, 0)
|
|
|
|
maxValue = ta.getInt(R.styleable.MinMaxNumberPicker_max, 0)
|
|
|
|
} finally {
|
|
|
|
ta.recycle()
|
|
|
|
}
|
|
|
|
}
|
2021-11-27 18:48:49 +01:00
|
|
|
|
|
|
|
doOnLayout {
|
|
|
|
findDescendant<EditText>()?.setRawInputType(InputType.TYPE_CLASS_NUMBER)
|
|
|
|
}
|
2016-03-08 01:22:56 +01:00
|
|
|
}
|
|
|
|
}
|