summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-11-03 20:49:19 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-12-10 12:55:06 +0000
commit38f5b2a84c4c6b31ca51bd6a4c10c63a8bdcdc89 (patch)
treeb5f75d43a2bd52b6fee40fad283cd89d332e463f /android/src
parent49d330adb3b636901af07c8950c428541d1507d1 (diff)
downloadmullvadvpn-38f5b2a84c4c6b31ca51bd6a4c10c63a8bdcdc89.tar.xz
mullvadvpn-38f5b2a84c4c6b31ca51bd6a4c10c63a8bdcdc89.zip
Show "Add a server" row when enabled
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/AddCustomDnsServerHolder.kt5
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt38
-rw-r--r--android/src/main/res/drawable/icon_add.xml7
-rw-r--r--android/src/main/res/layout/add_custom_dns_server.xml31
-rw-r--r--android/src/main/res/values/strings.xml1
5 files changed, 78 insertions, 4 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/AddCustomDnsServerHolder.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/AddCustomDnsServerHolder.kt
new file mode 100644
index 0000000000..5ea8f49e96
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/AddCustomDnsServerHolder.kt
@@ -0,0 +1,5 @@
+package net.mullvad.mullvadvpn.ui.customdns
+
+import android.view.View
+
+class AddCustomDnsServerHolder(view: View) : CustomDnsItemHolder(view)
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 429a6f98fa..5516329f75 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,14 +3,24 @@ package net.mullvad.mullvadvpn.ui.customdns
import android.support.v7.widget.RecyclerView.Adapter
import android.view.LayoutInflater
import android.view.ViewGroup
+import kotlin.properties.Delegates.observable
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.service.CustomDns
import net.mullvad.mullvadvpn.util.JobTracker
class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>() {
+ private enum class ViewTypes {
+ ADD_SERVER,
+ FOOTER,
+ }
+
private val jobTracker = JobTracker()
- private var enabled = false
+ private var enabled by observable(false) { _, oldValue, newValue ->
+ if (oldValue != newValue) {
+ notifyDataSetChanged()
+ }
+ }
init {
customDns.onEnabledChanged.subscribe(this) { value ->
@@ -20,13 +30,33 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
}
}
- override fun getItemCount() = 1
+ override fun getItemCount() = if (enabled) { 2 } else { 1 }
+
+ override fun getItemViewType(position: Int): Int {
+ if (enabled) {
+ if (position == 0) {
+ return ViewTypes.ADD_SERVER.ordinal
+ } else {
+ return ViewTypes.FOOTER.ordinal
+ }
+ } else {
+ return ViewTypes.FOOTER.ordinal
+ }
+ }
override fun onCreateViewHolder(parentView: ViewGroup, type: Int): CustomDnsItemHolder {
val inflater = LayoutInflater.from(parentView.context)
- val view = inflater.inflate(R.layout.custom_dns_footer, parentView, false)
- return CustomDnsFooterHolder(view)
+ when (ViewTypes.values()[type]) {
+ ViewTypes.FOOTER -> {
+ val view = inflater.inflate(R.layout.custom_dns_footer, parentView, false)
+ return CustomDnsFooterHolder(view)
+ }
+ ViewTypes.ADD_SERVER -> {
+ val view = inflater.inflate(R.layout.add_custom_dns_server, parentView, false)
+ return AddCustomDnsServerHolder(view)
+ }
+ }
}
override fun onBindViewHolder(holder: CustomDnsItemHolder, position: Int) {}
diff --git a/android/src/main/res/drawable/icon_add.xml b/android/src/main/res/drawable/icon_add.xml
new file mode 100644
index 0000000000..f44a660a95
--- /dev/null
+++ b/android/src/main/res/drawable/icon_add.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<rotate xmlns:android="http://schemas.android.com/apk/res/android"
+ android:fromDegrees="45"
+ android:toDegrees="45"
+ android:pivotX="50%"
+ android:pivotY="50%"
+ android:drawable="@drawable/icon_close" />
diff --git a/android/src/main/res/layout/add_custom_dns_server.xml b/android/src/main/res/layout/add_custom_dns_server.xml
new file mode 100644
index 0000000000..892b48a6fe
--- /dev/null
+++ b/android/src/main/res/layout/add_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: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"
+ android:text="@string/add_a_server" />
+ <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/add"
+ 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_add" />
+</FrameLayout>
diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml
index 1e4802e972..95fc366713 100644
--- a/android/src/main/res/values/strings.xml
+++ b/android/src/main/res/values/strings.xml
@@ -165,6 +165,7 @@
applications should not be routed through the VPN tunnel.</string>
<string name="enable">Enable</string>
<string name="enable_custom_dns">Use custom DNS server</string>
+ <string name="add_a_server">Add a server</string>
<string name="custom_dns_footer">Enable to add at least one DNS server.</string>
<string name="exclude_applications">Exclude applications</string>
<string name="account_url">https://mullvad.net/en/account</string>