Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Some fixes in navigation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
M3DZIK committed Jun 8, 2024
1 parent 9d0da94 commit 82a2c8a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ class MainActivity : FragmentActivity() {

val expired = vault.handleExpiration(this)
if (expired) {
navController.navigate(
Unlock
) {
popUpToDestination(navController)
navController.navigate(Unlock) {
popUpToDestination(Unlock)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import dev.medzik.android.utils.runOnUiThread
import dev.medzik.android.utils.showToast
import dev.medzik.librepass.android.R
import dev.medzik.librepass.android.common.haveNetworkConnection
import dev.medzik.librepass.android.common.popUpToDestination
import dev.medzik.librepass.android.common.popUpToStartDestination
import dev.medzik.librepass.android.database.Credentials
import dev.medzik.librepass.android.ui.LibrePassViewModel
import dev.medzik.librepass.android.ui.components.auth.ChoiceServer
Expand Down Expand Up @@ -105,10 +105,8 @@ fun LoginScreen(
)

runOnUiThread {
navController.navigate(
Vault
) {
popUpToDestination(navController)
navController.navigate(Vault) {
popUpToStartDestination(navController)
}
}
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import dev.medzik.android.utils.runOnUiThread
import dev.medzik.android.utils.showToast
import dev.medzik.librepass.android.R
import dev.medzik.librepass.android.common.haveNetworkConnection
import dev.medzik.librepass.android.common.popUpToDestination
import dev.medzik.librepass.android.common.popUpToStartDestination
import dev.medzik.librepass.android.ui.components.auth.ChoiceServer
import dev.medzik.librepass.android.utils.showErrorToast
import dev.medzik.librepass.client.Server
Expand Down Expand Up @@ -75,10 +75,8 @@ fun RegisterScreen(navController: NavController) {
runOnUiThread {
context.showToast(R.string.Toast_PleaseVerifyYourEmail)

navController.navigate(
Login
) {
popUpToDestination(navController)
navController.navigate(Login) {
popUpToStartDestination(navController)
}
}
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ fun UnlockScreen(
// run only if loading is true (if no error occurred)
if (loading) {
runOnUiThread {
navController.navigate(
Vault
) {
popUpToDestination(navController)
navController.navigate(Vault) {
popUpToDestination(Vault)
}
}
}
Expand All @@ -129,10 +127,8 @@ fun UnlockScreen(
onAuthenticationSucceeded = { cipher ->
viewModel.vault.aesKey = KeyStore.decrypt(cipher, credentials.biometricAesKey!!)

navController.navigate(
Vault
) {
popUpToDestination(navController)
navController.navigate(Vault) {
popUpToDestination(Vault)
}
},
onAuthenticationFailed = { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package dev.medzik.librepass.android.ui.screens.settings.account

import androidx.navigation.NavController
import dev.medzik.android.utils.runOnUiThread
import dev.medzik.librepass.android.common.popUpToDestination
import dev.medzik.librepass.android.ui.LibrePassViewModel
import dev.medzik.librepass.android.ui.screens.Welcome
import dev.medzik.librepass.android.common.popUpToDestination
import kotlinx.coroutines.runBlocking
import java.util.*
import java.util.UUID

fun navigateToWelcomeAndLogout(
viewModel: LibrePassViewModel,
Expand All @@ -19,10 +19,8 @@ fun navigateToWelcomeAndLogout(
}

runOnUiThread {
navController.navigate(
Welcome
) {
popUpToDestination(navController)
navController.navigate(Welcome) {
popUpToDestination(Welcome)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavOptionsBuilder

fun NavOptionsBuilder.popUpToDestination(navController: NavController) {
fun NavOptionsBuilder.popUpToStartDestination(navController: NavController) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = false
inclusive = true
}
}

inline fun <reified T : Any> NavOptionsBuilder.popUpToDestination(destination: T) {
popUpTo(destination) {
saveState = false
inclusive = true
}
}

0 comments on commit 82a2c8a

Please sign in to comment.