summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-11-11 19:04:57 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-12-10 12:55:06 +0000
commit2c0a14b0feff2e482562033b037aa37fbd75cdba (patch)
tree97957e181f69852a94e817ed871a298bf71bbc77
parent18fc8cdccdb78794debb5baa1f3fca56ce0d36ed (diff)
downloadmullvadvpn-2c0a14b0feff2e482562033b037aa37fbd75cdba.tar.xz
mullvadvpn-2c0a14b0feff2e482562033b037aa37fbd75cdba.zip
Stop editing when focus is lost
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt22
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt11
2 files changed, 30 insertions, 3 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt
index 81f304154d..f91ae37f7f 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt
@@ -156,6 +156,22 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
}
}
+ fun stopEditing() {
+ if (enabled) {
+ editDnsServerAt(null)
+ }
+ }
+
+ fun stopEditing(address: InetAddress) {
+ if (enabled) {
+ editingPosition?.let { position ->
+ if (cachedCustomDnsServers.getOrNull(position) == address) {
+ editDnsServerAt(null)
+ }
+ }
+ }
+ }
+
fun removeDnsServer(address: InetAddress) {
jobTracker.newUiJob("removeDnsServer $address") {
val position = jobTracker.runOnBackground {
@@ -216,13 +232,15 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
}
}
- private fun editDnsServerAt(position: Int) {
+ private fun editDnsServerAt(position: Int?) {
editingPosition?.let { oldPosition ->
notifyItemChanged(oldPosition)
}
editingPosition = position
- notifyItemChanged(position)
+ position?.let { newPosition ->
+ notifyItemChanged(newPosition)
+ }
}
}
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 5fa6bb7e2e..edebc30266 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
@@ -1,6 +1,7 @@
package net.mullvad.mullvadvpn.ui.customdns
import android.view.View
+import android.view.View.OnFocusChangeListener
import android.widget.EditText
import java.net.InetAddress
import kotlin.properties.Delegates.observable
@@ -8,7 +9,15 @@ import net.mullvad.mullvadvpn.R
import net.mullvad.talpid.util.addressString
class EditCustomDnsServerHolder(view: View, adapter: CustomDnsAdapter) : CustomDnsItemHolder(view) {
- private val input: EditText = view.findViewById(R.id.input)
+ private val input: EditText = view.findViewById<EditText>(R.id.input).apply {
+ onFocusChangeListener = OnFocusChangeListener { _, hasFocus ->
+ if (!hasFocus) {
+ serverAddress?.let { address ->
+ adapter.stopEditing(address)
+ }
+ }
+ }
+ }
var serverAddress by observable<InetAddress?>(null) { _, _, address ->
if (address != null) {