Skip to content

Commit

Permalink
chore: update views
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Dec 18, 2024
1 parent 98b2183 commit 2047aa7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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() }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,15 @@ class ResultViewModel(
::Pair,
)
.onEach { (result, expandedDescriptorsKeys) ->
var groupedMeasurements = listOf<Any>()
var groupedMeasurements = listOf<MeasurementGroupItem>()
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),
Expand Down Expand Up @@ -163,7 +162,7 @@ class ResultViewModel(

data class State(
val result: ResultItem?,
val groupedMeasurements: List<Any>,
val groupedMeasurements: List<MeasurementGroupItem>,
val rerunEnabled: Boolean = false,
)

Expand All @@ -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<MeasurementWithUrl>,
val isExpanded: Boolean = false,
)
sealed class MeasurementGroupItem {
data class Single(val measurement: MeasurementWithUrl) : MeasurementGroupItem()
data class Group(
val test: TestType,
val measurements: List<MeasurementWithUrl>,
val isExpanded: Boolean
) : MeasurementGroupItem()
}
}

0 comments on commit 2047aa7

Please sign in to comment.