revert(service): reverts a bunch of changes to MeshService.kt (#2692)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2025-08-12 17:19:40 -05:00 committed by GitHub
parent 1923b6d6d4
commit a35e43d979
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 1622 additions and 1603 deletions

View file

@ -593,7 +593,7 @@ private fun TopBarActions(
onAction: (Any?) -> Unit,
) {
val ourNode by viewModel.ourNodeInfo.collectAsStateWithLifecycle()
val isConnected by viewModel.isConnected.collectAsStateWithLifecycle(false)
val isConnected by viewModel.isConnectedStateFlow.collectAsStateWithLifecycle(false)
AnimatedVisibility(ourNode != null && currentDestination?.isTopLevel() == true && isConnected) {
ourNode?.let { NodeChip(node = it, isThisNode = true, isConnected = isConnected, onAction = onAction) }
}
@ -645,14 +645,12 @@ private fun ConnectionState.getConnectionColor(): Color = when (this) {
ConnectionState.CONNECTED -> colorScheme.StatusGreen
ConnectionState.DEVICE_SLEEP -> colorScheme.StatusYellow
ConnectionState.DISCONNECTED -> colorScheme.StatusRed
ConnectionState.CONNECTING -> colorScheme.StatusYellow
}
private fun ConnectionState.getConnectionIcon(): ImageVector = when (this) {
ConnectionState.CONNECTED -> Icons.TwoTone.CloudDone
ConnectionState.DEVICE_SLEEP -> Icons.TwoTone.CloudUpload
ConnectionState.DISCONNECTED -> Icons.TwoTone.CloudOff
ConnectionState.CONNECTING -> Icons.TwoTone.CloudUpload
}
@Composable
@ -660,5 +658,4 @@ private fun ConnectionState.getTooltipString(): String = when (this) {
ConnectionState.CONNECTED -> stringResource(R.string.connected)
ConnectionState.DEVICE_SLEEP -> stringResource(R.string.device_sleeping)
ConnectionState.DISCONNECTED -> stringResource(R.string.disconnected)
ConnectionState.CONNECTING -> stringResource(R.string.connecting_to_device)
}

View file

@ -214,7 +214,6 @@ fun ConnectionsScreen(
ConnectionState.DISCONNECTED -> R.string.not_connected
ConnectionState.DEVICE_SLEEP -> R.string.connected_sleeping
ConnectionState.CONNECTING -> R.string.connecting_to_device
}.let {
val firmwareString = info?.firmwareString ?: context.getString(R.string.unknown)
scanModel.setErrorText(context.getString(it, firmwareString))
@ -257,7 +256,7 @@ fun ConnectionsScreen(
Spacer(modifier = Modifier.height(8.dp))
val isConnected by uiViewModel.isConnected.collectAsState(false)
val isConnected by uiViewModel.isConnectedStateFlow.collectAsState(false)
val ourNode by uiViewModel.ourNodeInfo.collectAsState()
if (isConnected) {
ourNode?.let { node ->

View file

@ -442,6 +442,8 @@ fun MapView(model: UIViewModel = viewModel(), navigateToNodeDetails: (Int) -> Un
}
}
val isConnected = model.isConnectedStateFlow.collectAsStateWithLifecycle(false)
LaunchedEffect(showCurrentCacheInfo) {
if (!showCurrentCacheInfo) return@LaunchedEffect
model.showSnackbar(R.string.calculating)
@ -475,7 +477,7 @@ fun MapView(model: UIViewModel = viewModel(), navigateToNodeDetails: (Int) -> Un
override fun longPressHelper(p: GeoPoint): Boolean {
performHapticFeedback()
val enabled = model.isConnected() && downloadRegionBoundingBox == null
val enabled = isConnected.value && downloadRegionBoundingBox == null
if (enabled) {
showEditWaypointDialog = waypoint {

View file

@ -141,7 +141,7 @@ internal fun MessageScreen(
// State from ViewModel
val ourNode by viewModel.ourNodeInfo.collectAsStateWithLifecycle()
val isConnected by viewModel.isConnected.collectAsStateWithLifecycle(initialValue = false)
val isConnected by viewModel.isConnectedStateFlow.collectAsStateWithLifecycle(initialValue = false)
val channels by viewModel.channels.collectAsStateWithLifecycle()
val quickChatActions by viewModel.quickChatActions.collectAsStateWithLifecycle(initialValue = emptyList())
val messages by viewModel.getMessagesFrom(contactKey).collectAsStateWithLifecycle(initialValue = emptyList())

View file

@ -70,17 +70,15 @@ fun DeliveryInfo(
) = AlertDialog(
onDismissRequest = onDismiss,
dismissButton = {
FilledTonalButton(
onClick = onDismiss,
modifier = Modifier.padding(horizontal = 16.dp),
) { Text(text = stringResource(id = R.string.close)) }
FilledTonalButton(onClick = onDismiss, modifier = Modifier.padding(horizontal = 16.dp)) {
Text(text = stringResource(id = R.string.close))
}
},
confirmButton = {
if (resendOption) {
FilledTonalButton(
onClick = onConfirm,
modifier = Modifier.padding(horizontal = 16.dp),
) { Text(text = stringResource(id = R.string.resend)) }
FilledTonalButton(onClick = onConfirm, modifier = Modifier.padding(horizontal = 16.dp)) {
Text(text = stringResource(id = R.string.resend))
}
}
},
title = {
@ -88,7 +86,7 @@ fun DeliveryInfo(
text = stringResource(id = title),
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.headlineSmall
style = MaterialTheme.typography.headlineSmall,
)
},
text = {
@ -97,12 +95,12 @@ fun DeliveryInfo(
text = stringResource(id = it),
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodyMedium
style = MaterialTheme.typography.bodyMedium,
)
}
},
shape = RoundedCornerShape(16.dp),
containerColor = MaterialTheme.colorScheme.surface
containerColor = MaterialTheme.colorScheme.surface,
)
@Suppress("LongMethod")
@ -138,7 +136,7 @@ internal fun MessageList(
viewModel.sendMessage(msg.text, contactKey)
},
onDismiss = { showStatusDialog = null },
resendOption = msg.status?.equals(MessageStatus.ERROR) ?: false
resendOption = msg.status?.equals(MessageStatus.ERROR) ?: false,
)
}
@ -156,19 +154,13 @@ internal fun MessageList(
val nodes by viewModel.nodeList.collectAsStateWithLifecycle()
val ourNode by viewModel.ourNodeInfo.collectAsStateWithLifecycle()
val isConnected by viewModel.isConnected.collectAsStateWithLifecycle(false)
val isConnected by viewModel.isConnectedStateFlow.collectAsStateWithLifecycle(false)
val coroutineScope = rememberCoroutineScope()
LazyColumn(
modifier = modifier.fillMaxSize(),
state = listState,
reverseLayout = true,
) {
LazyColumn(modifier = modifier.fillMaxSize(), state = listState, reverseLayout = true) {
items(messages, key = { it.uuid }) { msg ->
if (ourNode != null) {
val selected by remember { derivedStateOf { selectedIds.value.contains(msg.uuid) } }
val node by remember {
derivedStateOf { nodes.find { it.num == msg.node.num } ?: msg.node }
}
val node by remember { derivedStateOf { nodes.find { it.num == msg.node.num } ?: msg.node } }
MessageItem(
modifier = Modifier.animateItem(),
@ -195,7 +187,7 @@ internal fun MessageList(
listState.animateScrollToItem(index = targetIndex)
}
}
}
},
)
}
}
@ -203,11 +195,7 @@ internal fun MessageList(
}
@Composable
private fun <T> AutoScrollToBottom(
listState: LazyListState,
list: List<T>,
itemThreshold: Int = 3,
) = with(listState) {
private fun <T> AutoScrollToBottom(listState: LazyListState, list: List<T>, itemThreshold: Int = 3) = with(listState) {
val shouldAutoScroll by remember { derivedStateOf { firstVisibleItemIndex < itemThreshold } }
if (shouldAutoScroll) {
LaunchedEffect(list) {
@ -220,11 +208,7 @@ private fun <T> AutoScrollToBottom(
@OptIn(FlowPreview::class)
@Composable
private fun UpdateUnreadCount(
listState: LazyListState,
messages: List<Message>,
onUnreadChanged: (Long) -> Unit,
) {
private fun UpdateUnreadCount(listState: LazyListState, messages: List<Message>, onUnreadChanged: (Long) -> Unit) {
LaunchedEffect(messages) {
snapshotFlow { listState.firstVisibleItemIndex }
.debounce(timeoutMillis = 500L)