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