From a722a6bb4b0a97b70bbd4d6075ff5b43be6d5951 Mon Sep 17 00:00:00 2001 From: M3DZIK Date: Mon, 18 Mar 2024 22:08:40 +0100 Subject: [PATCH] Remember some values in cipher view/add/edit screens Not needed to re-setup with re-composable and fixes back animation --- .../medzik/librepass/android/ui/screens/vault/CipherAdd.kt | 7 ++++--- .../librepass/android/ui/screens/vault/CipherEdit.kt | 5 +++-- .../librepass/android/ui/screens/vault/CipherView.kt | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/CipherAdd.kt b/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/CipherAdd.kt index 44086c34..024ed637 100644 --- a/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/CipherAdd.kt +++ b/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/CipherAdd.kt @@ -9,6 +9,7 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier @@ -47,10 +48,10 @@ fun CipherAddScreen( ) { val context = LocalContext.current - val cipherTypeArg = navController.getString(Argument.CipherType) ?: return - val cipherType = CipherType.from(cipherTypeArg.toInt()) + val cipherTypeArg = remember { navController.getString(Argument.CipherType) } ?: return + val cipherType = remember { CipherType.from(cipherTypeArg.toInt()) } - val credentials = viewModel.credentialRepository.get() ?: return + val credentials = remember { viewModel.credentialRepository.get() } ?: return var cipher by rememberMutable( Cipher( diff --git a/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/CipherEdit.kt b/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/CipherEdit.kt index c87a2354..c003c056 100644 --- a/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/CipherEdit.kt +++ b/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/CipherEdit.kt @@ -9,6 +9,7 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier @@ -47,8 +48,8 @@ fun CipherEditScreen( ) { val context = LocalContext.current - val cipherId = navController.getString(Argument.CipherId) ?: return - val oldCipher = viewModel.vault.find(cipherId) ?: return + val cipherId = remember { navController.getString(Argument.CipherId) } ?: return + val oldCipher = remember { viewModel.vault.find(cipherId) } ?: return var cipher by rememberMutable(oldCipher) var loading by rememberMutableBoolean() diff --git a/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/CipherView.kt b/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/CipherView.kt index 5e002f99..d2e865aa 100644 --- a/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/CipherView.kt +++ b/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/CipherView.kt @@ -69,8 +69,8 @@ fun CipherViewScreen( navController: NavController, viewModel: LibrePassViewModel = hiltViewModel() ) { - val cipherId = navController.getString(Argument.CipherId) ?: return - val cipher = viewModel.vault.find(cipherId) ?: return + val cipherId = remember { navController.getString(Argument.CipherId) } ?: return + val cipher = remember { viewModel.vault.find(cipherId) } ?: return var totpCode by rememberMutable("") var totpElapsed by rememberMutable(0)