Optimized variables.
This commit is contained in:
parent
d4035ea817
commit
fb84613000
1 changed files with 11 additions and 7 deletions
|
@ -21,9 +21,9 @@ import android.text.InputFilter
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
|
|
||||||
class MinMaxFilter : InputFilter {
|
class MinMaxFilter : InputFilter {
|
||||||
private var min: Int = 0
|
private val min: Int
|
||||||
private var max: Int = 0
|
private val max: Int
|
||||||
private var size: Int = 0
|
private val size: Int
|
||||||
|
|
||||||
constructor(min: Int, max: Int, size: Int) {
|
constructor(min: Int, max: Int, size: Int) {
|
||||||
this.min = min
|
this.min = min
|
||||||
|
@ -32,11 +32,15 @@ class MinMaxFilter : InputFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned, dstart: Int, dend: Int): CharSequence? {
|
override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned, dstart: Int, dend: Int): CharSequence? {
|
||||||
|
try {
|
||||||
val input = (dest.toString() + source.toString()).toInt()
|
val input = (dest.toString() + source.toString()).toInt()
|
||||||
val len = dest.length + source.length
|
val len = dest.length + source.length
|
||||||
if ((min > 0 && size > 1 && len < size && input == 0) || input in IntRange(min, max)) {
|
if ((min > 0 && size > 1 && len < size && input == 0) || input in IntRange(min, max)) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
} catch (nef: NumberFormatException) {
|
||||||
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue