|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 Meshtastic LLC |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | +package org.meshtastic.feature.map.component |
| 18 | + |
| 19 | +import androidx.compose.foundation.layout.Arrangement |
| 20 | +import androidx.compose.foundation.layout.Column |
| 21 | +import androidx.compose.foundation.layout.Row |
| 22 | +import androidx.compose.foundation.layout.Spacer |
| 23 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 24 | +import androidx.compose.foundation.layout.height |
| 25 | +import androidx.compose.foundation.layout.padding |
| 26 | +import androidx.compose.material3.Button |
| 27 | +import androidx.compose.material3.ExperimentalMaterial3Api |
| 28 | +import androidx.compose.material3.MaterialTheme |
| 29 | +import androidx.compose.material3.ModalBottomSheet |
| 30 | +import androidx.compose.material3.Text |
| 31 | +import androidx.compose.material3.rememberModalBottomSheetState |
| 32 | +import androidx.compose.runtime.Composable |
| 33 | +import androidx.compose.ui.Alignment |
| 34 | +import androidx.compose.ui.Modifier |
| 35 | +import androidx.compose.ui.unit.dp |
| 36 | +import org.jetbrains.compose.resources.stringResource |
| 37 | +import org.meshtastic.core.model.Node |
| 38 | +import org.meshtastic.core.resources.Res |
| 39 | +import org.meshtastic.core.resources.view_details |
| 40 | +import org.meshtastic.core.ui.component.LastHeardInfo |
| 41 | +import org.meshtastic.core.ui.component.MaterialBatteryInfo |
| 42 | +import org.meshtastic.core.ui.component.SignalInfo |
| 43 | + |
| 44 | +/** |
| 45 | + * A modal bottom sheet showing a compact summary of a node when tapped on the map. Provides quick info (name, last |
| 46 | + * heard, battery, signal) and a button to navigate to full details. |
| 47 | + */ |
| 48 | +@OptIn(ExperimentalMaterial3Api::class) |
| 49 | +@Composable |
| 50 | +internal fun NodeInfoSheet(node: Node, onDismiss: () -> Unit, onViewDetails: (Int) -> Unit) { |
| 51 | + val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) |
| 52 | + |
| 53 | + ModalBottomSheet(onDismissRequest = onDismiss, sheetState = sheetState) { |
| 54 | + Column(modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp, vertical = 16.dp)) { |
| 55 | + // Node name |
| 56 | + Text( |
| 57 | + text = node.user.long_name.ifBlank { node.user.short_name }, |
| 58 | + style = MaterialTheme.typography.titleLarge, |
| 59 | + ) |
| 60 | + if (node.user.long_name.isNotBlank() && node.user.short_name.isNotBlank()) { |
| 61 | + Text( |
| 62 | + text = node.user.short_name, |
| 63 | + style = MaterialTheme.typography.bodyMedium, |
| 64 | + color = MaterialTheme.colorScheme.onSurfaceVariant, |
| 65 | + ) |
| 66 | + } |
| 67 | + |
| 68 | + Spacer(Modifier.height(16.dp)) |
| 69 | + |
| 70 | + // Info row: last heard, battery, signal |
| 71 | + Row( |
| 72 | + modifier = Modifier.fillMaxWidth(), |
| 73 | + horizontalArrangement = Arrangement.spacedBy(16.dp), |
| 74 | + verticalAlignment = Alignment.CenterVertically, |
| 75 | + ) { |
| 76 | + LastHeardInfo(lastHeard = node.lastHeard, showLabel = false) |
| 77 | + MaterialBatteryInfo(level = node.batteryLevel) |
| 78 | + SignalInfo(node = node) |
| 79 | + } |
| 80 | + |
| 81 | + Spacer(Modifier.height(24.dp)) |
| 82 | + |
| 83 | + // View details button |
| 84 | + Button(onClick = { onViewDetails(node.num) }, modifier = Modifier.fillMaxWidth()) { |
| 85 | + Text(stringResource(Res.string.view_details)) |
| 86 | + } |
| 87 | + |
| 88 | + Spacer(Modifier.height(8.dp)) |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments