summaryrefslogtreecommitdiffhomepage
path: root/android/app/src
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2024-02-07 23:30:19 +0100
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2024-02-08 10:50:58 +0100
commita63afba8c2f3912185fbc5ed17c351e0a3701dd3 (patch)
tree2e3cfa28d7945e30f98f90ccecbbb4b9a7f621df /android/app/src
parent52a9cf9686756b366c5e1d8359f5a2b37c18df8a (diff)
downloadmullvadvpn-a63afba8c2f3912185fbc5ed17c351e0a3701dd3.tar.xz
mullvadvpn-a63afba8c2f3912185fbc5ed17c351e0a3701dd3.zip
Add customlists support for RelayListUseCase
Diffstat (limited to 'android/app/src')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/RelayListUseCase.kt36
1 files changed, 26 insertions, 10 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/RelayListUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/RelayListUseCase.kt
index 8db90b9390..ab3d93e06e 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/RelayListUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/RelayListUseCase.kt
@@ -3,16 +3,15 @@ package net.mullvad.mullvadvpn.usecase
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
-import net.mullvad.mullvadvpn.lib.common.util.toGeographicLocationConstraint
import net.mullvad.mullvadvpn.model.Constraint
-import net.mullvad.mullvadvpn.model.GeographicLocationConstraint
+import net.mullvad.mullvadvpn.model.LocationConstraint
import net.mullvad.mullvadvpn.model.RelaySettings
import net.mullvad.mullvadvpn.model.WireguardConstraints
-import net.mullvad.mullvadvpn.relaylist.RelayCountry
import net.mullvad.mullvadvpn.relaylist.RelayItem
import net.mullvad.mullvadvpn.relaylist.RelayList
-import net.mullvad.mullvadvpn.relaylist.findItemForLocation
+import net.mullvad.mullvadvpn.relaylist.findItemForGeographicLocationConstraint
import net.mullvad.mullvadvpn.relaylist.toRelayCountries
+import net.mullvad.mullvadvpn.relaylist.toRelayItemLists
import net.mullvad.mullvadvpn.repository.SettingsRepository
import net.mullvad.mullvadvpn.ui.serviceconnection.RelayListListener
@@ -21,7 +20,7 @@ class RelayListUseCase(
private val settingsRepository: SettingsRepository
) {
- fun updateSelectedRelayLocation(value: GeographicLocationConstraint) {
+ fun updateSelectedRelayLocation(value: LocationConstraint) {
relayListListener.updateSelectedRelayLocation(value)
}
@@ -39,11 +38,15 @@ class RelayListUseCase(
settings?.relaySettings?.relayConstraints()?.providers ?: Constraint.Any()
val relayCountries =
relayList.toRelayCountries(ownership = ownership, providers = providers)
+ val customLists =
+ settings?.customLists?.customLists?.toRelayItemLists(relayCountries) ?: emptyList()
val selectedItem =
- relayCountries.findSelectedRelayItem(
+ findSelectedRelayItem(
relaySettings = settings?.relaySettings,
+ relayCountries = relayCountries,
+ customLists = customLists
)
- RelayList(relayCountries, selectedItem)
+ RelayList(customLists, relayCountries, selectedItem)
}
fun selectedRelayItem(): Flow<RelayItem?> = relayListWithSelection().map { it.selectedItem }
@@ -52,10 +55,23 @@ class RelayListUseCase(
relayListListener.fetchRelayList()
}
- private fun List<RelayCountry>.findSelectedRelayItem(
+ private fun findSelectedRelayItem(
relaySettings: RelaySettings?,
+ relayCountries: List<RelayItem.Country>,
+ customLists: List<RelayItem.CustomList>
): RelayItem? {
- val location = relaySettings?.relayConstraints()?.location
- return location?.let { this.findItemForLocation(location.toGeographicLocationConstraint()) }
+ val locationConstraint = relaySettings?.relayConstraints()?.location
+ return if (locationConstraint is Constraint.Only) {
+ when (val location = locationConstraint.value) {
+ is LocationConstraint.CustomList -> {
+ customLists.firstOrNull { it.id == location.listId }
+ }
+ is LocationConstraint.Location -> {
+ relayCountries.findItemForGeographicLocationConstraint(location.location)
+ }
+ }
+ } else {
+ null
+ }
}
}