Skip to content

Commit

Permalink
Fix data class issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Oct 2, 2023
1 parent b61b425 commit 4d84d22
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ interface RelayItem {
val locationName: String
get() = name

var expanded: Boolean
val expanded: Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.mullvad.mullvadvpn.model

data class RelayConstraintsUpdate(
var location: Constraint<LocationConstraint>?,
var wireguardConstraints: WireguardConstraints?
val location: Constraint<LocationConstraint>?,
val wireguardConstraints: WireguardConstraints?
)
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4d84d22

Please sign in to comment.