diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/data/models/Descriptor.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/data/models/Descriptor.kt index 442cbdd1..fd8bdc63 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/data/models/Descriptor.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/data/models/Descriptor.kt @@ -22,6 +22,7 @@ data class Descriptor( val longRunningTests: List = emptyList(), val source: Source, val updateStatus: UpdateStatus, + val enabled: Boolean = true, ) { sealed interface Source { data class Default(val value: DefaultTestDescriptor) : Source diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt index 660b3541..38c4cb54 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt @@ -292,6 +292,7 @@ class Dependencies( getDefaultTestDescriptors = getDefaultTestDescriptors::invoke, listInstalledTestDescriptors = testDescriptorRepository::list, descriptorUpdates = getDescriptorUpdate::observeAvailableUpdatesState, + getPreferenceValues = preferenceRepository::allSettings, ) } private val getTestDescriptorsBySpec by lazy { diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/domain/GetAutoRunSpecification.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/domain/GetAutoRunSpecification.kt index 47455162..bea85b27 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/domain/GetAutoRunSpecification.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/domain/GetAutoRunSpecification.kt @@ -27,7 +27,7 @@ class GetAutoRunSpecification( } private suspend fun List.filterForAutoRun() = - filter { it.isEnabledForAutoRun() } + filter { it.enabled && it.isEnabledForAutoRun() } .map { descriptor -> descriptor.copy( netTests = descriptor.netTests diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/domain/GetTestDescriptors.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/domain/GetTestDescriptors.kt index b98616c5..cff89106 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/domain/GetTestDescriptors.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/domain/GetTestDescriptors.kt @@ -8,10 +8,12 @@ import kotlinx.coroutines.flow.map import ooniprobe.composeapp.generated.resources.Res import ooniprobe.composeapp.generated.resources.Settings_TestOptions_LongRunningTest import org.jetbrains.compose.resources.stringResource +import org.ooni.engine.models.WebConnectivityCategory import org.ooni.probe.data.models.DefaultTestDescriptor import org.ooni.probe.data.models.Descriptor import org.ooni.probe.data.models.DescriptorUpdatesStatus import org.ooni.probe.data.models.InstalledTestDescriptorModel +import org.ooni.probe.data.models.SettingsKey import org.ooni.probe.data.models.UpdateStatus import org.ooni.probe.data.models.toDescriptor @@ -19,21 +21,29 @@ class GetTestDescriptors( private val getDefaultTestDescriptors: () -> List, private val listInstalledTestDescriptors: () -> Flow>, private val descriptorUpdates: () -> Flow, + private val getPreferenceValues: (List) -> Flow>, ) { operator fun invoke(): Flow> { return combine( listInstalledTestDescriptors(), descriptorUpdates(), flowOf(getDefaultTestDescriptors()), - ) { installedDescriptors, descriptorUpdates, defaultDescriptors -> + isWebsitesDescriptorEnabled(), + ) { installedDescriptors, descriptorUpdates, defaultDescriptors, isWebsitesEnabled -> val updatedDescriptors = installedDescriptors.map { item -> item.toDescriptor(updateStatus = descriptorUpdates.getStatusOf(item.id)) } - return@combine defaultDescriptors - .map { it.toDescriptor() } + updatedDescriptors + val allDescriptors = defaultDescriptors.map { it.toDescriptor() } + updatedDescriptors + return@combine allDescriptors.map { + it.copy(enabled = it.name != "websites" || isWebsitesEnabled) + } } } + private fun isWebsitesDescriptorEnabled() = + getPreferenceValues(WebConnectivityCategory.entries.mapNotNull { it.settingsKey }) + .map { preferences -> preferences.any { it.value == true } } + private fun DefaultTestDescriptor.toDescriptor() = Descriptor( name = label, diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunScreen.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunScreen.kt index 054ba640..c6714f48 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunScreen.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunScreen.kt @@ -244,6 +244,7 @@ private fun LazyListScope.regularTestItems( items(testItems, key = { "${descriptor.key}_${it.item.test.name}" }) { testItem -> TestItem( testItem = testItem, + enabled = descriptor.enabled, onChecked = { onEvent( RunViewModel.Event.NetTestChecked( @@ -271,11 +272,13 @@ private fun DescriptorItem( state = descriptorItem.state, onClick = { onChecked(descriptorItem.state != ToggleableState.On) }, role = Role.Checkbox, + enabled = descriptor.enabled, ) .padding(horizontal = 16.dp), ) { TriStateCheckbox( state = descriptorItem.state, + enabled = descriptor.enabled, onClick = null, modifier = Modifier.padding(end = 24.dp), ) @@ -304,6 +307,7 @@ private fun DescriptorItem( @Composable fun TestItem( testItem: SelectableItem, + enabled: Boolean = true, onChecked: (Boolean) -> Unit, ) { val test = testItem.item @@ -315,11 +319,13 @@ fun TestItem( value = testItem.isSelected, onValueChange = { onChecked(it) }, role = Role.Checkbox, + enabled = enabled, ) .padding(horizontal = 16.dp, vertical = 10.dp), ) { Checkbox( checked = testItem.isSelected, + enabled = enabled, onCheckedChange = null, modifier = Modifier.padding(end = 24.dp), ) diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunViewModel.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunViewModel.kt index d37e8c4d..5e8818cd 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunViewModel.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunViewModel.kt @@ -20,8 +20,8 @@ import org.ooni.probe.config.OrganizationConfig import org.ooni.probe.config.TestDisplayMode import org.ooni.probe.data.models.Descriptor import org.ooni.probe.data.models.DescriptorType -import org.ooni.probe.data.models.PlatformAction import org.ooni.probe.data.models.NetTest +import org.ooni.probe.data.models.PlatformAction import org.ooni.probe.data.models.RunSpecification import org.ooni.probe.data.models.SettingsKey import org.ooni.probe.data.repositories.PreferenceRepository @@ -62,9 +62,9 @@ class RunViewModel( ParentSelectableItem( item = descriptor, - state = when (selectedTestsCount) { - 0 -> ToggleableState.Off - tests.size -> ToggleableState.On + state = when { + !descriptor.enabled || selectedTestsCount == 0 -> ToggleableState.Off + selectedTestsCount == tests.size -> ToggleableState.On else -> ToggleableState.Indeterminate }, isExpanded = when (OrganizationConfig.testDisplayMode) { @@ -75,7 +75,7 @@ class RunViewModel( ) to tests.map { test -> SelectableItem( item = test, - isSelected = preferences[descriptor to test] == true, + isSelected = descriptor.enabled && preferences[descriptor to test] == true, ) } }