diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-11-09 19:05:06 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-12-10 12:55:06 +0000 |
| commit | c9e40c26725bc1f73aebc104e479c674ab8d8b6f (patch) | |
| tree | 3500d62f8d764d154cbcd5abf85cbf53b72b4139 /android/src | |
| parent | 9ff4a665f51992386c21122b04cde3549b6045d6 (diff) | |
| download | mullvadvpn-c9e40c26725bc1f73aebc104e479c674ab8d8b6f.tar.xz mullvadvpn-c9e40c26725bc1f73aebc104e479c674ab8d8b6f.zip | |
Show DNS servers and listen for changes
Diffstat (limited to 'android/src')
3 files changed, 78 insertions, 7 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 db89555a8e..e527f9e233 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 @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.ui.customdns import android.support.v7.widget.RecyclerView.Adapter import android.view.LayoutInflater import android.view.ViewGroup +import java.net.InetAddress import kotlin.properties.Delegates.observable import net.mullvad.mullvadvpn.R import net.mullvad.mullvadvpn.service.CustomDns @@ -12,6 +13,7 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>( private enum class ViewTypes { ADD_SERVER, EDIT_SERVER, + SHOW_SERVER, FOOTER, } @@ -19,6 +21,10 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>( private var enteringNewServer = false + private var customDnsServers by observable<List<InetAddress>>(emptyList()) { _, _, _ -> + notifyDataSetChanged() + } + private var enabled by observable(false) { _, oldValue, newValue -> if (oldValue != newValue) { notifyDataSetChanged() @@ -26,16 +32,24 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>( } init { - customDns.onEnabledChanged.subscribe(this) { value -> - jobTracker.newUiJob("updateEnabled") { - enabled = value + customDns.apply { + onDnsServersChanged.subscribe(this) { dnsServers -> + jobTracker.newUiJob("updateDnsServers") { + customDnsServers = dnsServers + } + } + + onEnabledChanged.subscribe(this) { value -> + jobTracker.newUiJob("updateEnabled") { + enabled = value + } } } } override fun getItemCount() = if (enabled) { - 2 + customDnsServers.size + 2 } else { 1 } @@ -54,7 +68,7 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>( return ViewTypes.ADD_SERVER.ordinal } } else { - throw RuntimeException("Too many items in the custom DNS list") + return ViewTypes.SHOW_SERVER.ordinal } } @@ -74,13 +88,24 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>( val view = inflater.inflate(R.layout.edit_custom_dns_server, parentView, false) return EditCustomDnsServerHolder(view) } + ViewTypes.SHOW_SERVER -> { + val view = inflater.inflate(R.layout.custom_dns_server, parentView, false) + return CustomDnsServerHolder(view) + } } } - override fun onBindViewHolder(holder: CustomDnsItemHolder, position: Int) {} + override fun onBindViewHolder(holder: CustomDnsItemHolder, position: Int) { + if (holder is CustomDnsServerHolder) { + holder.serverAddress = customDnsServers[position] + } + } fun onDestroy() { - customDns.onEnabledChanged.unsubscribe(this) + customDns.apply { + onDnsServersChanged.unsubscribe(this) + onEnabledChanged.unsubscribe(this) + } } fun newDnsServer() { 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 new file mode 100644 index 0000000000..06fb4dcede --- /dev/null +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsServerHolder.kt @@ -0,0 +1,15 @@ +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 + +class CustomDnsServerHolder(view: View) : CustomDnsItemHolder(view) { + private val label: TextView = view.findViewById(R.id.label) + + var serverAddress by observable<InetAddress?>(null) { _, _, address -> + label.text = address.toString() + } +} diff --git a/android/src/main/res/layout/custom_dns_server.xml b/android/src/main/res/layout/custom_dns_server.xml new file mode 100644 index 0000000000..54d7e9f01e --- /dev/null +++ b/android/src/main/res/layout/custom_dns_server.xml @@ -0,0 +1,31 @@ +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@color/blue40" + android:orientation="horizontal"> + <TextView android:id="@+id/label" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_marginLeft="54dp" + android:layout_marginVertical="14dp" + android:background="?android:attr/selectableItemBackground" + android:gravity="center_vertical" + android:textColor="@color/white" + android:textSize="@dimen/text_medium" /> + <View android:id="@+id/click_area" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_alignParentLeft="true" + android:layout_alignParentRight="true" + android:focusable="true" + android:clickable="true" + android:background="?android:attr/selectableItemBackground" /> + <ImageButton android:id="@+id/remove" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_gravity="right" + android:paddingHorizontal="16dp" + android:paddingVertical="14dp" + android:background="?android:attr/selectableItemBackground" + android:src="@drawable/icon_close" /> +</FrameLayout> |
