Skip to content

Commit 6687847

Browse files
committed
chore: start migration to ooni tests
1 parent 447b5b8 commit 6687847

File tree

11 files changed

+672
-40
lines changed

11 files changed

+672
-40
lines changed

composeApp/src/commonMain/kotlin/org/ooni/probe/data/models/Descriptor.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ data class Descriptor(
3636
val key: String
3737
get() = when (source) {
3838
is Source.Default -> name
39-
is Source.Installed -> source.value.id.value.toString()
39+
is Source.Installed -> source.value.key
4040
}
4141

4242
val allTests get() = netTests + longRunningTests
@@ -45,4 +45,18 @@ data class Descriptor(
4545
get() = allTests
4646
.sumOf { it.test.runtime(it.inputs).inWholeSeconds }
4747
.seconds
48+
49+
fun isDefaultDescriptor(): Boolean {
50+
return when (source) {
51+
is Source.Default -> true
52+
is Source.Installed -> source.value.isDefaultTestDescriptor
53+
}
54+
}
55+
56+
fun isInstalledNonDefaultDescriptor(): Boolean {
57+
return when (source) {
58+
is Source.Installed -> !source.value.isDefaultTestDescriptor
59+
else -> false
60+
}
61+
}
4862
}

composeApp/src/commonMain/kotlin/org/ooni/probe/data/models/InstalledTestDescriptorModel.kt

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ import kotlinx.datetime.format
1313
import kotlinx.datetime.format.MonthNames
1414
import kotlinx.datetime.format.char
1515
import ooniprobe.composeapp.generated.resources.Dashboard_Runv2_Overview_LastUpdatd
16+
import ooniprobe.composeapp.generated.resources.TestResults_NotAvailable
1617
import ooniprobe.composeapp.generated.resources.months
18+
import ooniprobe.composeapp.generated.resources.performance_datausage
19+
import ooniprobe.composeapp.generated.resources.small_datausage
1720
import ooniprobe.composeapp.generated.resources.test_circumvention
1821
import ooniprobe.composeapp.generated.resources.test_experimental
1922
import ooniprobe.composeapp.generated.resources.test_instant_messaging
2023
import ooniprobe.composeapp.generated.resources.test_performance
2124
import ooniprobe.composeapp.generated.resources.test_websites
25+
import ooniprobe.composeapp.generated.resources.websites_datausage
26+
import org.jetbrains.compose.resources.StringResource
2227
import org.jetbrains.compose.resources.stringArrayResource
2328
import org.ooni.probe.data.TestDescriptor
2429
import org.ooni.probe.shared.InstalledDescriptorIcons
@@ -53,6 +58,21 @@ data class InstalledTestDescriptorModel(
5358

5459
val isExpired get() = expirationDate != null && expirationDate < LocalDateTime.now()
5560

61+
val isDefaultTestDescriptor get() = id.value in 10470..10474 // TODO(aanorbel): switch to OONI reserved namespace
62+
63+
val key get() = if (isDefaultTestDescriptor) {
64+
when(id.value) {
65+
10470L -> "websites"
66+
10471L -> "instant_messaging"
67+
10472L -> "circumvention"
68+
10473L -> "performance"
69+
10474L -> "experimental"
70+
else -> id.value.toString()
71+
}
72+
} else {
73+
id.value.toString()
74+
}
75+
5676
fun shouldUpdate(other: InstalledTestDescriptorModel): Boolean {
5777
return dateUpdated != null && other.dateUpdated != null && other.dateUpdated > dateUpdated
5878
}
@@ -80,13 +100,24 @@ fun InstalledTestDescriptorModel.toDescriptor(updateStatus: UpdateStatus = Updat
80100
icon = icon?.let(InstalledDescriptorIcons::getIconFromValue),
81101
color = color?.hexToColor(),
82102
animation = icon?.let { determineAnimation(it) } ?: animation?.let(Animation::fromFileName),
83-
dataUsage = { null },
103+
dataUsage = { if (isDefaultTestDescriptor) stringResource(getDataUsage()) else null },
84104
expirationDate = expirationDate,
85105
netTests = netTests.orEmpty(),
86106
source = Descriptor.Source.Installed(this),
87107
updateStatus = updateStatus,
88108
)
89109

110+
fun InstalledTestDescriptorModel.getDataUsage(): StringResource {
111+
return when(this.key) {
112+
"websites" -> Res.string.websites_datausage
113+
"instant_messaging" -> Res.string.small_datausage
114+
"circumvention" -> Res.string.small_datausage
115+
"performance" -> Res.string.performance_datausage
116+
"experimental" -> Res.string.TestResults_NotAvailable
117+
else -> Res.string.TestResults_NotAvailable
118+
}
119+
}
120+
90121
private val iconAnimationMap = mapOf(
91122
Res.drawable.test_websites to Animation.Websites,
92123
Res.drawable.test_instant_messaging to Animation.InstantMessaging,

composeApp/src/commonMain/kotlin/org/ooni/probe/ui/dashboard/DashboardViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ class DashboardViewModel(
141141

142142
private fun List<Descriptor>.groupByType() =
143143
mapOf(
144-
DescriptorType.Default to filter { it.source is Descriptor.Source.Default },
145-
DescriptorType.Installed to filter { it.source is Descriptor.Source.Installed },
144+
DescriptorType.Default to filter { it.isDefaultDescriptor() },
145+
DescriptorType.Installed to filter { it.isInstalledNonDefaultDescriptor() },
146146
)
147147

148148
data class State(

composeApp/src/commonMain/kotlin/org/ooni/probe/ui/descriptor/DescriptorScreen.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ fun DescriptorScreen(
127127
modifier = Modifier.padding(horizontal = 16.dp, vertical = 16.dp),
128128
)
129129

130-
if (descriptor.source is Descriptor.Source.Installed) {
131-
ConfigureUpdates(onEvent, descriptor.source.value.autoUpdate)
130+
if (descriptor.isInstalledNonDefaultDescriptor()) {
131+
(descriptor.source as Descriptor.Source.Installed?)?.let {
132+
ConfigureUpdates(onEvent, it.value.autoUpdate)
133+
}
132134
}
133135
Text(
134136
stringResource(Res.string.AddDescriptor_Settings),

composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ class RunViewModel(
8080
}
8181
mapOf(
8282
DescriptorType.Default to descriptorsWithTests
83-
.filter { it.key.item.source is Descriptor.Source.Default },
83+
.filter { (key, _) -> key.item.isDefaultDescriptor() },
8484
DescriptorType.Installed to descriptorsWithTests
85-
.filter { it.key.item.source is Descriptor.Source.Installed },
85+
.filter { (key, _) -> key.item.isInstalledNonDefaultDescriptor() },
8686
)
8787
}
8888
}

composeApp/src/dwMain/kotlin/org/ooni/probe/domain/GetDefaultTestDescriptors.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.

composeApp/src/ooniMain/kotlin/org/ooni/probe/domain/GetBootstrapTestDescriptors.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

composeApp/src/ooniMain/kotlin/org/ooni/probe/domain/GetDefaultTestDescriptors.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ import org.ooni.probe.data.models.DefaultTestDescriptor
3232
import org.ooni.probe.data.models.NetTest
3333

3434
class GetDefaultTestDescriptors {
35-
operator fun invoke(): List<DefaultTestDescriptor> =
36-
listOf(
35+
operator fun invoke(): List<DefaultTestDescriptor> = emptyList()
36+
/*listOf(
3737
WEBSITES,
3838
INSTANT_MESSAGING,
3939
CIRCUMVENTION,
4040
PERFORMANCE,
4141
EXPERIMENTAL,
42-
)
42+
)*/
4343

4444
companion object {
4545
private val WEBSITES =

composeApp/src/ooniMain/kotlin/org/ooni/probe/ui/descriptor/InstalledDescriptorActionsView.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,16 @@ fun InstalledDescriptorActionsView(
9090
}
9191
}
9292
}
93-
Button(
94-
onClick = { showDialog = true },
95-
colors = ButtonDefaults.buttonColors(
96-
containerColor = MaterialTheme.colorScheme.error,
97-
contentColor = Color.White,
98-
),
99-
) {
100-
Text(text = stringResource(Res.string.Dashboard_Runv2_Overview_UninstallLink))
93+
if (descriptor.isDefaultTestDescriptor.not()) {
94+
Button(
95+
onClick = { showDialog = true },
96+
colors = ButtonDefaults.buttonColors(
97+
containerColor = MaterialTheme.colorScheme.error,
98+
contentColor = Color.White,
99+
),
100+
) {
101+
Text(text = stringResource(Res.string.Dashboard_Runv2_Overview_UninstallLink))
102+
}
101103
}
102104
}
103105
}

0 commit comments

Comments
 (0)