mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-05 20:05:09 +01:00
Only allow digits in custom download range dialog (closes #6220)
This commit is contained in:
parent
a8a761aa5f
commit
1e4d7f8c6e
@ -1,11 +1,14 @@
|
|||||||
package eu.kanade.tachiyomi.widget
|
package eu.kanade.tachiyomi.widget
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.text.InputFilter
|
||||||
import android.text.SpannableStringBuilder
|
import android.text.SpannableStringBuilder
|
||||||
|
import android.text.Spanned
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import androidx.core.text.isDigitsOnly
|
||||||
import androidx.core.widget.doOnTextChanged
|
import androidx.core.widget.doOnTextChanged
|
||||||
import eu.kanade.tachiyomi.databinding.DownloadCustomAmountBinding
|
import eu.kanade.tachiyomi.databinding.DownloadCustomAmountBinding
|
||||||
import eu.kanade.tachiyomi.util.system.logcat
|
import eu.kanade.tachiyomi.util.system.logcat
|
||||||
@ -45,6 +48,7 @@ class DialogCustomDownloadView @JvmOverloads constructor(context: Context, attrs
|
|||||||
|
|
||||||
// Set download count to 0.
|
// Set download count to 0.
|
||||||
binding.myNumber.text = SpannableStringBuilder(getAmount(0).toString())
|
binding.myNumber.text = SpannableStringBuilder(getAmount(0).toString())
|
||||||
|
binding.myNumber.filters = arrayOf(DigitInputFilter())
|
||||||
|
|
||||||
// When user presses button decrease amount by 10.
|
// When user presses button decrease amount by 10.
|
||||||
binding.btnDecrease10.setOnClickListener {
|
binding.btnDecrease10.setOnClickListener {
|
||||||
@ -102,3 +106,20 @@ class DialogCustomDownloadView @JvmOverloads constructor(context: Context, attrs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class DigitInputFilter : InputFilter {
|
||||||
|
|
||||||
|
override fun filter(
|
||||||
|
source: CharSequence,
|
||||||
|
start: Int,
|
||||||
|
end: Int,
|
||||||
|
dest: Spanned,
|
||||||
|
dstart: Int,
|
||||||
|
dend: Int,
|
||||||
|
): CharSequence {
|
||||||
|
return when {
|
||||||
|
source.toString().isDigitsOnly() -> source.toString()
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user