diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt index b7f23ea76849..fec20ceb185c 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt @@ -18,7 +18,6 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/Relay.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/Relay.kt index f3c3a3cc7cc6..9bdb59168b1a 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/Relay.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/Relay.kt @@ -12,7 +12,5 @@ data class Relay( override val type = RelayItemType.Relay override val hasChildren = false - override var expanded - get() = false - set(_) {} + override val expanded = false } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt index d1a3332a78b6..e3693963f81f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt @@ -6,7 +6,7 @@ data class RelayCity( override val name: String, override val code: String, override val location: GeographicLocationConstraint, - override var expanded: Boolean, + override val expanded: Boolean, val relays: List ) : RelayItem { override val type = RelayItemType.City diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt index d418fd3a4ae3..3ad1d5962fcc 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt @@ -5,7 +5,7 @@ import net.mullvad.mullvadvpn.model.GeographicLocationConstraint data class RelayCountry( override val name: String, override val code: String, - override var expanded: Boolean, + override val expanded: Boolean, val cities: List ) : RelayItem { override val type = RelayItemType.Country diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt index f4387e96471c..3d38d6b0685d 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt @@ -13,5 +13,5 @@ interface RelayItem { val locationName: String get() = name - var expanded: Boolean + val expanded: Boolean } 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 401f03d744d3..39618f96034e 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 @@ -122,8 +122,9 @@ fun List.filterOnSearchTerm( // Finally if the city has not already been added to the filtered list, add it, but // do not expand it yet. if (relayCity.name.contains(other = searchTerm, ignoreCase = true)) { - if (filteredCountries.containsKey(relayCountry.code)) { - filteredCountries[relayCountry.code]?.expanded = true + val value = filteredCountries[relayCountry.code] + if (value != null) { + filteredCountries[relayCountry.code] = value.copy(expanded = true) } else { filteredCountries[relayCountry.code] = relayCountry.copy(expanded = true, cities = cities) @@ -141,15 +142,23 @@ fun List.filterOnSearchTerm( // if so expand it, if not add it to the filtered list and expand it. // Finally add the relay to the list. if (relay.name.contains(other = searchTerm, ignoreCase = true)) { - if (filteredCountries.containsKey(relayCountry.code)) { - filteredCountries[relayCountry.code]?.expanded = true + val value = filteredCountries[relayCountry.code] + if (value != null) { + filteredCountries[relayCountry.code] = value.copy(expanded = true) } else { filteredCountries[relayCountry.code] = relayCountry.copy(expanded = true, cities = cities) } - val city = cities.find { it.code == relayCity.code } - city?.let { city.expanded = true } - ?: run { cities.add(relayCity.copy(expanded = true, relays = relays)) } + val cityIndex = cities.indexOfFirst { it.code == relayCity.code } + + // No city found + if (cityIndex < 0) { + cities.add(relayCity.copy(expanded = true, relays = relays)) + } else { + // Update found city as expanded + cities[cityIndex] = cities[cityIndex].copy(expanded = true) + } + relays.add(relay.copy()) } } diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt index bd5bfb9605d1..991ae7dbdeef 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt @@ -1,6 +1,6 @@ package net.mullvad.mullvadvpn.model data class RelayConstraintsUpdate( - var location: Constraint?, - var wireguardConstraints: WireguardConstraints? + val location: Constraint?, + val wireguardConstraints: WireguardConstraints? ) diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelaySettingsUpdate.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelaySettingsUpdate.kt index a7d4c0b03d0a..f8d27f115e37 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelaySettingsUpdate.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelaySettingsUpdate.kt @@ -3,5 +3,5 @@ package net.mullvad.mullvadvpn.model sealed class RelaySettingsUpdate { object CustomTunnelEndpoint : RelaySettingsUpdate() - data class Normal(var constraints: RelayConstraintsUpdate) : RelaySettingsUpdate() + data class Normal(val constraints: RelayConstraintsUpdate) : RelaySettingsUpdate() } diff --git a/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/classes/DataClassTests.kt b/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/classes/DataClassTests.kt index 248eef5a1006..50bd21057ee4 100644 --- a/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/classes/DataClassTests.kt +++ b/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/classes/DataClassTests.kt @@ -3,11 +3,9 @@ package net.mullvad.mullvadvpn.test.arch.classes import com.lemonappdev.konsist.api.ext.list.modifierprovider.withDataModifier import com.lemonappdev.konsist.api.verify.assert import net.mullvad.mullvadvpn.test.arch.extensions.projectScope -import org.junit.Ignore import org.junit.Test class DataClasses { - @Ignore("Code needs clean up") @Test fun `data classes use only immutable parameters`() { projectScope().classes(includeNested = true).withDataModifier().assert { diff --git a/android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/MockApiDispatcher.kt b/android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/MockApiDispatcher.kt index 06f716403465..6a604bb09f53 100644 --- a/android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/MockApiDispatcher.kt +++ b/android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/MockApiDispatcher.kt @@ -8,7 +8,10 @@ import net.mullvad.mullvadvpn.test.mockapi.constant.DUMMY_ACCESS_TOKEN import net.mullvad.mullvadvpn.test.mockapi.constant.DUMMY_DEVICE_NAME import net.mullvad.mullvadvpn.test.mockapi.constant.DUMMY_ID import net.mullvad.mullvadvpn.test.mockapi.constant.LOG_TAG +import net.mullvad.mullvadvpn.test.mockapi.util.accessTokenJsonResponse +import net.mullvad.mullvadvpn.test.mockapi.util.accountInfoJson import net.mullvad.mullvadvpn.test.mockapi.util.currentUtcTimeWithOffsetZero +import net.mullvad.mullvadvpn.test.mockapi.util.deviceJson import okhttp3.mockwebserver.Dispatcher import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.RecordedRequest