summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-02-05 20:44:44 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-02-08 15:30:37 +0000
commit04d9870967fb9fc6462c0b9040e99f629219c035 (patch)
tree323b60acff59341fc1e18b40e4af7a468ce8ed3b /android/src
parent258a4581f33538781f436f32a7dd9be10a166c25 (diff)
downloadmullvadvpn-04d9870967fb9fc6462c0b9040e99f629219c035.tar.xz
mullvadvpn-04d9870967fb9fc6462c0b9040e99f629219c035.zip
Add state property to `EditCustomDnsServerHolder`
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt32
1 files changed, 24 insertions, 8 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..fcb43bbd5f 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,6 +11,11 @@ import net.mullvad.mullvadvpn.R
import net.mullvad.talpid.util.addressString
class EditCustomDnsServerHolder(view: View, adapter: CustomDnsAdapter) : CustomDnsItemHolder(view) {
+ private enum class State {
+ Normal,
+ Error,
+ }
+
private val context = view.context
private val errorColor = context.getColor(R.color.red)
private val normalColor = context.getColor(R.color.blue)
@@ -25,17 +30,31 @@ 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) { _, _, 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,11 +70,8 @@ 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)
- }
+ adapter.saveDnsServer(input.text.toString(), onFailCallback) {
+ state = State.Error
}
}
}