diff options
| author | David Göransson <david.goransson90@gmail.com> | 2023-10-02 08:25:15 +0200 |
|---|---|---|
| committer | David Göransson <david.goransson90@gmail.com> | 2023-10-02 16:06:03 +0200 |
| commit | 23517aa5dda6ba8360a6fa9ce408aa63ae5751ce (patch) | |
| tree | 7bccfc5398403de5cc4f4fdf02fc12cb7fef5a5b /android/app | |
| parent | 469e0efbec57ce256973d1329f5a616e2234e742 (diff) | |
| download | mullvadvpn-23517aa5dda6ba8360a6fa9ce408aa63ae5751ce.tar.xz mullvadvpn-23517aa5dda6ba8360a6fa9ce408aa63ae5751ce.zip | |
Fix data class issues
Diffstat (limited to 'android/app')
7 files changed, 27 insertions, 17 deletions
diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt index 4844177b45..106d960d1f 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt @@ -82,9 +82,13 @@ class SelectLocationScreenTest { uiState = SelectLocationUiState.ShowData( countries = - DUMMY_RELAY_COUNTRIES.apply { - this[0].expanded = true - this[0].cities[0].expanded = true + DUMMY_RELAY_COUNTRIES.let { + val cities = it[0].cities.toMutableList() + val city = cities.removeAt(0) + cities.add(0, city.copy(expanded = true)) + it.toMutableList()[0] = + it[0].copy(expanded = true, cities = cities.toList()) + it }, selectedRelay = DUMMY_RELAY_COUNTRIES[0].cities[0].relays[0] ), 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 b7f23ea768..fec20ceb18 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 f3c3a3cc7c..9bdb59168b 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 d1a3332a78..e3693963f8 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<Relay> ) : 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 d418fd3a4a..3ad1d5962f 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<RelayCity> ) : 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 f4387e9647..3d38d6b068 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 401f03d744..39618f9603 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<RelayCountry>.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<RelayCountry>.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()) } } |
