summaryrefslogtreecommitdiffhomepage
path: root/android/src/main
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-11-04 17:37:53 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-12-10 12:55:06 +0000
commitb230c0c712aadbffddd225cb0cc5ce77b4346b65 (patch)
tree9bee7bf9730b1491aaa725a19e0b8eb7e4d862d5 /android/src/main
parent38f5b2a84c4c6b31ca51bd6a4c10c63a8bdcdc89 (diff)
downloadmullvadvpn-b230c0c712aadbffddd225cb0cc5ce77b4346b65.tar.xz
mullvadvpn-b230c0c712aadbffddd225cb0cc5ce77b4346b65.zip
Create row to edit custom DNS address
Diffstat (limited to 'android/src/main')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt30
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt5
-rw-r--r--android/src/main/res/drawable/icon_tick_green.xml11
-rw-r--r--android/src/main/res/layout/edit_custom_dns_server.xml30
-rw-r--r--android/src/main/res/values/strings.xml1
5 files changed, 71 insertions, 6 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 5516329f75..7a48b2485b 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
@@ -11,11 +11,14 @@ import net.mullvad.mullvadvpn.util.JobTracker
class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>() {
private enum class ViewTypes {
ADD_SERVER,
+ EDIT_SERVER,
FOOTER,
}
private val jobTracker = JobTracker()
+ private var enteringNewServer = false
+
private var enabled by observable(false) { _, oldValue, newValue ->
if (oldValue != newValue) {
notifyDataSetChanged()
@@ -30,17 +33,28 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
}
}
- override fun getItemCount() = if (enabled) { 2 } else { 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
+ val count = getItemCount()
+ val footer = count - 1
+ val addServerOrNewServer = count - 2
+
+ if (position == footer) {
+ return ViewTypes.FOOTER.ordinal
+ } else if (position == addServerOrNewServer) {
+ if (enteringNewServer) {
+ return ViewTypes.EDIT_SERVER.ordinal
} else {
- return ViewTypes.FOOTER.ordinal
+ return ViewTypes.ADD_SERVER.ordinal
}
} else {
- return ViewTypes.FOOTER.ordinal
+ throw RuntimeException("Too many items in the custom DNS list")
}
}
@@ -56,6 +70,10 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
val view = inflater.inflate(R.layout.add_custom_dns_server, parentView, false)
return AddCustomDnsServerHolder(view)
}
+ ViewTypes.EDIT_SERVER -> {
+ val view = inflater.inflate(R.layout.edit_custom_dns_server, parentView, false)
+ return EditCustomDnsServerHolder(view)
+ }
}
}
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
new file mode 100644
index 0000000000..a55f0b87c2
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt
@@ -0,0 +1,5 @@
+package net.mullvad.mullvadvpn.ui.customdns
+
+import android.view.View
+
+class EditCustomDnsServerHolder(view: View) : CustomDnsItemHolder(view)
diff --git a/android/src/main/res/drawable/icon_tick_green.xml b/android/src/main/res/drawable/icon_tick_green.xml
new file mode 100644
index 0000000000..a761a863ba
--- /dev/null
+++ b/android/src/main/res/drawable/icon_tick_green.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <group>
+ <path android:fillColor="@color/green"
+ android:pathData="M2.92646877,10.7979185 C2.25699855,10.1340272 1.17157288,10.1340272 0.502102661,10.7979185 C-0.167367554,11.4618098 -0.167367554,12.5381902 0.502102661,13.2020815 L7.35924552,20.0020815 C8.02871573,20.6659728 9.11414141,20.6659728 9.78361162,20.0020815 L23.4978973,6.40208153 C24.1673676,5.73819023 24.1673676,4.66180977 23.4978973,3.99791847 C22.8284271,3.33402718 21.7430014,3.33402718 21.0735312,3.99791847 L8.57142857,16.3958369 L2.92646877,10.7979185 Z" />
+ </group>
+</vector>
diff --git a/android/src/main/res/layout/edit_custom_dns_server.xml b/android/src/main/res/layout/edit_custom_dns_server.xml
new file mode 100644
index 0000000000..91090efb9e
--- /dev/null
+++ b/android/src/main/res/layout/edit_custom_dns_server.xml
@@ -0,0 +1,30 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="@color/white"
+ android:orientation="horizontal">
+ <EditText android:id="@+id/input"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:layout_marginLeft="54dp"
+ android:layout_marginVertical="14dp"
+ android:gravity="center_vertical"
+ android:background="@android:color/transparent"
+ android:singleLine="true"
+ android:imeOptions="flagNoPersonalizedLearning"
+ android:textCursorDrawable="@drawable/text_input_cursor"
+ android:textColorHint="@color/blue60"
+ android:textColor="@color/blue"
+ android:textSize="@dimen/text_medium"
+ android:hint="@string/custom_dns_example" />
+ <ImageButton android:id="@+id/save"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_weight="0"
+ android:layout_gravity="right"
+ android:paddingHorizontal="16dp"
+ android:paddingVertical="14dp"
+ android:background="?android:attr/selectableItemBackground"
+ android:src="@drawable/icon_tick_green" />
+</LinearLayout>
diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml
index 95fc366713..fb442a9e9b 100644
--- a/android/src/main/res/values/strings.xml
+++ b/android/src/main/res/values/strings.xml
@@ -166,6 +166,7 @@
<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_example">e.g. 123.456.789.111</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>