@@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.SharingStarted
16
16
import kotlinx.coroutines.flow.StateFlow
17
17
import kotlinx.coroutines.flow.combine
18
18
import kotlinx.coroutines.flow.filterNotNull
19
+ import kotlinx.coroutines.flow.first
19
20
import kotlinx.coroutines.flow.receiveAsFlow
20
21
import kotlinx.coroutines.flow.stateIn
21
22
import kotlinx.coroutines.launch
@@ -55,11 +56,12 @@ class DnsDialogViewModel(
55
56
) : ViewModel() {
56
57
private val navArgs = DnsDestination .argsFrom(savedStateHandle)
57
58
59
+ private val settings = MutableStateFlow <Settings ?>(null )
58
60
private val currentIndex = MutableStateFlow (navArgs.index)
59
61
private val _ipAddressInput = MutableStateFlow (navArgs.initialValue ? : EMPTY_STRING )
60
62
61
63
val uiState: StateFlow <DnsDialogViewState > =
62
- combine(_ipAddressInput , currentIndex, repository.settingsUpdates .filterNotNull()) {
64
+ combine(_ipAddressInput , currentIndex, settings .filterNotNull()) {
63
65
input,
64
66
currentIndex,
65
67
settings ->
@@ -74,6 +76,10 @@ class DnsDialogViewModel(
74
76
private val _uiSideEffect = Channel <DnsDialogSideEffect >()
75
77
val uiSideEffect = _uiSideEffect .receiveAsFlow()
76
78
79
+ init {
80
+ viewModelScope.launch { settings.emit(repository.settingsUpdates.filterNotNull().first()) }
81
+ }
82
+
77
83
private fun createViewState (
78
84
customDnsList : List <InetAddress >,
79
85
currentIndex : Int? ,
@@ -116,7 +122,7 @@ class DnsDialogViewModel(
116
122
if (index != null ) {
117
123
repository.setCustomDns(index = index, address = address)
118
124
} else {
119
- repository.addCustomDns(address = address).onRight { currentIndex.value = it }
125
+ repository.addCustomDns(address = address)
120
126
}
121
127
122
128
result.fold(
0 commit comments