diff --git a/app/src/main/java/com/geeksville/mesh/ui/SignalInfo.kt b/app/src/main/java/com/geeksville/mesh/ui/SignalInfo.kt index 162f755c9..4a3d43b2c 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SignalInfo.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SignalInfo.kt @@ -10,6 +10,7 @@ import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.tooling.preview.PreviewParameter import com.geeksville.mesh.R import com.geeksville.mesh.database.entity.NodeEntity +import com.geeksville.mesh.ui.components.NodeSignalQuality import com.geeksville.mesh.ui.preview.NodeEntityPreviewParameterProvider import com.geeksville.mesh.ui.theme.AppTheme @@ -21,7 +22,7 @@ fun signalInfo( modifier: Modifier = Modifier, node: NodeEntity, isThisNode: Boolean -): Boolean { +) { val text = if (isThisNode) { stringResource(R.string.channel_air_util).format( node.deviceMetrics.channelUtilization, @@ -40,24 +41,22 @@ fun signalInfo( if (node.channel > 0) { add("ch:${node.channel}") } - if (node.hopsAway <= 0) { - if (node.snr < MAX_VALID_SNR && node.rssi < MAX_VALID_RSSI) { - add("RSSI: %d SNR: %.1f".format(node.rssi, node.snr)) - } - } if (node.hopsAway != 0) add(hopsString) }.joinToString(" | ") } - return if (text.isNotEmpty()) { + if (text.isNotEmpty()) { Text( modifier = modifier, text = text, color = MaterialTheme.colors.onSurface, fontSize = MaterialTheme.typography.button.fontSize ) - true - } else { - false + } + /* We only know the Signal Quality from direct nodes aka 0 hop. */ + if (node.hopsAway <= 0) { + if (node.snr < MAX_VALID_SNR && node.rssi < MAX_VALID_RSSI) { + NodeSignalQuality(node.snr, node.rssi) + } } } diff --git a/app/src/main/java/com/geeksville/mesh/ui/components/LoraSignalIndicator.kt b/app/src/main/java/com/geeksville/mesh/ui/components/LoraSignalIndicator.kt index c5b479280..95d7ac8bd 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/components/LoraSignalIndicator.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/components/LoraSignalIndicator.kt @@ -41,7 +41,30 @@ private enum class Quality( } /** - * Displays the `snr` and `rssi` with color depending on the value respectively. + * Displays the `snr` and `rssi` color coded based on the signal quality, along with + * a human readable description and related icon. + */ +@Composable +fun NodeSignalQuality(snr: Float, rssi: Int) { + val quality = determineSignalQuality(snr, rssi) + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween + ) { + Snr(snr) + Rssi(rssi) + Text(text = "${stringResource(R.string.signal)} ${stringResource(quality.nameRes)}") + Icon( + imageVector = quality.imageVector, + contentDescription = stringResource(R.string.signal_quality), + tint = quality.color + ) + } +} + +/** + * Displays the `snr` and `rssi` with color depending on the values respectively. */ @Composable fun SnrAndRssi(snr: Float, rssi: Int){ @@ -55,7 +78,7 @@ fun SnrAndRssi(snr: Float, rssi: Int){ } /** - * Displays a signal indicator based on `snr` and `rssi`. + * Displays a human readable description and icon representing the signal quality. */ @Composable fun LoraSignalIndicator(snr: Float, rssi: Int) {