summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-03-17 22:49:59 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-03-18 12:08:46 +0000
commit350c25bd08d4fe4335148039d3d848cdec431ca1 (patch)
treeea838de02c550b1779cfee7bcb885abcd44cf3eb /android
parent35c5e29341c15f70e358b54c0e536255edaa654e (diff)
downloadmullvadvpn-350c25bd08d4fe4335148039d3d848cdec431ca1.tar.xz
mullvadvpn-350c25bd08d4fe4335148039d3d848cdec431ca1.zip
Refactor to move confirmation check logic
Move it out of the `CustomDnsAdapter` and into the `AdvancedFragment`.
Diffstat (limited to 'android')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt17
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt18
2 files changed, 17 insertions, 18 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt
index 8e241ace49..07cadf5e0e 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt
@@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
+import java.net.InetAddress
import kotlinx.coroutines.CompletableDeferred
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.model.Settings
@@ -37,9 +38,7 @@ class AdvancedFragment : ServiceDependentFragment(OnNoService.GoBack) {
titleController = CollapsibleTitleController(view, R.id.contents)
customDnsAdapter = CustomDnsAdapter(customDns).apply {
- showPublicDnsAddressWarning = { confirmation ->
- showConfirmPublicDnsServerDialog(confirmation)
- }
+ confirmAddAddress = ::confirmAddAddress
}
view.findViewById<CustomRecyclerView>(R.id.contents).apply {
@@ -123,6 +122,18 @@ class AdvancedFragment : ServiceDependentFragment(OnNoService.GoBack) {
}
}
+ private suspend fun confirmAddAddress(address: InetAddress): Boolean {
+ if (address.isLinkLocalAddress() || address.isSiteLocalAddress()) {
+ return true
+ }
+
+ val confirmation = CompletableDeferred<Boolean>()
+
+ showConfirmPublicDnsServerDialog(confirmation)
+
+ return confirmation.await()
+ }
+
private fun showConfirmPublicDnsServerDialog(confirmation: CompletableDeferred<Boolean>) {
val transaction = parentFragmentManager.beginTransaction()
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 0bb528c623..c66fc04848 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
@@ -5,7 +5,6 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.Adapter
import java.net.InetAddress
import kotlin.properties.Delegates.observable
-import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import net.mullvad.mullvadvpn.R
@@ -55,7 +54,8 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
val isEditing
get() = editingPosition != null
- var showPublicDnsAddressWarning: ((CompletableDeferred<Boolean>) -> Unit)? = null
+ // By default, refuse the address so that the dialog can be recreated by the user if needed
+ var confirmAddAddress: suspend (InetAddress) -> Boolean = { false }
init {
customDns.apply {
@@ -286,22 +286,10 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>(
if (inetAddressValidator.isValid(addressText)) {
val address = InetAddress.getByName(addressText)
- if (!address.isLoopbackAddress() && confirmAddIfPublicAddress(address)) {
+ if (!address.isLoopbackAddress() && confirmAddAddress(address)) {
handler(address)
}
}
}
}
-
- private suspend fun confirmAddIfPublicAddress(address: InetAddress): Boolean {
- if (address.isLinkLocalAddress() || address.isSiteLocalAddress()) {
- return true
- }
-
- val confirmation = CompletableDeferred<Boolean>()
-
- showPublicDnsAddressWarning?.invoke(confirmation)
-
- return confirmation.await()
- }
}