diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt index 0218e06afd80..b93fce2e06c5 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt @@ -40,14 +40,14 @@ private val DUMMY_RELAY_2 = private val DUMMY_RELAY_CITY_1 = RelayItem.Location.City( name = "Relay City 1", - id = GeoLocationId.City(countryCode = GeoLocationId.Country("RCo1"), cityCode = "RCi1"), + id = GeoLocationId.City(country = GeoLocationId.Country("RCo1"), code = "RCi1"), relays = listOf(DUMMY_RELAY_1), expanded = false ) private val DUMMY_RELAY_CITY_2 = RelayItem.Location.City( name = "Relay City 2", - id = GeoLocationId.City(countryCode = GeoLocationId.Country("RCo2"), cityCode = "RCi2"), + id = GeoLocationId.City(country = GeoLocationId.Country("RCo2"), code = "RCi2"), relays = listOf(DUMMY_RELAY_2), expanded = false ) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/preview/RelayItemPreviewData.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/preview/RelayItemPreviewData.kt index 570c39441268..c1b42c9415e3 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/preview/RelayItemPreviewData.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/preview/RelayItemPreviewData.kt @@ -56,7 +56,7 @@ private fun generateRelayItemRelay( id = GeoLocationId.Hostname( city = cityCode, - hostname = hostName, + code = hostName, ), active = active, provider = Provider(ProviderId("Provider"), Ownership.MullvadOwned), @@ -69,6 +69,6 @@ private fun String.generateCityCode(countryCode: GeoLocationId.Country) = GeoLocationId.City(countryCode, take(CITY_CODE_LENGTH).lowercase()) private fun generateHostname(city: GeoLocationId.City, index: Int) = - "${city.countryCode.countryCode}-${city.cityCode}-wg-${index+1}" + "${city.country.code}-${city.code}-wg-${index+1}" private const val CITY_CODE_LENGTH = 3 diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/EditCustomListScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/EditCustomListScreen.kt index c3f7662ea250..2ab962485242 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/EditCustomListScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/EditCustomListScreen.kt @@ -67,7 +67,7 @@ private fun PreviewEditCustomListScreen() { GeoLocationId.Hostname( GeoLocationId.City( GeoLocationId.Country("country"), - cityCode = "city" + code = "city" ), "hostname", ) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt index 94b5ddac0689..0edd689082b7 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt @@ -16,7 +16,7 @@ fun List.newFilterOnSearch( val matchesIds = withDescendants().filter { it.name.contains(searchTerm, ignoreCase = true) }.map { it.id } - val expansionSet = matchesIds.flatMap { it.parents() }.toSet() + val expansionSet = matchesIds.flatMap { it.ancestors() }.toSet() Logger.d("Expansion Set: $expansionSet") val filteredCountryList = mapNotNull { country -> @@ -40,7 +40,7 @@ fun List.newFilterOnSearch( return expansionSet to filteredCountryList } -private fun GeoLocationId.parents(): List = +private fun GeoLocationId.ancestors(): List = when (this) { is GeoLocationId.City -> listOf(country) is GeoLocationId.Country -> emptyList() diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt index 08c6255d19c7..814ef2c4697d 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt @@ -56,9 +56,9 @@ class SelectLocationViewModel( val item = relayListRepository.selectedLocation.value.getOrNull() return when (item) { is CustomListId -> setOf() - is GeoLocationId.City -> setOf(item.countryCode.countryCode) + is GeoLocationId.City -> setOf(item.country.code) is GeoLocationId.Country -> setOf() - is GeoLocationId.Hostname -> setOf(item.country.countryCode, item.city.cityCode) + is GeoLocationId.Hostname -> setOf(item.country.code, item.city.code) null -> setOf() } } @@ -281,9 +281,7 @@ class SelectLocationViewModel( (parent?.value ?: "") + when (this) { is CustomListId -> value - is GeoLocationId.City -> cityCode - is GeoLocationId.Country -> countryCode - is GeoLocationId.Hostname -> hostname + is GeoLocationId -> code } fun selectRelay(relayItem: RelayItem) { diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt index d98292ccd9e2..357689b06a1f 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt @@ -151,7 +151,7 @@ class CustomListActionUseCaseTest { val action = CustomListAction.Delete(id = customListId) val expectedResult = Deleted(undo = action.not(name = name, locations = listOf(location))).right() - every { mockLocation.countryCode } returns location.countryCode + every { mockLocation.code } returns location.code coEvery { mockCustomListsRepository.deleteCustomList(id = customListId) } returns Unit.right() coEvery { mockCustomListsRepository.getCustomListById(customListId) } returns diff --git a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/FromDomain.kt b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/FromDomain.kt index 014bafb85b10..95f3f20f2905 100644 --- a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/FromDomain.kt +++ b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/FromDomain.kt @@ -106,12 +106,12 @@ internal fun GeoLocationId.fromDomain(): ManagementInterface.GeographicLocationC ManagementInterface.GeographicLocationConstraint.newBuilder() .apply { when (val id = this@fromDomain) { - is GeoLocationId.Country -> setCountry(id.countryCode) - is GeoLocationId.City -> setCountry(id.countryCode.countryCode).setCity(id.cityCode) + is GeoLocationId.Country -> setCountry(id.code) + is GeoLocationId.City -> setCountry(id.country.code).setCity(id.code) is GeoLocationId.Hostname -> - setCountry(id.country.countryCode) - .setCity(id.city.cityCode) - .setHostname(id.hostname) + setCountry(id.country.code) + .setCity(id.city.code) + .setHostname(id.code) } } .build() diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/RelayItem.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/RelayItem.kt index ff809a31dde8..17bc563a8ddd 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/RelayItem.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/RelayItem.kt @@ -61,7 +61,7 @@ sealed interface RelayItem { val provider: Provider, override val active: Boolean, ) : Location { - override val name: String = id.hostname + override val name: String = id.code override val hasChildren: Boolean = false companion object diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/RelayItemId.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/RelayItemId.kt index c560fab49c65..26d5b418a01f 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/RelayItemId.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/RelayItemId.kt @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.lib.model import android.os.Parcelable import arrow.optics.optics +import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize @optics @@ -21,28 +22,29 @@ value class CustomListId(val value: String) : RelayItemId, Parcelable { sealed interface GeoLocationId : RelayItemId, Parcelable { @optics @Parcelize - data class Country(val countryCode: String) : GeoLocationId { + data class Country(override val code: String) : GeoLocationId { companion object } @optics @Parcelize - data class City(val countryCode: Country, val cityCode: String) : GeoLocationId { + data class City(override val country: Country, override val code: String) : GeoLocationId { companion object } @optics @Parcelize - data class Hostname(val city: City, val hostname: String) : GeoLocationId { + data class Hostname(val city: City, override val code: String) : GeoLocationId { companion object } + val code: String val country: Country get() = when (this) { is Country -> this - is City -> this.countryCode - is Hostname -> this.city.countryCode + is City -> this.country + is Hostname -> this.city.country } companion object