-
Notifications
You must be signed in to change notification settings - Fork 353
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
15 changed files
with
147 additions
and
121 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
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
46 changes: 25 additions & 21 deletions
46
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,37 +1,41 @@ | ||
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 | ||
import net.mullvad.mullvadvpn.lib.model.Providers | ||
|
||
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<Providers> = Constraint.Any, | ||
) { | ||
val allProviders: List<ProviderId> = providerToOwnerships.keys.toList().sorted() | ||
val allProviders: Providers = providerToOwnerships.keys | ||
|
||
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.toList() | ||
is Constraint.Only -> | ||
providerToOwnerships.filterValues { selectedOwnership.value in it }.keys | ||
}.sorted() | ||
|
||
val isApplyButtonEnabled = selectedProviders.getOrNull()?.isNotEmpty() != false | ||
val removedProviders: List<ProviderId> = selectedProviders - allProviders | ||
|
||
val isApplyButtonEnabled = selectedProviders.isNotEmpty() | ||
|
||
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
Oops, something went wrong.