mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix: allow forgetting of network nodes (#3820)
This commit is contained in:
parent
e9383e20dc
commit
fb2aebf637
4 changed files with 36 additions and 9 deletions
|
|
@ -17,7 +17,11 @@
|
|||
|
||||
package com.geeksville.mesh.ui.connections.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.Indication
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.indication
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
|
|
@ -35,8 +39,10 @@ import androidx.compose.material3.ListItemDefaults
|
|||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.geeksville.mesh.model.DeviceListEntry
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
|
@ -55,6 +61,7 @@ fun DeviceListItem(
|
|||
device: DeviceListEntry,
|
||||
onSelect: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
onDelete: (() -> Unit)? = null,
|
||||
) {
|
||||
val icon =
|
||||
when (device) {
|
||||
|
|
@ -81,10 +88,19 @@ fun DeviceListItem(
|
|||
}
|
||||
|
||||
val useSelectable = modifier == Modifier
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val indication: Indication = LocalIndication.current
|
||||
|
||||
ListItem(
|
||||
modifier =
|
||||
if (useSelectable) {
|
||||
modifier.fillMaxWidth().clickable(onClick = onSelect)
|
||||
if (useSelectable && onDelete != null) {
|
||||
modifier.fillMaxWidth().indication(interactionSource, indication).pointerInput(onDelete) {
|
||||
detectTapGestures(onTap = { onSelect() }, onLongPress = { onDelete() })
|
||||
}
|
||||
} else if (useSelectable) {
|
||||
modifier.fillMaxWidth().indication(interactionSource, indication).pointerInput(Unit) {
|
||||
detectTapGestures(onTap = { onSelect() })
|
||||
}
|
||||
} else {
|
||||
modifier.fillMaxWidth()
|
||||
},
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ fun List<DeviceListEntry>.DeviceListSection(
|
|||
selectedDevice: String,
|
||||
onSelect: (DeviceListEntry) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
onDelete: ((DeviceListEntry) -> Unit)? = null,
|
||||
) {
|
||||
if (isNotEmpty()) {
|
||||
TitledCard(title = title, modifier = modifier) {
|
||||
|
|
@ -39,6 +40,7 @@ fun List<DeviceListEntry>.DeviceListSection(
|
|||
connectionState.takeIf { device.fullAddress == selectedDevice } ?: ConnectionState.Disconnected,
|
||||
device = device,
|
||||
onSelect = { onSelect(device) },
|
||||
onDelete = onDelete?.let { delete -> { delete(device) } },
|
||||
modifier = Modifier.Companion,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@ import org.meshtastic.core.service.ConnectionState
|
|||
import org.meshtastic.core.strings.Res
|
||||
import org.meshtastic.core.strings.add_network_device
|
||||
import org.meshtastic.core.strings.cancel
|
||||
import org.meshtastic.core.strings.confirm_delete_node
|
||||
import org.meshtastic.core.strings.delete
|
||||
import org.meshtastic.core.strings.confirm_forget_connection
|
||||
import org.meshtastic.core.strings.discovered_network_devices
|
||||
import org.meshtastic.core.strings.forget_connection
|
||||
import org.meshtastic.core.strings.ip_address
|
||||
import org.meshtastic.core.strings.ip_port
|
||||
import org.meshtastic.core.strings.no_network_devices
|
||||
|
|
@ -100,7 +100,10 @@ fun NetworkDevices(
|
|||
deviceToDelete?.let {
|
||||
ConfirmDeleteDialog(
|
||||
it.fullAddress,
|
||||
onHideDialog = { showDeleteDialog = false },
|
||||
onHideDialog = {
|
||||
showDeleteDialog = false
|
||||
deviceToDelete = null
|
||||
},
|
||||
onConfirm = { deviceFullAddress -> scanModel.removeRecentAddress(deviceFullAddress) },
|
||||
)
|
||||
}
|
||||
|
|
@ -133,6 +136,10 @@ fun NetworkDevices(
|
|||
connectionState = connectionState,
|
||||
selectedDevice = selectedDevice,
|
||||
onSelect = scanModel::onSelected,
|
||||
onDelete = { device ->
|
||||
deviceToDelete = device
|
||||
showDeleteDialog = true
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -233,8 +240,8 @@ private fun ConfirmDeleteDialog(
|
|||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onHideDialog,
|
||||
title = { Text(stringResource(Res.string.delete)) },
|
||||
text = { Text(stringResource(Res.string.confirm_delete_node)) },
|
||||
title = { Text(stringResource(Res.string.forget_connection)) },
|
||||
text = { Text(stringResource(Res.string.confirm_forget_connection)) },
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = {
|
||||
|
|
@ -242,7 +249,7 @@ private fun ConfirmDeleteDialog(
|
|||
onHideDialog()
|
||||
},
|
||||
) {
|
||||
Text(stringResource(Res.string.delete))
|
||||
Text(stringResource(Res.string.forget_connection))
|
||||
}
|
||||
},
|
||||
dismissButton = { Button(onClick = { onHideDialog() }) { Text(stringResource(Res.string.cancel)) } },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue