Skip to content

Commit fb2aebf

Browse files
authored
fix: allow forgetting of network nodes (#3820)
1 parent e9383e2 commit fb2aebf

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

app/src/main/java/com/geeksville/mesh/ui/connections/components/DeviceListItem.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717

1818
package com.geeksville.mesh.ui.connections.components
1919

20-
import androidx.compose.foundation.clickable
20+
import androidx.compose.foundation.Indication
21+
import androidx.compose.foundation.LocalIndication
22+
import androidx.compose.foundation.gestures.detectTapGestures
23+
import androidx.compose.foundation.indication
24+
import androidx.compose.foundation.interaction.MutableInteractionSource
2125
import androidx.compose.foundation.layout.fillMaxWidth
2226
import androidx.compose.foundation.layout.size
2327
import androidx.compose.material.icons.Icons
@@ -35,8 +39,10 @@ import androidx.compose.material3.ListItemDefaults
3539
import androidx.compose.material3.RadioButton
3640
import androidx.compose.material3.Text
3741
import androidx.compose.runtime.Composable
42+
import androidx.compose.runtime.remember
3843
import androidx.compose.ui.Modifier
3944
import androidx.compose.ui.graphics.Color
45+
import androidx.compose.ui.input.pointer.pointerInput
4046
import androidx.compose.ui.unit.dp
4147
import com.geeksville.mesh.model.DeviceListEntry
4248
import org.jetbrains.compose.resources.stringResource
@@ -55,6 +61,7 @@ fun DeviceListItem(
5561
device: DeviceListEntry,
5662
onSelect: () -> Unit,
5763
modifier: Modifier = Modifier,
64+
onDelete: (() -> Unit)? = null,
5865
) {
5966
val icon =
6067
when (device) {
@@ -81,10 +88,19 @@ fun DeviceListItem(
8188
}
8289

8390
val useSelectable = modifier == Modifier
91+
val interactionSource = remember { MutableInteractionSource() }
92+
val indication: Indication = LocalIndication.current
93+
8494
ListItem(
8595
modifier =
86-
if (useSelectable) {
87-
modifier.fillMaxWidth().clickable(onClick = onSelect)
96+
if (useSelectable && onDelete != null) {
97+
modifier.fillMaxWidth().indication(interactionSource, indication).pointerInput(onDelete) {
98+
detectTapGestures(onTap = { onSelect() }, onLongPress = { onDelete() })
99+
}
100+
} else if (useSelectable) {
101+
modifier.fillMaxWidth().indication(interactionSource, indication).pointerInput(Unit) {
102+
detectTapGestures(onTap = { onSelect() })
103+
}
88104
} else {
89105
modifier.fillMaxWidth()
90106
},

app/src/main/java/com/geeksville/mesh/ui/connections/components/DeviceListSection.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fun List<DeviceListEntry>.DeviceListSection(
3030
selectedDevice: String,
3131
onSelect: (DeviceListEntry) -> Unit,
3232
modifier: Modifier = Modifier,
33+
onDelete: ((DeviceListEntry) -> Unit)? = null,
3334
) {
3435
if (isNotEmpty()) {
3536
TitledCard(title = title, modifier = modifier) {
@@ -39,6 +40,7 @@ fun List<DeviceListEntry>.DeviceListSection(
3940
connectionState.takeIf { device.fullAddress == selectedDevice } ?: ConnectionState.Disconnected,
4041
device = device,
4142
onSelect = { onSelect(device) },
43+
onDelete = onDelete?.let { delete -> { delete(device) } },
4244
modifier = Modifier.Companion,
4345
)
4446
}

app/src/main/java/com/geeksville/mesh/ui/connections/components/NetworkDevices.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ import org.meshtastic.core.service.ConnectionState
5959
import org.meshtastic.core.strings.Res
6060
import org.meshtastic.core.strings.add_network_device
6161
import org.meshtastic.core.strings.cancel
62-
import org.meshtastic.core.strings.confirm_delete_node
63-
import org.meshtastic.core.strings.delete
62+
import org.meshtastic.core.strings.confirm_forget_connection
6463
import org.meshtastic.core.strings.discovered_network_devices
64+
import org.meshtastic.core.strings.forget_connection
6565
import org.meshtastic.core.strings.ip_address
6666
import org.meshtastic.core.strings.ip_port
6767
import org.meshtastic.core.strings.no_network_devices
@@ -100,7 +100,10 @@ fun NetworkDevices(
100100
deviceToDelete?.let {
101101
ConfirmDeleteDialog(
102102
it.fullAddress,
103-
onHideDialog = { showDeleteDialog = false },
103+
onHideDialog = {
104+
showDeleteDialog = false
105+
deviceToDelete = null
106+
},
104107
onConfirm = { deviceFullAddress -> scanModel.removeRecentAddress(deviceFullAddress) },
105108
)
106109
}
@@ -133,6 +136,10 @@ fun NetworkDevices(
133136
connectionState = connectionState,
134137
selectedDevice = selectedDevice,
135138
onSelect = scanModel::onSelected,
139+
onDelete = { device ->
140+
deviceToDelete = device
141+
showDeleteDialog = true
142+
},
136143
)
137144
}
138145

@@ -233,16 +240,16 @@ private fun ConfirmDeleteDialog(
233240
) {
234241
AlertDialog(
235242
onDismissRequest = onHideDialog,
236-
title = { Text(stringResource(Res.string.delete)) },
237-
text = { Text(stringResource(Res.string.confirm_delete_node)) },
243+
title = { Text(stringResource(Res.string.forget_connection)) },
244+
text = { Text(stringResource(Res.string.confirm_forget_connection)) },
238245
confirmButton = {
239246
Button(
240247
onClick = {
241248
onConfirm(fullAddressToDelete)
242249
onHideDialog()
243250
},
244251
) {
245-
Text(stringResource(Res.string.delete))
252+
Text(stringResource(Res.string.forget_connection))
246253
}
247254
},
248255
dismissButton = { Button(onClick = { onHideDialog() }) { Text(stringResource(Res.string.cancel)) } },

core/strings/src/commonMain/composeResources/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,8 @@
825825
<string name="security_icon_help_dismiss">Dismiss</string>
826826

827827
<string name="confirm_delete_node">Are you sure you want to delete this node?</string>
828+
<string name="forget_connection">Forget connection</string>
829+
<string name="confirm_forget_connection">Are you sure you want to forget this connection?</string>
828830

829831
<string name="replying_to">Replying to %1$s</string>
830832
<string name="cancel_reply">Cancel reply</string>

0 commit comments

Comments
 (0)