feat: implement PacketResponseState.Loading (#630)

This commit is contained in:
Andre K 2023-05-08 17:31:07 -03:00 committed by GitHub
parent 7d1d793fb9
commit 70f7ffb5fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 133 additions and 39 deletions

View file

@ -31,11 +31,11 @@ fun EditDeviceProfileDialog(
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
) {
var longNameInput by remember { mutableStateOf(deviceProfile.hasLongName()) }
var shortNameInput by remember { mutableStateOf(deviceProfile.hasShortName()) }
var channelUrlInput by remember { mutableStateOf(deviceProfile.hasChannelUrl()) }
var configInput by remember { mutableStateOf(deviceProfile.hasConfig()) }
var moduleConfigInput by remember { mutableStateOf(deviceProfile.hasModuleConfig()) }
var longNameInput by remember(deviceProfile) { mutableStateOf(deviceProfile.hasLongName()) }
var shortNameInput by remember(deviceProfile) { mutableStateOf(deviceProfile.hasShortName()) }
var channelUrlInput by remember(deviceProfile) { mutableStateOf(deviceProfile.hasChannelUrl()) }
var configInput by remember(deviceProfile) { mutableStateOf(deviceProfile.hasConfig()) }
var moduleConfigInput by remember(deviceProfile) { mutableStateOf(deviceProfile.hasModuleConfig()) }
AlertDialog(
title = { Text(title) },

View file

@ -0,0 +1,69 @@
package com.geeksville.mesh.ui.components.config
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.AlertDialog
import androidx.compose.material.Button
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.geeksville.mesh.R
import com.geeksville.mesh.ui.PacketResponseState
@Composable
fun PacketResponseStateDialog(
state: PacketResponseState.Loading,
onDismiss: () -> Unit
) {
val progress = state.completed.toFloat() / state.total.toFloat()
AlertDialog(
onDismissRequest = { },
text = {
Column(
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,
)
}
},
buttons = {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
) {
Button(
onClick = onDismiss,
modifier = Modifier.padding(bottom = 16.dp)
) { Text(stringResource(R.string.cancel)) }
}
}
)
}
@Preview(showBackground = true)
@Composable
fun PacketResponseStateDialogPreview() {
PacketResponseStateDialog(
state = PacketResponseState.Loading.apply {
total = 17
completed = 5
},
onDismiss = { }
)
}