diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/result/ResultMeasurementCell.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/result/ResultMeasurementCell.kt index 3fd4281d..dc982777 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/result/ResultMeasurementCell.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/result/ResultMeasurementCell.kt @@ -38,6 +38,7 @@ import org.jetbrains.compose.resources.stringResource import org.ooni.engine.models.TestType import org.ooni.probe.data.models.MeasurementModel import org.ooni.probe.data.models.MeasurementWithUrl +import org.ooni.probe.ui.result.ResultViewModel.MeasurementGroupItem.Group @Composable fun ResultMeasurementCell( @@ -139,14 +140,16 @@ private fun TestName( @Composable fun ResultGroupMeasurementCell( - item: ResultViewModel.MeasurementGroup, + item: Group, isResultDone: Boolean, onClick: (MeasurementModel.ReportId, String?) -> Unit, onDropdownToggled: () -> Unit, ) { Row( verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.fillMaxWidth().alpha(0.66f).padding(horizontal = 16.dp), + modifier = Modifier.fillMaxWidth().alpha(0.66f).clickable { + onDropdownToggled() + }.padding(horizontal = 16.dp), ) { TestName(item.test, item.measurements.first(), modifier = Modifier.weight(1f)) IconButton(onClick = { onDropdownToggled() }) { diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/result/ResultScreen.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/result/ResultScreen.kt index c611d604..a29ba266 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/result/ResultScreen.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/result/ResultScreen.kt @@ -67,8 +67,9 @@ import ooniprobe.composeapp.generated.resources.ooni_bw import org.jetbrains.compose.resources.painterResource import org.jetbrains.compose.resources.stringResource import org.ooni.engine.models.NetworkType -import org.ooni.probe.data.models.MeasurementWithUrl import org.ooni.probe.data.models.ResultItem +import org.ooni.probe.ui.result.ResultViewModel.MeasurementGroupItem.Group +import org.ooni.probe.ui.result.ResultViewModel.MeasurementGroupItem.Single import org.ooni.probe.ui.results.UploadResults import org.ooni.probe.ui.shared.TopBar import org.ooni.probe.ui.shared.formatDataUsage @@ -145,15 +146,13 @@ fun ResultScreen( } items(state.groupedMeasurements, key = { item -> - var key: Any = item.toString() when (item) { - is ResultViewModel.MeasurementGroup -> key = item.test.name - is MeasurementWithUrl -> key = item.measurement.idOrThrow.value + is Group -> item.test.name + is Single -> item.measurement.measurement.idOrThrow.value } - key }) { item -> when (item) { - is ResultViewModel.MeasurementGroup -> { + is Group -> { ResultGroupMeasurementCell( item = item, isResultDone = state.result.result.isDone, @@ -166,9 +165,9 @@ fun ResultScreen( ) } - is MeasurementWithUrl -> { + is Single -> { ResultMeasurementCell( - item = item, + item = item.measurement, isResultDone = state.result.result.isDone, onClick = { reportId, input -> onEvent(ResultViewModel.Event.MeasurementClicked(reportId, input)) diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/result/ResultViewModel.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/result/ResultViewModel.kt index 714eb720..d2d1e36c 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/result/ResultViewModel.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/result/ResultViewModel.kt @@ -49,16 +49,15 @@ class ResultViewModel( ::Pair, ) .onEach { (result, expandedDescriptorsKeys) -> - var groupedMeasurements = listOf() + var groupedMeasurements = listOf() result?.measurements?.let { measurements -> - groupedMeasurements = measurements.groupBy { it.measurement.test.name }.flatMap { (_, itemList) -> + groupedMeasurements = measurements.groupBy { it.measurement.test }.flatMap { (key, itemList) -> when { - itemList.size == 1 -> listOf(itemList.first()) - itemList.size > 1 && itemList.size == measurements.size -> itemList + itemList.size == 1 -> listOf(MeasurementGroupItem.Single(itemList.first())) + itemList.size > 1 && itemList.size == measurements.size -> itemList.map { MeasurementGroupItem.Single(it) } else -> { - val key = itemList.first().measurement.test listOf( - MeasurementGroup( + MeasurementGroupItem.Group( test = key, measurements = itemList, isExpanded = expandedDescriptorsKeys.contains(key), @@ -163,7 +162,7 @@ class ResultViewModel( data class State( val result: ResultItem?, - val groupedMeasurements: List, + val groupedMeasurements: List, val rerunEnabled: Boolean = false, ) @@ -179,12 +178,15 @@ class ResultViewModel( data object RerunClicked : Event - data class MeasurementGroupToggled(val measurementGroup: MeasurementGroup) : Event + data class MeasurementGroupToggled(val measurementGroup: MeasurementGroupItem.Group) : Event } - data class MeasurementGroup( - val test: TestType, - val measurements: List, - val isExpanded: Boolean = false, - ) + sealed class MeasurementGroupItem { + data class Single(val measurement: MeasurementWithUrl) : MeasurementGroupItem() + data class Group( + val test: TestType, + val measurements: List, + val isExpanded: Boolean + ) : MeasurementGroupItem() + } }