From 32fe6c1e279de8ef980beb7a20c1e4170530c73f Mon Sep 17 00:00:00 2001 From: Steffen Heger Date: Fri, 1 Nov 2024 12:43:16 +0100 Subject: [PATCH] prevent back navigation from login screen --- driver-app/app/src/main/java/de/motis/prima/Home.kt | 3 --- driver-app/app/src/main/java/de/motis/prima/Login.kt | 8 ++++++++ driver-app/app/src/main/java/de/motis/prima/Tours.kt | 3 --- driver-app/app/src/main/java/de/motis/prima/Vehicles.kt | 3 --- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/driver-app/app/src/main/java/de/motis/prima/Home.kt b/driver-app/app/src/main/java/de/motis/prima/Home.kt index adb79b4..bed66d2 100644 --- a/driver-app/app/src/main/java/de/motis/prima/Home.kt +++ b/driver-app/app/src/main/java/de/motis/prima/Home.kt @@ -60,9 +60,6 @@ fun Home( viewModel.logoutEvent.collect { Log.d("Logout", "Logout event triggered.") navController.navigate("login") { - popUpTo(navController.graph.startDestinationId) { - inclusive = true - } launchSingleTop = true } } diff --git a/driver-app/app/src/main/java/de/motis/prima/Login.kt b/driver-app/app/src/main/java/de/motis/prima/Login.kt index c58ecd6..315ca3d 100644 --- a/driver-app/app/src/main/java/de/motis/prima/Login.kt +++ b/driver-app/app/src/main/java/de/motis/prima/Login.kt @@ -1,6 +1,8 @@ package de.motis.prima +import android.app.Activity import android.util.Log +import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column @@ -25,6 +27,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.KeyboardType @@ -81,6 +84,11 @@ fun Login( val networkErrorMessage = stringResource(id = R.string.network_error_message) + val activity = (LocalContext.current as? Activity) + BackHandler { + activity?.finish() + } + LaunchedEffect(key1 = viewModel) { // Catching successful login event and navigation to the next screen launch { diff --git a/driver-app/app/src/main/java/de/motis/prima/Tours.kt b/driver-app/app/src/main/java/de/motis/prima/Tours.kt index 120eb00..dfc9353 100644 --- a/driver-app/app/src/main/java/de/motis/prima/Tours.kt +++ b/driver-app/app/src/main/java/de/motis/prima/Tours.kt @@ -60,9 +60,6 @@ fun Tours( viewModel.logoutEvent.collect { Log.d("Logout", "Logout event triggered.") navController.navigate("login") { - popUpTo(navController.graph.startDestinationId) { - inclusive = true - } launchSingleTop = true } } diff --git a/driver-app/app/src/main/java/de/motis/prima/Vehicles.kt b/driver-app/app/src/main/java/de/motis/prima/Vehicles.kt index 90d6ee6..67b939b 100644 --- a/driver-app/app/src/main/java/de/motis/prima/Vehicles.kt +++ b/driver-app/app/src/main/java/de/motis/prima/Vehicles.kt @@ -60,9 +60,6 @@ fun Vehicles( viewModel.logoutEvent.collect { Log.d("Logout", "Logout event triggered.") navController.navigate("login") { - popUpTo(navController.graph.startDestinationId) { - inclusive = true - } launchSingleTop = true } }