Add exit button (#43)
This commit is contained in:
parent
78d9e65329
commit
62701dd630
@ -19,7 +19,9 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
AppTheme {
|
AppTheme {
|
||||||
MainScreen()
|
MainScreen() {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.width
|
|||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ExitToApp
|
||||||
import androidx.compose.material.icons.filled.Done
|
import androidx.compose.material.icons.filled.Done
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
@ -118,7 +119,7 @@ data class HeadwindStats(
|
|||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun MainScreen() {
|
fun MainScreen(onFinish: () -> Unit) {
|
||||||
var karooConnected by remember { mutableStateOf(false) }
|
var karooConnected by remember { mutableStateOf(false) }
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
@ -134,6 +135,7 @@ fun MainScreen() {
|
|||||||
val location by karooSystem.getGpsCoordinateFlow(ctx).collectAsStateWithLifecycle(null)
|
val location by karooSystem.getGpsCoordinateFlow(ctx).collectAsStateWithLifecycle(null)
|
||||||
|
|
||||||
var savedDialogVisible by remember { mutableStateOf(false) }
|
var savedDialogVisible by remember { mutableStateOf(false) }
|
||||||
|
var exitDialogVisible by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
ctx.streamSettings(karooSystem).collect { settings ->
|
ctx.streamSettings(karooSystem).collect { settings ->
|
||||||
@ -238,6 +240,28 @@ fun MainScreen() {
|
|||||||
} else {
|
} else {
|
||||||
Text(modifier = Modifier.padding(5.dp), text = "No weather data received yet, waiting for GPS fix...")
|
Text(modifier = Modifier.padding(5.dp), text = "No weather data received yet, waiting for GPS fix...")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilledTonalButton(modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(50.dp), onClick = {
|
||||||
|
exitDialogVisible = true
|
||||||
|
}) {
|
||||||
|
Icon(Icons.AutoMirrored.Default.ExitToApp, contentDescription = "Exit")
|
||||||
|
Spacer(modifier = Modifier.width(5.dp))
|
||||||
|
Text("Exit")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exitDialogVisible) {
|
||||||
|
AlertDialog(onDismissRequest = { exitDialogVisible = false },
|
||||||
|
confirmButton = { Button(onClick = {
|
||||||
|
onFinish()
|
||||||
|
}) { Text("Yes") } },
|
||||||
|
dismissButton = { Button(onClick = {
|
||||||
|
exitDialogVisible = false
|
||||||
|
}) { Text("No") } },
|
||||||
|
text = { Text("Do you really want to exit?") }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user