diff options
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/CellInput.kt | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/CellInput.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/CellInput.kt deleted file mode 100644 index dd40712e24..0000000000 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/CellInput.kt +++ /dev/null @@ -1,60 +0,0 @@ -package net.mullvad.mullvadvpn.ui - -import android.text.Editable -import android.text.TextWatcher -import android.widget.EditText -import net.mullvad.mullvadvpn.R - -class CellInput(val input: EditText, val minValue: Int, val maxValue: Int) { - private val context = input.context - - private val validInputColor = context.getColor(R.color.white) - private val invalidInputColor = context.getColor(R.color.red) - - var value - get() = input.text.toString().trim().toIntOrNull() - set(value) { - input.setText(value?.toString() ?: "") - } - - var onSubmit: ((Int?) -> Unit)? = null - - var hasFocus = false - private set(value) { - if (field != value) { - field = value - - if (value == false) { - val inputValue = this@CellInput.value - - if (inputValue == null || (inputValue >= minValue && inputValue <= maxValue)) { - onSubmit?.invoke(inputValue) - } - } - } - } - - init { - input.apply { - addTextChangedListener(InputWatcher()) - - setOnFocusChangeListener { _, newHasFocus -> hasFocus = newHasFocus } - } - } - - inner class InputWatcher : TextWatcher { - override fun beforeTextChanged(text: CharSequence, start: Int, count: Int, after: Int) {} - - override fun onTextChanged(text: CharSequence, start: Int, count: Int, after: Int) {} - - override fun afterTextChanged(text: Editable) { - val value = text.toString().trim().toIntOrNull() - - if (value != null && value >= minValue && value <= maxValue) { - input.setTextColor(validInputColor) - } else { - input.setTextColor(invalidInputColor) - } - } - } -} |
