summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-11-05 17:46:51 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-12-10 12:55:06 +0000
commit3e9f03981c7f7079230df8bf67e8d5bf71165cb8 (patch)
tree1f9983a78798ce6555b0252fe057d9f655ecb8e7 /android/src
parent0c9bcd2d2566b4a0efaf5485818638b959522291 (diff)
downloadmullvadvpn-3e9f03981c7f7079230df8bf67e8d5bf71165cb8.tar.xz
mullvadvpn-3e9f03981c7f7079230df8bf67e8d5bf71165cb8.zip
Add custom DNS server address when tick is pressed
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt12
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt12
2 files changed, 22 insertions, 2 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 e527f9e233..f724d4e292 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
@@ -8,6 +8,7 @@ import kotlin.properties.Delegates.observable
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.service.CustomDns
import net.mullvad.mullvadvpn.util.JobTracker
+import org.apache.commons.validator.routines.InetAddressValidator
class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>() {
private enum class ViewTypes {
@@ -17,6 +18,7 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
FOOTER,
}
+ private val inetAddressValidator = InetAddressValidator.getInstance()
private val jobTracker = JobTracker()
private var enteringNewServer = false
@@ -86,7 +88,7 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
}
ViewTypes.EDIT_SERVER -> {
val view = inflater.inflate(R.layout.edit_custom_dns_server, parentView, false)
- return EditCustomDnsServerHolder(view)
+ return EditCustomDnsServerHolder(view, this)
}
ViewTypes.SHOW_SERVER -> {
val view = inflater.inflate(R.layout.custom_dns_server, parentView, false)
@@ -117,4 +119,12 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
notifyItemChanged(count - 2)
}
}
+
+ fun addDnsServer(address: String) {
+ jobTracker.newBackgroundJob("addDnsServer $address") {
+ if (inetAddressValidator.isValid(address)) {
+ customDns.addDnsServer(InetAddress.getByName(address))
+ }
+ }
+ }
}
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
index a55f0b87c2..c0ca781628 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt
@@ -1,5 +1,15 @@
package net.mullvad.mullvadvpn.ui.customdns
import android.view.View
+import android.widget.TextView
+import net.mullvad.mullvadvpn.R
-class EditCustomDnsServerHolder(view: View) : CustomDnsItemHolder(view)
+class EditCustomDnsServerHolder(view: View, adapter: CustomDnsAdapter) : CustomDnsItemHolder(view) {
+ private val input: TextView = view.findViewById(R.id.input)
+
+ init {
+ view.findViewById<View>(R.id.save).setOnClickListener {
+ adapter.addDnsServer(input.text.toString())
+ }
+ }
+}