diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2021-02-08 13:01:31 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2021-02-08 13:01:31 -0300 |
| commit | 9196de73e9680b25a8a478f324f9f0f4a3df9c0d (patch) | |
| tree | a3fc95faf07c9a66a239e2c293e538c1dd1db646 /android/src | |
| parent | 258a4581f33538781f436f32a7dd9be10a166c25 (diff) | |
| parent | 3c7ec2535fd60188034e5bccc9662413f0b7b179 (diff) | |
| download | mullvadvpn-9196de73e9680b25a8a478f324f9f0f4a3df9c0d.tar.xz mullvadvpn-9196de73e9680b25a8a478f324f9f0f4a3df9c0d.zip | |
Merge branch 'fix-custom-dns-text-watcher-crash'
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt index 560bfb22d8..7e525bc4fe 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt @@ -11,9 +11,13 @@ import net.mullvad.mullvadvpn.R import net.mullvad.talpid.util.addressString class EditCustomDnsServerHolder(view: View, adapter: CustomDnsAdapter) : CustomDnsItemHolder(view) { - private val context = view.context - private val errorColor = context.getColor(R.color.red) - private val normalColor = context.getColor(R.color.blue) + private enum class State { + Normal, + Error, + } + + private val errorColor = view.context.getColor(R.color.red) + private val normalColor = view.context.getColor(R.color.blue) private val input: EditText = view.findViewById<EditText>(R.id.input).apply { onFocusChangeListener = OnFocusChangeListener { _, hasFocus -> @@ -25,17 +29,33 @@ class EditCustomDnsServerHolder(view: View, adapter: CustomDnsAdapter) : CustomD } } - private val watcher = object : TextWatcher { + private val watcher: TextWatcher = object : TextWatcher { override fun beforeTextChanged(text: CharSequence, start: Int, count: Int, after: Int) {} override fun afterTextChanged(text: Editable) { - input.setTextColor(normalColor) - input.removeTextChangedListener(this) + state = State.Normal } override fun onTextChanged(text: CharSequence, start: Int, before: Int, count: Int) {} } + private var state by observable(State.Normal) { _, oldState, newState -> + if (oldState != newState) { + input.apply { + when (newState) { + State.Normal -> { + setTextColor(normalColor) + removeTextChangedListener(watcher) + } + State.Error -> { + setTextColor(errorColor) + addTextChangedListener(watcher) + } + } + } + } + } + var serverAddress by observable<InetAddress?>(null) { _, _, address -> if (address != null) { val addressString = address.addressString() @@ -51,12 +71,9 @@ class EditCustomDnsServerHolder(view: View, adapter: CustomDnsAdapter) : CustomD init { view.findViewById<View>(R.id.save).setOnClickListener { - adapter.saveDnsServer(input.text.toString()) { - input.apply { - setTextColor(errorColor) - addTextChangedListener(watcher) - } - } + val onFailCallback = { state = State.Error } + + adapter.saveDnsServer(input.text.toString(), onFailCallback) } } } |
