From 3463d6c752cfc1145f4c8db9f65f145002ece5fb Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sun, 28 Nov 2021 00:48:49 +0700 Subject: [PATCH] MinMaxNumberPicker: Set IME input to use number only (#6286) * MinMaxNumberPicker: Set IME input to use number only * MinMaxNumberPicker: Auto disable keyboard input when needed --- .../tachiyomi/widget/MinMaxNumberPicker.kt | 18 ++++++++++++++++++ .../main/res/layout/pref_library_columns.xml | 2 -- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/MinMaxNumberPicker.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/MinMaxNumberPicker.kt index a041db442b..5da40a9039 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/MinMaxNumberPicker.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/MinMaxNumberPicker.kt @@ -1,13 +1,27 @@ package eu.kanade.tachiyomi.widget import android.content.Context +import android.text.InputType import android.util.AttributeSet +import android.widget.EditText import android.widget.NumberPicker +import androidx.core.view.doOnLayout import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.view.findDescendant class MinMaxNumberPicker @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : NumberPicker(context, attrs) { + override fun setDisplayedValues(displayedValues: Array?) { + 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 + } + } + init { if (attrs != null) { val ta = context.obtainStyledAttributes(attrs, R.styleable.MinMaxNumberPicker, 0, 0) @@ -18,5 +32,9 @@ class MinMaxNumberPicker @JvmOverloads constructor(context: Context, attrs: Attr ta.recycle() } } + + doOnLayout { + findDescendant()?.setRawInputType(InputType.TYPE_CLASS_NUMBER) + } } } diff --git a/app/src/main/res/layout/pref_library_columns.xml b/app/src/main/res/layout/pref_library_columns.xml index aa3caed897..059e33ebfb 100644 --- a/app/src/main/res/layout/pref_library_columns.xml +++ b/app/src/main/res/layout/pref_library_columns.xml @@ -22,7 +22,6 @@ android:id="@+id/portrait_columns" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:descendantFocusability="blocksDescendants" app:max="10" app:min="0" /> @@ -44,7 +43,6 @@ android:id="@+id/landscape_columns" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:descendantFocusability="blocksDescendants" app:max="10" app:min="0" />