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 0edd689082b7..cea69127377a 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 @@ -1,6 +1,5 @@ package net.mullvad.mullvadvpn.relaylist -import co.touchlab.kermit.Logger import net.mullvad.mullvadvpn.lib.model.GeoLocationId import net.mullvad.mullvadvpn.lib.model.RelayItem @@ -10,14 +9,16 @@ fun List.findByGeoLocationId(geoLocationId: GeoLocat fun List.findByGeoLocationId(geoLocationId: GeoLocationId.City) = flatMap { it.cities }.firstOrNull { it.id == geoLocationId } +fun List.search(searchTerm: String): List = + withDescendants().filter { it.name.contains(searchTerm, ignoreCase = true) }.map { it.id } + +fun List.expansionSet() = flatMap { it.ancestors() }.toSet() + fun List.newFilterOnSearch( searchTerm: String ): Pair, List> { - val matchesIds = - withDescendants().filter { it.name.contains(searchTerm, ignoreCase = true) }.map { it.id } - - val expansionSet = matchesIds.flatMap { it.ancestors() }.toSet() - Logger.d("Expansion Set: $expansionSet") + val matchesIds = search(searchTerm) + val expansionSet = matchesIds.expansionSet() val filteredCountryList = mapNotNull { country -> if (country.id in matchesIds) {