summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-08-07 14:26:17 +0200
committerLinus Färnstrand <linus@mullvad.net>2022-08-10 16:22:10 +0200
commit880b529651f2db43d51c44d65576aa3ce315f05a (patch)
tree7acded131a013a865a07cc14085290ffbda2d004 /android
parentc4683d6a5a6d37280b2ae685c79ccb89d260fdb1 (diff)
downloadmullvadvpn-880b529651f2db43d51c44d65576aa3ce315f05a.tar.xz
mullvadvpn-880b529651f2db43d51c44d65576aa3ce315f05a.zip
Set custom dns toggle in onStart
Diffstat (limited to 'android')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt22
1 files changed, 9 insertions, 13 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt
index 30b9608a9d..4e3fff52c9 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt
@@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.launch
import net.mullvad.mullvadvpn.R
@@ -56,7 +57,7 @@ class AdvancedFragment : BaseFragment() {
@Deprecated("Refactor code to instead rely on Lifecycle.")
private val jobTracker = JobTracker()
- val shared = serviceConnectionManager.connectionState
+ val sharedCustomDnsInstance = serviceConnectionManager.connectionState
.flatMapLatest { state ->
if (state is ServiceConnectionState.ConnectedReady) {
flowOf(state.container)
@@ -93,9 +94,12 @@ class AdvancedFragment : BaseFragment() {
}
launch {
- shared
- .flatMapLatest {
- callbackFlowFromNotifier(it.onEnabledChanged)
+ sharedCustomDnsInstance
+ .flatMapLatest { customDnsInstance ->
+ callbackFlowFromNotifier(customDnsInstance.onEnabledChanged)
+ .onStart {
+ emit(customDnsInstance.isCustomDnsEnabled())
+ }
}
.collect { isEnabled ->
customDnsAdapter?.updateState(isEnabled)
@@ -110,7 +114,7 @@ class AdvancedFragment : BaseFragment() {
}
launch {
- shared
+ sharedCustomDnsInstance
.flatMapLatest {
callbackFlowFromNotifier(it.onDnsServersChanged)
}
@@ -206,14 +210,6 @@ class AdvancedFragment : BaseFragment() {
}
customDnsToggle = view.findViewById<ToggleCell>(R.id.enable_custom_dns).apply {
- state = serviceConnectionManager.customDns().let { customDns ->
- if (customDns?.isCustomDnsEnabled() == true) {
- CellSwitch.State.ON
- } else {
- CellSwitch.State.OFF
- }
- }
-
listener = { state ->
jobTracker.newBackgroundJob("toggleCustomDns") {
if (state == CellSwitch.State.ON) {