summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-11-10 21:45:26 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-12-10 12:55:06 +0000
commitb5b0a18da7b0a54c91b8fb70b77f47a1651a347c (patch)
treec6f1999da15b316cd4e720a9cde75b028c17b522 /android/src
parentc3d3843e6aab553b170ff714a57b74437dc5f93d (diff)
downloadmullvadvpn-b5b0a18da7b0a54c91b8fb70b77f47a1651a347c.tar.xz
mullvadvpn-b5b0a18da7b0a54c91b8fb70b77f47a1651a347c.zip
Allow changing a custom DNS server address
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt28
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsServerHolder.kt6
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt7
3 files changed, 38 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 d7d9a5813e..38950a6b06 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
@@ -104,6 +104,12 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
override fun onBindViewHolder(holder: CustomDnsItemHolder, position: Int) {
if (holder is CustomDnsServerHolder) {
holder.serverAddress = cachedCustomDnsServers[position]
+ } else if (holder is EditCustomDnsServerHolder) {
+ if (position >= cachedCustomDnsServers.size) {
+ holder.serverAddress = null
+ } else {
+ holder.serverAddress = cachedCustomDnsServers[position]
+ }
}
}
@@ -118,9 +124,7 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
if (enabled) {
val count = getItemCount()
- editingPosition = count - 2
-
- notifyItemChanged(count - 2)
+ editDnsServerAt(count - 2)
}
}
@@ -136,6 +140,14 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
}
}
+ fun editDnsServer(address: InetAddress) {
+ if (enabled) {
+ val position = cachedCustomDnsServers.indexOf(address)
+
+ editDnsServerAt(position)
+ }
+ }
+
fun removeDnsServer(address: InetAddress) {
jobTracker.newBackgroundJob("removeDnsServer $address") {
customDns.removeDnsServer(address)
@@ -186,4 +198,14 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
notifyItemChanged(position)
}
}
+
+ private fun editDnsServerAt(position: Int) {
+ editingPosition?.let { oldPosition ->
+ notifyItemChanged(oldPosition)
+ }
+
+ editingPosition = position
+
+ notifyItemChanged(position)
+ }
}
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsServerHolder.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsServerHolder.kt
index 967077818e..49efad9310 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsServerHolder.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsServerHolder.kt
@@ -15,6 +15,12 @@ class CustomDnsServerHolder(view: View, adapter: CustomDnsAdapter) : CustomDnsIt
}
init {
+ view.findViewById<View>(R.id.click_area).setOnClickListener {
+ serverAddress?.let { address ->
+ adapter.editDnsServer(address)
+ }
+ }
+
view.findViewById<View>(R.id.remove).setOnClickListener {
serverAddress?.let { address ->
adapter.removeDnsServer(address)
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 d2decf9241..f2022dd10d 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
@@ -2,11 +2,18 @@ package net.mullvad.mullvadvpn.ui.customdns
import android.view.View
import android.widget.TextView
+import java.net.InetAddress
+import kotlin.properties.Delegates.observable
import net.mullvad.mullvadvpn.R
+import net.mullvad.talpid.util.addressString
class EditCustomDnsServerHolder(view: View, adapter: CustomDnsAdapter) : CustomDnsItemHolder(view) {
private val input: TextView = view.findViewById(R.id.input)
+ var serverAddress by observable<InetAddress?>(null) { _, _, address ->
+ input.text = address?.addressString() ?: ""
+ }
+
init {
view.findViewById<View>(R.id.save).setOnClickListener {
adapter.saveDnsServer(input.text.toString())