-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
109 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 26 additions & 18 deletions
44
android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/RelayFilterUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,43 @@ | ||
package net.mullvad.mullvadvpn.compose.state | ||
|
||
import net.mullvad.mullvadvpn.lib.model.Constraint | ||
import net.mullvad.mullvadvpn.lib.model.Ownership | ||
import net.mullvad.mullvadvpn.lib.model.ProviderId | ||
|
||
data class RelayFilterUiState( | ||
private val providerToOwnerships: Map<ProviderId, Set<Ownership>> = emptyMap(), | ||
val selectedOwnership: Ownership? = null, | ||
val selectedProviders: List<ProviderId> = emptyList(), | ||
val selectedOwnership: Constraint<Ownership> = Constraint.Any, | ||
val selectedProviders: Constraint<List<ProviderId>> = Constraint.Any, | ||
) { | ||
val allProviders: List<ProviderId> = providerToOwnerships.keys.toList().sorted() | ||
|
||
val selectableOwnerships: List<Ownership> = | ||
if (selectedProviders.isEmpty()) { | ||
Ownership.entries | ||
} else { | ||
providerToOwnerships | ||
.filterKeys { it in selectedProviders } | ||
.values | ||
.flatten() | ||
.distinct() | ||
} | ||
.sorted() | ||
when (selectedProviders) { | ||
Constraint.Any -> Ownership.entries | ||
is Constraint.Only -> | ||
if (selectedProviders.value.isEmpty()) { | ||
Ownership.entries | ||
} else { | ||
providerToOwnerships | ||
.filterKeys { it in selectedProviders.value } | ||
.values | ||
.flatten() | ||
.distinct() | ||
} | ||
}.sorted() | ||
|
||
val selectableProviders: List<ProviderId> = | ||
if (selectedOwnership != null) { | ||
providerToOwnerships.filterValues { selectedOwnership in it }.keys.toList().sorted() | ||
} else { | ||
allProviders | ||
when (selectedOwnership) { | ||
Constraint.Any -> allProviders | ||
is Constraint.Only -> | ||
providerToOwnerships | ||
.filterValues { selectedOwnership.value in it } | ||
.keys | ||
.toList() | ||
.sorted() | ||
} | ||
|
||
val isApplyButtonEnabled = selectedProviders.isNotEmpty() | ||
val isApplyButtonEnabled = selectedProviders.getOrNull()?.isNotEmpty() != false | ||
|
||
val isAllProvidersChecked = allProviders.size == selectedProviders.size | ||
val isAllProvidersChecked = selectedProviders is Constraint.Any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.