From 0337f3f707ea5081a4f684e5f6c7df343444e2c7 Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Tue, 26 Nov 2024 15:02:21 +0100 Subject: [PATCH] Fixes based on feedback --- .../compose/screen/ConnectScreen.kt | 21 ++++++++++------- .../screen/location/SelectLocationScreen.kt | 5 +++- .../relaylist/RelayItemExtensions.kt | 23 ++++++++----------- .../mullvadvpn/usecase/FilterChipUseCase.kt | 4 ++-- .../usecase/FilteredRelayListUseCase.kt | 4 ++-- .../FilterCustomListsRelayItemUseCase.kt | 14 +++++------ .../net/mullvad/mullvadvpn/util/Daita.kt | 2 +- .../lib/theme/dimensions/Dimensions.kt | 3 ++- 8 files changed, 41 insertions(+), 35 deletions(-) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreen.kt index e299b8541805..1d98c17b50d7 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreen.kt @@ -409,14 +409,8 @@ private fun ConnectionCardHeader( maxLines = 1, overflow = TextOverflow.Ellipsis, ) - - val hostname = - when { - location?.entryHostname != null && location.hostname != null -> - stringResource(R.string.x_via_x, location.hostname!!, location.entryHostname!!) - else -> location?.hostname - } - AnimatedContent(hostname, label = "hostname") { + val hostnames = location.hostNames() + AnimatedContent(hostnames, label = "hostname") { if (it != null) { Text( modifier = Modifier.fillMaxWidth(), @@ -444,6 +438,17 @@ private fun GeoIpLocation?.asString(): String { } } +@Composable +private fun GeoIpLocation?.hostNames(): String? { + val entryHostName = this?.entryHostname + val exitHostName = this?.hostname + return when { + entryHostName != null && exitHostName != null -> + stringResource(R.string.x_via_x, exitHostName, entryHostName) + else -> exitHostName + } +} + @Composable private fun ConnectionInfo( featureIndicators: List, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreen.kt index 5ad5eb1507b2..3e40d5709051 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreen.kt @@ -277,7 +277,10 @@ fun SelectLocationScreen( MultihopBar(state.relayListType, onSelectRelayList) } - Spacer(modifier = Modifier.height(height = Dimens.verticalSpace)) + if (state.filterChips.isNotEmpty() || state.multihopEnabled) { + Spacer(modifier = Modifier.height(height = Dimens.verticalSpace)) + } + RelayLists( state = state, backgroundColor = backgroundColor, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItemExtensions.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItemExtensions.kt index 0aeef5e219a1..f21adee73584 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItemExtensions.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItemExtensions.kt @@ -56,15 +56,14 @@ private fun RelayItem.Location.hasProvider(providersConstraint: Constraint, providers: Constraint, - shouldFilterByDaita: Boolean, + daita: Boolean, ): RelayItem.CustomList { val newLocations = locations.mapNotNull { when (it) { - is RelayItem.Location.Country -> - it.filter(ownership, providers, shouldFilterByDaita) - is RelayItem.Location.City -> it.filter(ownership, providers, shouldFilterByDaita) - is RelayItem.Location.Relay -> it.filter(ownership, providers, shouldFilterByDaita) + is RelayItem.Location.Country -> it.filter(ownership, providers, daita) + is RelayItem.Location.City -> it.filter(ownership, providers, daita) + is RelayItem.Location.Relay -> it.filter(ownership, providers, daita) } } return copy(locations = newLocations) @@ -73,9 +72,9 @@ fun RelayItem.CustomList.filter( fun RelayItem.Location.Country.filter( ownership: Constraint, providers: Constraint, - shouldFilterByDaita: Boolean, + daita: Boolean, ): RelayItem.Location.Country? { - val cities = cities.mapNotNull { it.filter(ownership, providers, shouldFilterByDaita) } + val cities = cities.mapNotNull { it.filter(ownership, providers, daita) } return if (cities.isNotEmpty()) { this.copy(cities = cities) } else { @@ -86,9 +85,9 @@ fun RelayItem.Location.Country.filter( private fun RelayItem.Location.City.filter( ownership: Constraint, providers: Constraint, - shouldFilterByDaita: Boolean, + daita: Boolean, ): RelayItem.Location.City? { - val relays = relays.mapNotNull { it.filter(ownership, providers, shouldFilterByDaita) } + val relays = relays.mapNotNull { it.filter(ownership, providers, daita) } return if (relays.isNotEmpty()) { this.copy(relays = relays) } else { @@ -103,12 +102,10 @@ private fun RelayItem.Location.Relay.hasMatchingDaitaSetting(isDaitaEnabled: Boo private fun RelayItem.Location.Relay.filter( ownership: Constraint, providers: Constraint, - shouldFilterByDaita: Boolean, + daita: Boolean, ): RelayItem.Location.Relay? { return if ( - hasMatchingDaitaSetting(shouldFilterByDaita) && - hasOwnership(ownership) && - hasProvider(providers) + hasMatchingDaitaSetting(daita) && hasOwnership(ownership) && hasProvider(providers) ) { this } else { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCase.kt index 3874785920dc..366a7321f63f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCase.kt @@ -11,7 +11,7 @@ import net.mullvad.mullvadvpn.lib.model.Providers import net.mullvad.mullvadvpn.repository.RelayListFilterRepository import net.mullvad.mullvadvpn.repository.SettingsRepository import net.mullvad.mullvadvpn.repository.WireguardConstraintsRepository -import net.mullvad.mullvadvpn.util.showOnlyRelaysWithDaita +import net.mullvad.mullvadvpn.util.shouldFilterByDaita typealias ModelOwnership = Ownership @@ -71,7 +71,7 @@ class FilterChipUseCase( add(FilterChip.Provider(providerCountFilter)) } if ( - showOnlyRelaysWithDaita( + shouldFilterByDaita( isDaitaEnabled = isDaitaEnabled, relayListType = relayListType, isMultihopEnabled = isMultihopEnabled, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt index 5a83e483d5ee..6712d9275ff3 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt @@ -11,7 +11,7 @@ import net.mullvad.mullvadvpn.repository.RelayListFilterRepository import net.mullvad.mullvadvpn.repository.RelayListRepository import net.mullvad.mullvadvpn.repository.SettingsRepository import net.mullvad.mullvadvpn.repository.WireguardConstraintsRepository -import net.mullvad.mullvadvpn.util.showOnlyRelaysWithDaita +import net.mullvad.mullvadvpn.util.shouldFilterByDaita class FilteredRelayListUseCase( private val relayListRepository: RelayListRepository, @@ -31,7 +31,7 @@ class FilteredRelayListUseCase( ownership = selectedOwnership, providers = selectedProviders, shouldFilterByDaita = - showOnlyRelaysWithDaita( + shouldFilterByDaita( isDaitaEnabled = settings?.isDaitaEnabled() == true, isMultihopEnabled = wireguardConstraints?.isMultihopEnabled == true, relayListType = relayListType, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/FilterCustomListsRelayItemUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/FilterCustomListsRelayItemUseCase.kt index af519841a249..c326b176a5e9 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/FilterCustomListsRelayItemUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/FilterCustomListsRelayItemUseCase.kt @@ -11,7 +11,7 @@ import net.mullvad.mullvadvpn.relaylist.filter import net.mullvad.mullvadvpn.repository.RelayListFilterRepository import net.mullvad.mullvadvpn.repository.SettingsRepository import net.mullvad.mullvadvpn.repository.WireguardConstraintsRepository -import net.mullvad.mullvadvpn.util.showOnlyRelaysWithDaita +import net.mullvad.mullvadvpn.util.shouldFilterByDaita class FilterCustomListsRelayItemUseCase( private val customListsRelayItemUseCase: CustomListsRelayItemUseCase, @@ -28,11 +28,11 @@ class FilterCustomListsRelayItemUseCase( settingsRepository.settingsUpdates, wireguardConstraintsRepository.wireguardConstraints, ) { customLists, selectedOwnership, selectedProviders, settings, wireguardConstraints -> - customLists.filterOnOwnershipAndProvider( + customLists.filter( ownership = selectedOwnership, providers = selectedProviders, - shouldFilterByDaita = - showOnlyRelaysWithDaita( + daita = + shouldFilterByDaita( isDaitaEnabled = settings?.isDaitaEnabled() == true, isMultihopEnabled = wireguardConstraints?.isMultihopEnabled == true, relayListType = relayListType, @@ -40,9 +40,9 @@ class FilterCustomListsRelayItemUseCase( ) } - private fun List.filterOnOwnershipAndProvider( + private fun List.filter( ownership: Constraint, providers: Constraint, - shouldFilterByDaita: Boolean, - ) = mapNotNull { it.filter(ownership, providers, shouldFilterByDaita = shouldFilterByDaita) } + daita: Boolean, + ) = mapNotNull { it.filter(ownership, providers, daita = daita) } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/Daita.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/Daita.kt index 0126e9e7f540..717d007f92ad 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/Daita.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/Daita.kt @@ -2,7 +2,7 @@ package net.mullvad.mullvadvpn.util import net.mullvad.mullvadvpn.compose.state.RelayListType -fun showOnlyRelaysWithDaita( +fun shouldFilterByDaita( isDaitaEnabled: Boolean, isMultihopEnabled: Boolean, relayListType: RelayListType, diff --git a/android/lib/theme/src/main/kotlin/net/mullvad/mullvadvpn/lib/theme/dimensions/Dimensions.kt b/android/lib/theme/src/main/kotlin/net/mullvad/mullvadvpn/lib/theme/dimensions/Dimensions.kt index d0caba267ae2..6a5da5c18d31 100644 --- a/android/lib/theme/src/main/kotlin/net/mullvad/mullvadvpn/lib/theme/dimensions/Dimensions.kt +++ b/android/lib/theme/src/main/kotlin/net/mullvad/mullvadvpn/lib/theme/dimensions/Dimensions.kt @@ -56,7 +56,8 @@ data class Dimensions( val relayCircleSize: Dp = 16.dp, val screenVerticalMargin: Dp = 22.dp, val searchFieldHeight: Dp = 42.dp, - val searchFieldHeightExpanded: Dp = 85.dp, + // Search view full screen header container height (material design guidelines) + val searchFieldHeightExpanded: Dp = 72.dp, val searchFieldHorizontalPadding: Dp = 22.dp, val searchIconSize: Dp = 24.dp, val selectLocationTitlePadding: Dp = 12.dp,