feat: Add contentColor parameter to info components (#3363)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2025-10-06 17:02:44 -05:00 committed by GitHub
parent 6a71891790
commit ff9d621978
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 76 additions and 52 deletions

View file

@ -109,7 +109,7 @@ fun SnrAndRssi(snr: Float, rssi: Int) {
/** Displays a human readable description and icon representing the signal quality. */
@Composable
fun LoraSignalIndicator(snr: Float, rssi: Int) {
fun LoraSignalIndicator(snr: Float, rssi: Int, contentColor: Color = MaterialTheme.colorScheme.onSurface) {
val quality = determineSignalQuality(snr, rssi)
Column(
verticalArrangement = Arrangement.Center,
@ -125,6 +125,7 @@ fun LoraSignalIndicator(snr: Float, rssi: Int) {
Text(
text = "${stringResource(R.string.signal)} ${stringResource(quality.nameRes)}",
style = MaterialTheme.typography.labelSmall,
color = contentColor,
)
}
}

View file

@ -32,6 +32,7 @@ import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.tooling.preview.PreviewParameter
@ -51,7 +52,12 @@ private const val SIZE_ICON = 20
@Suppress("MagicNumber", "LongMethod")
@Composable
fun MaterialBatteryInfo(modifier: Modifier = Modifier, level: Int?, voltage: Float? = null) {
fun MaterialBatteryInfo(
modifier: Modifier = Modifier,
level: Int?,
voltage: Float? = null,
contentColor: Color = MaterialTheme.colorScheme.onSurface,
) {
val levelString = FORMAT.format(level)
Row(
@ -63,22 +69,18 @@ fun MaterialBatteryInfo(modifier: Modifier = Modifier, level: Int?, voltage: Flo
Icon(
modifier = Modifier.size(SIZE_ICON.dp),
imageVector = MeshtasticIcons.BatteryUnknown,
tint = MaterialTheme.colorScheme.onSurface,
tint = contentColor,
contentDescription = stringResource(R.string.unknown),
)
} else if (level > 100) {
Icon(
modifier = Modifier.size(SIZE_ICON.dp).rotate(90f),
imageVector = Icons.Rounded.Power,
tint = MaterialTheme.colorScheme.onSurface,
tint = contentColor,
contentDescription = levelString,
)
Text(
text = "PWD",
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.labelMedium,
)
Text(text = "PWD", color = contentColor, style = MaterialTheme.typography.labelMedium)
} else {
// Map battery percentage to color
val fillColor =
@ -108,24 +110,16 @@ fun MaterialBatteryInfo(modifier: Modifier = Modifier, level: Int?, voltage: Flo
)
},
imageVector = MeshtasticIcons.BatteryEmpty,
tint = MaterialTheme.colorScheme.onSurface,
tint = contentColor,
contentDescription = levelString,
)
Text(
text = levelString,
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.labelMedium,
)
Text(text = levelString, color = contentColor, style = MaterialTheme.typography.labelMedium)
}
voltage
?.takeIf { it > 0 }
?.let {
Text(
text = "%.2fV".format(it),
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.labelMedium,
)
Text(text = "%.2fV".format(it), color = contentColor, style = MaterialTheme.typography.labelMedium)
}
}
}

View file

@ -27,6 +27,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewLightDark
@ -42,7 +43,12 @@ const val MAX_VALID_RSSI = 0
@Suppress("LongMethod")
@Composable
fun SignalInfo(modifier: Modifier = Modifier, node: Node, isThisNode: Boolean) {
fun SignalInfo(
modifier: Modifier = Modifier,
node: Node,
isThisNode: Boolean,
contentColor: Color = MaterialTheme.colorScheme.onSurface,
) {
val text =
if (isThisNode) {
stringResource(R.string.channel_air_util)
@ -72,7 +78,7 @@ fun SignalInfo(modifier: Modifier = Modifier, node: Node, isThisNode: Boolean) {
verticalAlignment = Alignment.CenterVertically,
) {
if (text.isNotEmpty()) {
Text(text = text, color = MaterialTheme.colorScheme.onSurface, style = MaterialTheme.typography.labelSmall)
Text(text = text, color = contentColor, style = MaterialTheme.typography.labelSmall)
}
/* We only know the Signal Quality from direct nodes aka 0 hop. */
if (node.hopsAway <= 0) {
@ -98,7 +104,7 @@ fun SignalInfo(modifier: Modifier = Modifier, node: Node, isThisNode: Boolean) {
Text(
text = "${stringResource(R.string.signal)} ${stringResource(quality.nameRes)}",
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurface,
color = contentColor,
maxLines = 1,
)
}