diff options
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt | 16 |
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] } } |
