Finish implementation of MainScreen

This commit is contained in:
William Brawner 2022-03-03 19:21:57 -07:00
parent 2a6c469f07
commit 6165886416

View file

@ -133,10 +133,10 @@ fun DisableControls(viewModel: PiHelperViewModel = hiltViewModel()) {
PrimaryButton("Disable for 10 seconds") { viewModel.disablePiHole(10) } PrimaryButton("Disable for 10 seconds") { viewModel.disablePiHole(10) }
PrimaryButton("Disable for 30 seconds") { viewModel.disablePiHole(30) } PrimaryButton("Disable for 30 seconds") { viewModel.disablePiHole(30) }
PrimaryButton("Disable for 5 minutes") { viewModel.disablePiHole(300) } PrimaryButton("Disable for 5 minutes") { viewModel.disablePiHole(300) }
PrimaryButton("Disable for custom time") { /* TODO: Show dialog for custom input */ } PrimaryButton("Disable for custom time") { setDialogVisible(true) }
PrimaryButton("Disable permanently") { viewModel.disablePiHole() } PrimaryButton("Disable permanently") { viewModel.disablePiHole() }
CustomTimeDialog(dialogVisible, setDialogVisible) { CustomTimeDialog(dialogVisible, setDialogVisible) {
viewModel.disablePiHole(it)
} }
} }
} }
@ -173,44 +173,50 @@ fun CustomTimeDialog(
mutableStateOf(Duration.SECONDS) mutableStateOf(Duration.SECONDS)
} }
AlertDialog( AlertDialog(
shape = MaterialTheme.shapes.small,
onDismissRequest = { setVisible(false) }, onDismissRequest = { setVisible(false) },
buttons = { buttons = {
Row { Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End
) {
TextButton({ setVisible(false) }) { TextButton({ setVisible(false) }) {
Text("Cancel") Text("Cancel")
} }
TextButton(onClick = { TextButton(onClick = {
// TODO: Move this math to the viewmodel or repository // TODO: Move this math to the viewmodel or repository
onTimeSelected(time * (60.0.pow(duration.ordinal)).roundToLong()) onTimeSelected(time.toLong() * (60.0.pow(duration.ordinal)).roundToLong())
setVisible(false) setVisible(false)
}) { }) {
Text("Disable") Text("Disable")
} }
} }
}, },
title = { Text("Disable for custom time") }, title = { Text("Disable for custom time: ") },
text = { text = {
Column( Column(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
TextField( OutlinedTextField(
value = time.toString(), value = time,
onValueChange = { setTime(it.toLong()) }, onValueChange = { setTime(it) },
placeholder = { Text("Time to disable") } placeholder = { Text("Time to disable") }
) )
Row(modifier = Modifier.fillMaxWidth()) { Row(
DurationRadio( modifier = Modifier.fillMaxWidth()
) {
DurationToggle(
selected = duration == Duration.SECONDS, selected = duration == Duration.SECONDS,
onClick = { selectDuration(Duration.SECONDS) }, onClick = { selectDuration(Duration.SECONDS) },
text = "Seconds" text = "Seconds"
) )
DurationRadio( DurationToggle(
selected = duration == Duration.MINUTES, selected = duration == Duration.MINUTES,
onClick = { selectDuration(Duration.MINUTES) }, onClick = { selectDuration(Duration.MINUTES) },
text = "Minutes" text = "Minutes"
) )
DurationRadio( DurationToggle(
selected = duration == Duration.HOURS, selected = duration == Duration.HOURS,
onClick = { selectDuration(Duration.HOURS) }, onClick = { selectDuration(Duration.HOURS) },
text = "Hours" text = "Hours"
@ -222,13 +228,27 @@ fun CustomTimeDialog(
} }
@Composable @Composable
fun DurationRadio(selected: Boolean, onClick: () -> Unit, text: String) { fun DurationToggle(selected: Boolean, onClick: () -> Unit, text: String) {
Row(modifier = Modifier.selectable(selected = selected, onClick = onClick)) { Row(
RadioButton( modifier = Modifier.selectable(selected = selected, onClick = onClick),
selected = selected, verticalAlignment = Alignment.CenterVertically
onClick = onClick ) {
) Button(
Text(text = text) onClick = onClick,
colors = ButtonDefaults.buttonColors(
backgroundColor = if (selected)
MaterialTheme.colors.primary
else
MaterialTheme.colors.background,
contentColor = if (selected)
MaterialTheme.colors.onPrimary
else
MaterialTheme.colors.primary
),
elevation = null
) {
Text(text = text)
}
} }
} }