summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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) {