diff --git a/app/src/main/java/com/geeksville/mesh/ui/DeviceSettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/DeviceSettingsFragment.kt index bb0761fe..8a01a3cc 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/DeviceSettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/DeviceSettingsFragment.kt @@ -225,8 +225,8 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) { } ) - if (isWaiting) PacketResponseStateDialog( - packetResponseState as PacketResponseState.Loading, + if (isWaiting || packetResponseState is PacketResponseState.Error) PacketResponseStateDialog( + packetResponseState, onDismiss = { packetResponseState = PacketResponseState.Empty viewModel.clearPacketResponse() @@ -235,6 +235,11 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) { if (isWaiting) LaunchedEffect(configResponse) { val data = configResponse?.meshPacket?.decoded + if (data?.portnumValue == Portnums.PortNum.ROUTING_APP_VALUE) { + val parsed = MeshProtos.Routing.parseFrom(data.payload) + if (parsed.errorReason != MeshProtos.Routing.Error.NONE) + packetResponseState = PacketResponseState.Error(parsed.errorReason.toString()) + } if (data?.portnumValue == Portnums.PortNum.ADMIN_APP_VALUE) { viewModel.clearPacketResponse() val parsed = AdminProtos.AdminMessage.parseFrom(data.payload) diff --git a/app/src/main/java/com/geeksville/mesh/ui/components/config/PacketResponseStateDialog.kt b/app/src/main/java/com/geeksville/mesh/ui/components/config/PacketResponseStateDialog.kt index fe90b45f..168d69a1 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/components/config/PacketResponseStateDialog.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/components/config/PacketResponseStateDialog.kt @@ -21,10 +21,9 @@ import com.geeksville.mesh.ui.PacketResponseState @Composable fun PacketResponseStateDialog( - state: PacketResponseState.Loading, + state: PacketResponseState, onDismiss: () -> Unit ) { - val progress = state.completed.toFloat() / state.total.toFloat() AlertDialog( onDismissRequest = { }, text = { @@ -32,14 +31,20 @@ fun PacketResponseStateDialog( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally ) { - Text("%.0f%%".format(progress * 100)) - LinearProgressIndicator( - progress = progress, - modifier = Modifier - .fillMaxWidth() - .padding(top = 8.dp), - color = MaterialTheme.colors.onSurface, - ) + if (state is PacketResponseState.Loading) { + val progress = state.completed.toFloat() / state.total.toFloat() + Text("%.0f%%".format(progress * 100)) + LinearProgressIndicator( + progress = progress, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + color = MaterialTheme.colors.onSurface, + ) + } + if (state is PacketResponseState.Error) { + Text("Error: ${state.error}") + } } }, buttons = { @@ -50,7 +55,13 @@ fun PacketResponseStateDialog( Button( onClick = onDismiss, modifier = Modifier.padding(bottom = 16.dp) - ) { Text(stringResource(R.string.cancel)) } + ) { + if (state is PacketResponseState.Loading) { + Text(stringResource(R.string.cancel)) + } else { + Text(stringResource(R.string.close)) + } + } } } )