Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filter screen selection #5920

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ fun Ownership?.toOwnershipConstraint(): Constraint<Ownership> =
else -> Constraint.Only(this)
}

fun Constraint<Providers>.toSelectedProviders(allProviders: List<Provider>): List<Provider>? =
fun Constraint<Providers>.toSelectedProviders(allProviders: List<Provider>): List<Provider> =
when (this) {
is Constraint.Any -> null
is Constraint.Any -> allProviders
is Constraint.Only ->
this.value.providers.toList().mapNotNull { providerName ->
value.providers.toList().mapNotNull { providerName ->
allProviders.firstOrNull { it.name == providerName }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FilterViewModel(
) { allProviders, selectedConstraintProviders ->
selectedConstraintProviders.toSelectedProviders(allProviders)
}
.first() ?: emptyList()
.first()

val ownershipConstraint = relayListFilterUseCase.selectedOwnership().first()
selectedOwnership.value = ownershipConstraint.toNullableOwnership()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ class SelectLocationViewModel(
selectedConstraintProviders ->
val selectedOwnershipItem = selectedOwnership.toNullableOwnership()
val selectedProvidersCount =
filterSelectedProvidersByOwnership(
selectedConstraintProviders.toSelectedProviders(allProviders),
selectedOwnershipItem
)
?.size
when (selectedConstraintProviders) {
is Constraint.Any -> null
is Constraint.Only ->
filterSelectedProvidersByOwnership(
selectedConstraintProviders.toSelectedProviders(allProviders),
selectedOwnershipItem
)
.size
}

val filteredRelayCountries =
relayCountries.filterOnSearchTerm(searchTerm, selectedItem)
Expand Down Expand Up @@ -97,15 +101,13 @@ class SelectLocationViewModel(
}

private fun filterSelectedProvidersByOwnership(
selectedProviders: List<Provider>?,
selectedProviders: List<Provider>,
selectedOwnership: Ownership?
): List<Provider>? =
selectedProviders?.let {
when (selectedOwnership) {
Ownership.MullvadOwned -> selectedProviders.filter { it.mullvadOwned }
Ownership.Rented -> selectedProviders.filterNot { it.mullvadOwned }
else -> selectedProviders
}
): List<Provider> =
when (selectedOwnership) {
Ownership.MullvadOwned -> selectedProviders.filter { it.mullvadOwned }
Ownership.Rented -> selectedProviders.filterNot { it.mullvadOwned }
else -> selectedProviders
}

fun removeOwnerFilter() {
Expand Down
Loading