Skip to content

Commit

Permalink
Fixes based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Nov 26, 2024
1 parent ba4ecfa commit 0337f3f
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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<FeatureIndicator>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ private fun RelayItem.Location.hasProvider(providersConstraint: Constraint<Provi
fun RelayItem.CustomList.filter(
ownership: Constraint<Ownership>,
providers: Constraint<Providers>,
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)
Expand All @@ -73,9 +72,9 @@ fun RelayItem.CustomList.filter(
fun RelayItem.Location.Country.filter(
ownership: Constraint<Ownership>,
providers: Constraint<Providers>,
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 {
Expand All @@ -86,9 +85,9 @@ fun RelayItem.Location.Country.filter(
private fun RelayItem.Location.City.filter(
ownership: Constraint<Ownership>,
providers: Constraint<Providers>,
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 {
Expand All @@ -103,12 +102,10 @@ private fun RelayItem.Location.Relay.hasMatchingDaitaSetting(isDaitaEnabled: Boo
private fun RelayItem.Location.Relay.filter(
ownership: Constraint<Ownership>,
providers: Constraint<Providers>,
shouldFilterByDaita: Boolean,
daita: Boolean,
): RelayItem.Location.Relay? {
return if (
hasMatchingDaitaSetting(shouldFilterByDaita) &&
hasOwnership(ownership) &&
hasProvider(providers)
hasMatchingDaitaSetting(daita) && hasOwnership(ownership) && hasProvider(providers)
) {
this
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -71,7 +71,7 @@ class FilterChipUseCase(
add(FilterChip.Provider(providerCountFilter))
}
if (
showOnlyRelaysWithDaita(
shouldFilterByDaita(
isDaitaEnabled = isDaitaEnabled,
relayListType = relayListType,
isMultihopEnabled = isMultihopEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,7 +31,7 @@ class FilteredRelayListUseCase(
ownership = selectedOwnership,
providers = selectedProviders,
shouldFilterByDaita =
showOnlyRelaysWithDaita(
shouldFilterByDaita(
isDaitaEnabled = settings?.isDaitaEnabled() == true,
isMultihopEnabled = wireguardConstraints?.isMultihopEnabled == true,
relayListType = relayListType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,21 +28,21 @@ 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,
),
)
}

private fun List<RelayItem.CustomList>.filterOnOwnershipAndProvider(
private fun List<RelayItem.CustomList>.filter(
ownership: Constraint<Ownership>,
providers: Constraint<Providers>,
shouldFilterByDaita: Boolean,
) = mapNotNull { it.filter(ownership, providers, shouldFilterByDaita = shouldFilterByDaita) }
daita: Boolean,
) = mapNotNull { it.filter(ownership, providers, daita = daita) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0337f3f

Please sign in to comment.