mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: Initial implementation of adding nodes to favorites (#1520)
* Implement initial support for adding and removing nodes from favorites * Make favorite nodes' names show up bold in the node list * Forgot to add this here when I was fixing the previous merge conflicts. Whoops! * Make detekt happy --------- Co-authored-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
584fe8d6f8
commit
e15ad23c46
7 changed files with 70 additions and 1 deletions
|
|
@ -84,6 +84,7 @@ fun NodeItem(
|
|||
currentTimeMillis: Long,
|
||||
isConnected: Boolean = false,
|
||||
) {
|
||||
val isFavorite = thatNode.isFavorite
|
||||
val isIgnored = thatNode.isIgnored
|
||||
val longName = thatNode.user.longName.ifEmpty { stringResource(id = R.string.unknown_username) }
|
||||
|
||||
|
|
@ -150,7 +151,7 @@ fun NodeItem(
|
|||
Text(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
text = thatNode.user.shortName.ifEmpty { "???" },
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontWeight = if (isFavorite) FontWeight.Bold else FontWeight.Normal,
|
||||
fontSize = MaterialTheme.typography.button.fontSize,
|
||||
textDecoration = TextDecoration.LineThrough.takeIf { isIgnored },
|
||||
textAlign = TextAlign.Center,
|
||||
|
|
@ -173,6 +174,7 @@ fun NodeItem(
|
|||
Text(
|
||||
modifier = Modifier.weight(1f),
|
||||
text = longName,
|
||||
fontWeight = if (isFavorite) FontWeight.Bold else FontWeight.Normal,
|
||||
style = style,
|
||||
textDecoration = TextDecoration.LineThrough.takeIf { isIgnored },
|
||||
softWrap = true,
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ fun NodesScreen(
|
|||
when (menuItem) {
|
||||
is NodeMenuAction.Remove -> model.removeNode(node.num)
|
||||
is NodeMenuAction.Ignore -> model.ignoreNode(node)
|
||||
is NodeMenuAction.Favorite -> model.favoriteNode(node)
|
||||
is NodeMenuAction.DirectMessage -> navigateToMessages(node)
|
||||
is NodeMenuAction.RequestUserInfo -> model.requestUserInfo(node.num)
|
||||
is NodeMenuAction.RequestPosition -> model.requestPosition(node.num)
|
||||
|
|
|
|||
|
|
@ -47,8 +47,25 @@ fun NodeMenu(
|
|||
expanded: Boolean = false,
|
||||
onAction: (NodeMenuAction) -> Unit
|
||||
) {
|
||||
var displayFavoriteDialog by remember { mutableStateOf(false) }
|
||||
var displayIgnoreDialog by remember { mutableStateOf(false) }
|
||||
var displayRemoveDialog by remember { mutableStateOf(false) }
|
||||
if (displayFavoriteDialog) {
|
||||
SimpleAlertDialog(
|
||||
title = R.string.favorite,
|
||||
text = stringResource(
|
||||
id = if (node.isFavorite) R.string.favorite_remove else R.string.favorite_add,
|
||||
node.user.longName
|
||||
),
|
||||
onConfirm = {
|
||||
displayFavoriteDialog = false
|
||||
onAction(NodeMenuAction.Favorite(node))
|
||||
},
|
||||
onDismiss = {
|
||||
displayFavoriteDialog = false
|
||||
}
|
||||
)
|
||||
}
|
||||
if (displayIgnoreDialog) {
|
||||
SimpleAlertDialog(
|
||||
title = R.string.ignore,
|
||||
|
|
@ -113,6 +130,25 @@ fun NodeMenu(
|
|||
},
|
||||
content = { Text(stringResource(R.string.traceroute)) }
|
||||
)
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
onDismissRequest()
|
||||
displayFavoriteDialog = true
|
||||
},
|
||||
enabled = !node.isIgnored,
|
||||
) {
|
||||
Text(stringResource(R.string.favorite))
|
||||
Spacer(Modifier.weight(1f))
|
||||
Checkbox(
|
||||
checked = node.isFavorite,
|
||||
onCheckedChange = {
|
||||
onDismissRequest()
|
||||
displayFavoriteDialog = true
|
||||
},
|
||||
modifier = Modifier.size(24.dp),
|
||||
enabled = !node.isIgnored,
|
||||
)
|
||||
}
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
onDismissRequest()
|
||||
|
|
@ -152,6 +188,7 @@ fun NodeMenu(
|
|||
sealed class NodeMenuAction {
|
||||
data class Remove(val node: Node) : NodeMenuAction()
|
||||
data class Ignore(val node: Node) : NodeMenuAction()
|
||||
data class Favorite(val node: Node) : NodeMenuAction()
|
||||
data class DirectMessage(val node: Node) : NodeMenuAction()
|
||||
data class RequestUserInfo(val node: Node) : NodeMenuAction()
|
||||
data class RequestPosition(val node: Node) : NodeMenuAction()
|
||||
|
|
|
|||
|
|
@ -283,6 +283,7 @@ internal fun MessageScreen(
|
|||
when (action) {
|
||||
is NodeMenuAction.Remove -> viewModel.removeNode(action.node.num)
|
||||
is NodeMenuAction.Ignore -> viewModel.ignoreNode(action.node)
|
||||
is NodeMenuAction.Favorite -> viewModel.favoriteNode(action.node)
|
||||
is NodeMenuAction.DirectMessage -> navigateToMessages(action.node)
|
||||
is NodeMenuAction.RequestUserInfo -> viewModel.requestUserInfo(action.node.num)
|
||||
is NodeMenuAction.RequestPosition -> viewModel.requestPosition(action.node.num)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue