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

feat: website categories and test duration do not apply to NewsMediaScan #288

Merged
merged 1 commit into from
Nov 20, 2024
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 @@ -2,7 +2,6 @@ package org.ooni.probe.domain

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import org.ooni.engine.models.WebConnectivityCategory
import org.ooni.probe.data.models.Descriptor
import org.ooni.probe.data.models.SettingsKey
import org.ooni.probe.data.repositories.PreferenceRepository
Expand All @@ -29,16 +28,12 @@ class BootstrapPreferences(
preferencesRepository.setValuesByKey(
listOf(
SettingsKey.FIRST_RUN to true,
SettingsKey.MAX_RUNTIME_ENABLED to true,
SettingsKey.MAX_RUNTIME to 90,
SettingsKey.UPLOAD_RESULTS to true,
SettingsKey.AUTOMATED_TESTING_WIFIONLY to true,
SettingsKey.AUTOMATED_TESTING_CHARGING to true,
SettingsKey.AUTOMATED_TESTING_NOT_UPLOADED_LIMIT to NOT_UPLOADED_LIMIT_DEFAULT,
) +
WebConnectivityCategory.entries
.mapNotNull { it.settingsKey }
.map { it to true },
preferenceDefaults(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ import ooniprobe.composeapp.generated.resources.Settings_Storage_Clear
import ooniprobe.composeapp.generated.resources.Settings_Storage_Label
import ooniprobe.composeapp.generated.resources.Settings_TestOptions_Label
import ooniprobe.composeapp.generated.resources.Settings_WarmVPNInUse_Label
import ooniprobe.composeapp.generated.resources.Settings_Websites_Categories_Description
import ooniprobe.composeapp.generated.resources.Settings_Websites_Categories_Label
import ooniprobe.composeapp.generated.resources.Settings_Websites_MaxRuntime
import ooniprobe.composeapp.generated.resources.Settings_Websites_MaxRuntimeEnabled
import ooniprobe.composeapp.generated.resources.advanced
import ooniprobe.composeapp.generated.resources.auto_test_not_uploaded_limit
import ooniprobe.composeapp.generated.resources.ic_settings
Expand All @@ -60,8 +56,6 @@ import org.ooni.probe.data.models.SettingsKey
import org.ooni.probe.data.repositories.PreferenceRepository
import org.ooni.probe.ui.settings.category.SettingsDescription
import org.ooni.probe.ui.shared.formatDataUsage
import org.ooni.probe.ui.shared.shortFormat
import kotlin.time.Duration.Companion.seconds

class GetSettings(
private val preferencesRepository: PreferenceRepository,
Expand All @@ -87,8 +81,7 @@ class GetSettings(
buildSettings(
uploadResultsEnabled = preferences[SettingsKey.UPLOAD_RESULTS] == true,
autoRunEnabled = preferences[SettingsKey.AUTOMATED_TESTING_ENABLED] == true,
autoRunNotUploadedLimit =
preferences[SettingsKey.AUTOMATED_TESTING_NOT_UPLOADED_LIMIT] as? Int,
autoRunNotUploadedLimit = preferences[SettingsKey.AUTOMATED_TESTING_NOT_UPLOADED_LIMIT] as? Int,
enabledCategoriesCount = enabledCategoriesCount,
maxRuntimeEnabled = preferences[SettingsKey.MAX_RUNTIME_ENABLED] == true,
maxRuntime = preferences[SettingsKey.MAX_RUNTIME] as? Int,
Expand Down Expand Up @@ -167,44 +160,10 @@ class GetSettings(
Text(value.toString())
},
),
SettingsCategoryItem(
title = Res.string.Settings_Websites_Categories_Label,
route = PreferenceCategoryKey.WEBSITES_CATEGORIES,
supportingContent = {
Text(
stringResource(
Res.string.Settings_Websites_Categories_Description,
enabledCategoriesCount,
),
)
},
settings = WebConnectivityCategory.entries
.mapNotNull { cat ->
SettingsItem(
icon = cat.icon,
title = cat.title,
supportingContent = { Text(stringResource(cat.description)) },
key = cat.settingsKey ?: return@mapNotNull null,
type = PreferenceItemType.SWITCH,
)
},
),
SettingsItem(
title = Res.string.Settings_Websites_MaxRuntimeEnabled,
key = SettingsKey.MAX_RUNTIME_ENABLED,
type = PreferenceItemType.SWITCH,
),
SettingsItem(
title = Res.string.Settings_Websites_MaxRuntime,
key = SettingsKey.MAX_RUNTIME,
type = PreferenceItemType.INT,
enabled = maxRuntimeEnabled,
supportingContent = {
maxRuntime?.let {
Text(it.coerceAtLeast(0).seconds.shortFormat())
}
},
),
) + webConnectivityPreferences(
enabledCategoriesCount,
maxRuntimeEnabled,
maxRuntime,
),
footerContent = {
SettingsDescription(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.ooni.probe.domain

import org.ooni.probe.data.models.PreferenceItem
import org.ooni.probe.data.models.SettingsKey

fun webConnectivityPreferences(
enabledCategoriesCount: Int,
maxRuntimeEnabled: Boolean,
maxRuntime: Int?,
): List<PreferenceItem> {
return emptyList()
}

fun preferenceDefaults(): List<Pair<SettingsKey,Any>> {
return emptyList()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.ooni.probe.domain

import androidx.compose.material3.Text
import ooniprobe.composeapp.generated.resources.Res
import ooniprobe.composeapp.generated.resources.Settings_Websites_Categories_Description
import ooniprobe.composeapp.generated.resources.Settings_Websites_Categories_Label
import ooniprobe.composeapp.generated.resources.Settings_Websites_MaxRuntime
import ooniprobe.composeapp.generated.resources.Settings_Websites_MaxRuntimeEnabled
import org.jetbrains.compose.resources.stringResource
import org.ooni.engine.models.WebConnectivityCategory
import org.ooni.probe.data.models.PreferenceCategoryKey
import org.ooni.probe.data.models.PreferenceItem
import org.ooni.probe.data.models.PreferenceItemType
import org.ooni.probe.data.models.SettingsCategoryItem
import org.ooni.probe.data.models.SettingsItem
import org.ooni.probe.data.models.SettingsKey
import org.ooni.probe.ui.shared.shortFormat
import kotlin.time.Duration.Companion.seconds

fun webConnectivityPreferences(
enabledCategoriesCount: Int,
maxRuntimeEnabled: Boolean,
maxRuntime: Int?,
): List<PreferenceItem> {
return listOf(
SettingsCategoryItem(
title = Res.string.Settings_Websites_Categories_Label,
route = PreferenceCategoryKey.WEBSITES_CATEGORIES,
supportingContent = {
Text(
stringResource(
Res.string.Settings_Websites_Categories_Description,
enabledCategoriesCount,
),
)
},
settings = WebConnectivityCategory.entries.mapNotNull { cat ->
SettingsItem(
icon = cat.icon,
title = cat.title,
supportingContent = { Text(stringResource(cat.description)) },
key = cat.settingsKey ?: return@mapNotNull null,
type = PreferenceItemType.SWITCH,
)
},
),
SettingsItem(
title = Res.string.Settings_Websites_MaxRuntimeEnabled,
key = SettingsKey.MAX_RUNTIME_ENABLED,
type = PreferenceItemType.SWITCH,
),
SettingsItem(
title = Res.string.Settings_Websites_MaxRuntime,
key = SettingsKey.MAX_RUNTIME,
type = PreferenceItemType.INT,
enabled = maxRuntimeEnabled,
supportingContent = {
maxRuntime?.let {
Text(it.coerceAtLeast(0).seconds.shortFormat())
}
},
),
)
}

fun preferenceDefaults(): List<Pair<SettingsKey, Any>> {
return listOf(
SettingsKey.MAX_RUNTIME_ENABLED to true,
SettingsKey.MAX_RUNTIME to 90,
) + WebConnectivityCategory.entries
.mapNotNull { it.settingsKey }
.map { it to true }
}