summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-11-10 17:59:57 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-12-10 12:55:06 +0000
commit78af944e5262edc4f7c9209eadacf40c517890fc (patch)
tree98c2145f5da4d8522336eb21511098adc685c49e /android/src
parente0fb1fc375d5448a1fb3214244807706d4759041 (diff)
downloadmullvadvpn-78af944e5262edc4f7c9209eadacf40c517890fc.tar.xz
mullvadvpn-78af944e5262edc4f7c9209eadacf40c517890fc.zip
Create a mirror of custom DNS server list
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt16
1 files changed, 11 insertions, 5 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 eb35e36005..2b97b1d04f 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
@@ -23,10 +23,16 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
private var enteringNewServer = false
- private var customDnsServers by observable<List<InetAddress>>(emptyList()) { _, _, _ ->
- notifyDataSetChanged()
+ private var activeCustomDnsServers
+ by observable<List<InetAddress>>(emptyList()) { _, _, servers ->
+ if (servers != cachedCustomDnsServers) {
+ cachedCustomDnsServers = servers.toMutableList()
+ notifyDataSetChanged()
+ }
}
+ private var cachedCustomDnsServers = emptyList<InetAddress>().toMutableList()
+
private var enabled by observable(false) { _, oldValue, newValue ->
if (oldValue != newValue) {
notifyDataSetChanged()
@@ -37,7 +43,7 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
customDns.apply {
onDnsServersChanged.subscribe(this) { dnsServers ->
jobTracker.newUiJob("updateDnsServers") {
- customDnsServers = dnsServers
+ activeCustomDnsServers = dnsServers
}
}
@@ -51,7 +57,7 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
override fun getItemCount() =
if (enabled) {
- customDnsServers.size + 2
+ cachedCustomDnsServers.size + 2
} else {
1
}
@@ -99,7 +105,7 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
override fun onBindViewHolder(holder: CustomDnsItemHolder, position: Int) {
if (holder is CustomDnsServerHolder) {
- holder.serverAddress = customDnsServers[position]
+ holder.serverAddress = cachedCustomDnsServers[position]
}
}