sforkowany z mirror/meshtastic-android
feat: implement `PacketResponseState.Error` (#633)
rodzic
2502bee55f
commit
068f5e7544
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue