Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.meshtastic.core.ui.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -52,11 +53,11 @@ import org.meshtastic.core.ui.theme.StatusColors.StatusRed

private const val SIZE_ICON = 16

@Suppress("MagicNumber", "LongMethod")
@Suppress("MagicNumber")
@Composable
fun MaterialBatteryInfo(
modifier: Modifier = Modifier,
level: Int?,
modifier: Modifier = Modifier,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
voltage: Float? = null,
contentColor: Color = MaterialTheme.colorScheme.onSurface,
unknownLabel: String = stringResource(Res.string.unknown),
Expand All @@ -67,6 +68,43 @@ fun MaterialBatteryInfo(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(1.dp),
) {
Percents(level, contentColor, unknownLabel, levelString)
Volts(voltage, contentColor)
}
}

@Suppress("MagicNumber")
@Composable
fun MaterialBatteryCompactInfo(
level: Int?,
modifier: Modifier = Modifier,
voltage: Float? = null,
contentColor: Color = MaterialTheme.colorScheme.onSurface,
unknownLabel: String = stringResource(Res.string.unknown),
) {
val levelString = level?.let { MetricFormatter.percent(it) } ?: unknownLabel

Column(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(1.dp),
) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(1.dp)) {
Percents(level, contentColor, unknownLabel, levelString)
}
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(1.dp)) {
Volts(voltage, contentColor)
}
}
}

@Composable
@Suppress("MagicNumber")
private fun Percents(level: Int?, contentColor: Color, unknownLabel: String, levelString: String) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(1.dp),
) {
if (level == null || level < 0) {
Icon(
Expand All @@ -86,7 +124,11 @@ fun MaterialBatteryInfo(
Text(
text = stringResource(Res.string.external_power_short),
color = contentColor.copy(alpha = 0.95f),
style = MaterialTheme.typography.labelMedium.copy(fontWeight = FontWeight.SemiBold, fontSize = 12.sp),
style =
MaterialTheme.typography.labelMedium.copy(
fontWeight = FontWeight.SemiBold,
fontSize = 12.sp,
),
)
} else {
// Map battery percentage to color
Expand Down Expand Up @@ -125,21 +167,30 @@ fun MaterialBatteryInfo(
Text(
text = levelString,
color = contentColor.copy(alpha = 0.95f),
style = MaterialTheme.typography.labelMedium.copy(fontWeight = FontWeight.SemiBold, fontSize = 12.sp),
style =
MaterialTheme.typography.labelMedium.copy(
fontWeight = FontWeight.SemiBold,
fontSize = 12.sp,
),
)
}
voltage
?.takeIf { it > 0 }
?.let {
Text(
text = MetricFormatter.voltage(it),
color = contentColor.copy(alpha = 0.8f),
style = MaterialTheme.typography.labelMedium.copy(fontSize = 12.sp),
)
}
}
}

@Composable
@Suppress("MagicNumber")
private fun Volts(voltage: Float?, contentColor: Color) {
voltage
?.takeIf { it > 0 }
?.let {
Text(
text = MetricFormatter.voltage(it),
color = contentColor.copy(alpha = 0.8f),
style = MaterialTheme.typography.labelMedium.copy(fontSize = 12.sp),
)
}
}

class BatteryInfoPreviewParameterProvider : PreviewParameterProvider<Pair<Int?, Float?>> {
override val values: Sequence<Pair<Int?, Float?>>
get() =
Expand All @@ -157,6 +208,16 @@ class BatteryInfoPreviewParameterProvider : PreviewParameterProvider<Pair<Int?,

@PreviewLightDark
@Composable
fun MaterialBatteryInfoPreview(@PreviewParameter(BatteryInfoPreviewParameterProvider::class) info: Pair<Int?, Float?>) {
private fun MaterialBatteryInfoPreview(
@PreviewParameter(BatteryInfoPreviewParameterProvider::class) info: Pair<Int?, Float?>,
) {
AppTheme { MaterialBatteryInfo(level = info.first, voltage = info.second) }
}

@PreviewLightDark
@Composable
private fun MaterialBatteryCompactInfoPreview(
@PreviewParameter(BatteryInfoPreviewParameterProvider::class) info: Pair<Int?, Float?>,
) {
AppTheme { MaterialBatteryCompactInfo(level = info.first, voltage = info.second) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -187,19 +186,19 @@ fun NodeItemCompact(
onLongClick = onLongClick,
)
.fillMaxWidth()
.padding(horizontal = 12.dp, vertical = 8.dp),
.padding(start = 12.dp, top = 2.dp, end = 12.dp, bottom = 8.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalAlignment = Alignment.Top,
) {
// Column 1: Chip + Battery (fixed width)
// Column 1: Chip + Battery
Column(
modifier = Modifier.widthIn(min = 90.dp),
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.spacedBy(4.dp),
modifier = Modifier.padding(vertical = 10.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(6.dp),
) {
NodeChip(node = thatNode)
if (showPower && (thatNode.batteryLevel ?: 0) > 0) {
MaterialBatteryInfo(
MaterialBatteryCompactInfo(
level = thatNode.batteryLevel ?: 0,
voltage = thatNode.voltage ?: 0f,
contentColor = contentColor,
Expand Down Expand Up @@ -269,7 +268,7 @@ private fun CompactNameRow(
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(6.dp),
horizontalArrangement = Arrangement.spacedBy(2.dp),
) {
NodeSecurityIcons(thatNode, iconSize = 18.dp, isThisNode = isThisNode)
Text(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading