Skip to content

Commit

Permalink
Merge branch 'all-providers-are-not-selected-by-default-in-filterscre…
Browse files Browse the repository at this point in the history
…en-droid-730'
  • Loading branch information
Rawa committed Mar 8, 2024
2 parents 5b81fe6 + 68daaa4 commit 972d2fa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
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

0 comments on commit 972d2fa

Please sign in to comment.