summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
Diffstat (limited to 'android')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt13
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt4
2 files changed, 11 insertions, 6 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt
index 3df2b2f623..7fa101a8e3 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt
@@ -97,8 +97,9 @@ class CustomListLocationsViewModel(
val (exp, filteredRelayCountries) = relayCountries.newFilterOnSearch(searchTerm)
exp.toSet() to filteredRelayCountries
} else {
- initialExpands((_selectedLocations.value ?: emptyList()).toSet()) to
- relayCountries
+ initialExpands(
+ _selectedLocations.value?.calculateLocationsToSave() ?: emptyList()
+ ) to relayCountries
}
}
.onEach { _expandedItems.value = it.first }
@@ -223,16 +224,16 @@ class CustomListLocationsViewModel(
}
private suspend fun fetchInitialSelectedLocations() {
- val selectedLocations =
- customListRelayItemsUseCase(navArgs.customListId).first().withDescendants().toSet()
+ val locations = customListRelayItemsUseCase(navArgs.customListId).first()
+ val selectedLocations = locations.withDescendants().toSet()
_initialLocations.value = selectedLocations
_selectedLocations.value = selectedLocations
// Initial expand
- _expandedItems.value = initialExpands(selectedLocations)
+ _expandedItems.value = initialExpands(locations)
}
- private fun initialExpands(locations: Set<RelayItem.Location>): Set<RelayItemId> =
+ private fun initialExpands(locations: List<RelayItem.Location>): Set<RelayItemId> =
locations.flatMap { it.id.ancestors() }.toSet()
private fun List<RelayItem.Location>.toRelayItems(
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt
index d2eaedd8c2..f73dbee7a3 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt
@@ -133,8 +133,10 @@ class CustomListLocationsViewModelTest {
// Act, Assert
viewModel.uiState.test {
+ awaitItem()
// Expand country
viewModel.onExpand(DUMMY_COUNTRIES[0], true)
+ awaitItem()
// Expand city
viewModel.onExpand(DUMMY_COUNTRIES[0].cities[0], true)
// Check initial selected
@@ -164,8 +166,10 @@ class CustomListLocationsViewModelTest {
// Act, Assert
viewModel.uiState.test {
+ awaitItem()
// Expand country
viewModel.onExpand(DUMMY_COUNTRIES[0], true)
+ awaitItem()
// Expand city
viewModel.onExpand(DUMMY_COUNTRIES[0].cities[0], true)
// Check initial selected