refactor: Remove unused parameters and code in UI components - Cleaned up AppShell.kt, AppTopBar.kt, AppContent.kt, ShoppingListDetailScreen.kt, WebAppIntegrationScreen.kt, NoteDetailScreen.kt, ShoppingListsViewModel.kt, NotesViewModel.kt, RecipesViewModel.kt, and EncryptionPasswordDialog.kt by removing unused parameters, imports, and functions, and updating Base64 usage and shared preferences editing.
This commit is contained in:
@@ -942,10 +942,6 @@ fun AppShell(
|
||||
exportLauncher = exportLauncher,
|
||||
noteExportLauncher = noteExportLauncher,
|
||||
recipeExportLauncher = recipeExportLauncher,
|
||||
hasEncryptionPassword = hasEncryptionPassword,
|
||||
onShowSetPasswordDialog = { setShowSetPasswordDialog(true) },
|
||||
onShowSetRecipePasswordDialog = { setShowSetRecipePasswordDialog(true) },
|
||||
onShowSetListPasswordDialog = { setShowSetListPasswordDialog(true) },
|
||||
onShowChooseLockMethodDialog = { type, id ->
|
||||
setItemToLockType(type)
|
||||
setItemToLockId(id)
|
||||
|
||||
@@ -30,6 +30,7 @@ import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.edit
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import de.lxtools.noteshop.BiometricAuthenticator
|
||||
import de.lxtools.noteshop.R
|
||||
@@ -104,7 +105,7 @@ fun EncryptionPasswordDialog(
|
||||
val encryptedDerivedKey = authorizedCipher.doFinal(pbeKey.encoded)
|
||||
val iv = authorizedCipher.iv
|
||||
keyManager.storeEncryptedDerivedKey(encryptedDerivedKey, iv, useBiometrics)
|
||||
sharedPrefs.edit().putBoolean("biometric_unlock_enabled", useBiometrics).apply()
|
||||
sharedPrefs.edit { putBoolean("biometric_unlock_enabled", useBiometrics) }
|
||||
onPasswordSet()
|
||||
Toast.makeText(context, R.string.encryption_password_set_success, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
@@ -117,7 +117,6 @@ fun AppContent(
|
||||
listId = selectedListId,
|
||||
viewModel = shoppingListsViewModel,
|
||||
dynamicStrings = dynamicStrings,
|
||||
wasInitiallyLocked = itemWasInitiallyLocked,
|
||||
isContentDecrypted = itemWasInitiallyLocked,
|
||||
onUnlockClick = {
|
||||
val list = shoppingListsViewModel.uiState.value.shoppingLists.find { it.shoppingList.id == selectedListId }?.shoppingList
|
||||
@@ -201,7 +200,6 @@ fun AppContent(
|
||||
is Screen.WebAppIntegration -> {
|
||||
WebAppIntegrationScreen(
|
||||
viewModel = webAppIntegrationViewModel,
|
||||
onNavigateUp = { onScreenChange(Screen.Settings) },
|
||||
padding = innerPadding,
|
||||
onAuthenticateAndTogglePasswordVisibility = onAuthenticateAndTogglePasswordVisibility
|
||||
)
|
||||
|
||||
@@ -68,10 +68,6 @@ fun AppTopBar(
|
||||
exportLauncher: ActivityResultLauncher<String>,
|
||||
noteExportLauncher: ActivityResultLauncher<String>,
|
||||
recipeExportLauncher: ActivityResultLauncher<String>,
|
||||
hasEncryptionPassword: Boolean,
|
||||
onShowSetPasswordDialog: () -> Unit,
|
||||
onShowSetRecipePasswordDialog: () -> Unit,
|
||||
onShowSetListPasswordDialog: () -> Unit,
|
||||
onShowChooseLockMethodDialog: (LockableItemType, Int) -> Unit
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
@@ -30,13 +30,7 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import de.lxtools.noteshop.security.FileEncryptor
|
||||
import javax.crypto.SecretKey
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import de.lxtools.noteshop.findActivity
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
||||
@@ -82,7 +82,7 @@ class NotesViewModel(private val noteshopRepository: NoteshopRepository) : ViewM
|
||||
|
||||
suspend fun saveNote() {
|
||||
if (noteDetails.value.isValid()) {
|
||||
var currentNote = noteDetails.value.toNote()
|
||||
val currentNote = noteDetails.value.toNote()
|
||||
|
||||
// Encryption on save is now handled by the new protection flow.
|
||||
|
||||
@@ -140,35 +140,6 @@ class NotesViewModel(private val noteshopRepository: NoteshopRepository) : ViewM
|
||||
}
|
||||
}
|
||||
|
||||
fun setProtectionPattern(pattern: String) {
|
||||
Log.d("NotesViewModel", "setProtectionPattern called with pattern: $pattern")
|
||||
}
|
||||
|
||||
fun setProtectionPin(pin: String) {
|
||||
viewModelScope.launch {
|
||||
val currentNoteDetails = _noteDetails.value
|
||||
if (pin.isNotBlank()) {
|
||||
val hash = PasswordHasher.hashPassword(pin)
|
||||
val updatedNote = currentNoteDetails.toNote().copy(
|
||||
protectionHash = hash,
|
||||
protectionType = 3, // 3 for PIN protection
|
||||
lockMethod = 3
|
||||
)
|
||||
noteshopRepository.updateNote(updatedNote)
|
||||
updateNoteDetails(updatedNote) // Update the UI state
|
||||
} else {
|
||||
// PIN is blank, so we remove protection
|
||||
val updatedNote = currentNoteDetails.toNote().copy(
|
||||
protectionHash = "",
|
||||
protectionType = 0,
|
||||
lockMethod = 0
|
||||
)
|
||||
noteshopRepository.updateNote(updatedNote)
|
||||
updateNoteDetails(updatedNote) // Update the UI state
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun resetNoteDetails() {
|
||||
_noteDetails.value = NoteDetails()
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ class RecipesViewModel(private val noteshopRepository: NoteshopRepository) : Vie
|
||||
|
||||
suspend fun saveRecipe() {
|
||||
if (recipeDetails.value.isValid()) {
|
||||
var currentRecipe = recipeDetails.value.toRecipe()
|
||||
val currentRecipe = recipeDetails.value.toRecipe()
|
||||
|
||||
// Encryption on save is now handled by the new protection flow.
|
||||
|
||||
@@ -138,35 +138,6 @@ class RecipesViewModel(private val noteshopRepository: NoteshopRepository) : Vie
|
||||
}
|
||||
}
|
||||
|
||||
fun setProtectionPattern(pattern: String) {
|
||||
Log.d("RecipesViewModel", "setProtectionPattern called with pattern: $pattern")
|
||||
}
|
||||
|
||||
fun setProtectionPin(pin: String) {
|
||||
viewModelScope.launch {
|
||||
val currentRecipeDetails = _recipeDetails.value
|
||||
if (pin.isNotBlank()) {
|
||||
val hash = PasswordHasher.hashPassword(pin)
|
||||
val updatedRecipe = currentRecipeDetails.toRecipe().copy(
|
||||
protectionHash = hash,
|
||||
protectionType = 3, // 3 for PIN protection
|
||||
lockMethod = 3
|
||||
)
|
||||
noteshopRepository.updateRecipe(updatedRecipe)
|
||||
updateRecipeDetails(updatedRecipe) // Update the UI state
|
||||
} else {
|
||||
// PIN is blank, so we remove protection
|
||||
val updatedRecipe = currentRecipeDetails.toRecipe().copy(
|
||||
protectionHash = "",
|
||||
protectionType = 0,
|
||||
lockMethod = 0
|
||||
)
|
||||
noteshopRepository.updateRecipe(updatedRecipe)
|
||||
updateRecipeDetails(updatedRecipe) // Update the UI state
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun resetRecipeDetails() {
|
||||
_recipeDetails.value = RecipeDetails()
|
||||
}
|
||||
|
||||
@@ -49,19 +49,14 @@ import androidx.compose.ui.text.style.TextDecoration
|
||||
import androidx.compose.ui.unit.dp
|
||||
import de.lxtools.noteshop.R
|
||||
import de.lxtools.noteshop.data.ShoppingListItem
|
||||
import de.lxtools.noteshop.security.FileEncryptor
|
||||
import javax.crypto.SecretKey
|
||||
|
||||
import kotlinx.coroutines.launch
|
||||
import sh.calvin.reorderable.ReorderableItem
|
||||
import sh.calvin.reorderable.rememberReorderableLazyListState
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import de.lxtools.noteshop.findActivity
|
||||
import androidx.compose.ui.text.withStyle
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -70,18 +65,14 @@ fun ShoppingListDetailScreen(
|
||||
viewModel: ShoppingListsViewModel,
|
||||
dynamicStrings: de.lxtools.noteshop.DynamicListStrings,
|
||||
modifier: Modifier = Modifier,
|
||||
wasInitiallyLocked: Boolean,
|
||||
isContentDecrypted: Boolean,
|
||||
onUnlockClick: (Int) -> Unit,
|
||||
onNavigateBack: () -> Unit
|
||||
) {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
|
||||
BackHandler(enabled = true) {
|
||||
keyboardController?.hide()
|
||||
onNavigateBack()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Collect state from ViewModel
|
||||
val newItemName by viewModel.newItemName.collectAsState()
|
||||
@@ -100,7 +91,7 @@ fun ShoppingListDetailScreen(
|
||||
onDispose {
|
||||
val activity = context.findActivity()
|
||||
if (!activity.isChangingConfigurations) {
|
||||
// TODO: Handle lock state correctly
|
||||
onNavigateBack()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,8 @@ import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.json.Json
|
||||
import de.lxtools.noteshop.security.FileEncryptor
|
||||
import java.util.Base64
|
||||
import javax.crypto.SecretKey
|
||||
import de.lxtools.noteshop.security.PasswordHasher
|
||||
import android.util.Base64
|
||||
|
||||
class ShoppingListsViewModel(private val noteshopRepository: NoteshopRepository, application: Application) : AndroidViewModel(application) {
|
||||
|
||||
@@ -193,35 +192,6 @@ class ShoppingListsViewModel(private val noteshopRepository: NoteshopRepository,
|
||||
}
|
||||
}
|
||||
|
||||
fun setProtectionPattern(pattern: String) {
|
||||
Log.d("ShoppingListsViewModel", "setProtectionPattern called with pattern: $pattern")
|
||||
}
|
||||
|
||||
fun setProtectionPin(pin: String) {
|
||||
viewModelScope.launch {
|
||||
val currentListDetails = _listDetails.value
|
||||
if (pin.isNotBlank()) {
|
||||
val hash = PasswordHasher.hashPassword(pin)
|
||||
val updatedList = currentListDetails.toShoppingList().copy(
|
||||
protectionHash = hash,
|
||||
protectionType = 3, // 3 for PIN protection
|
||||
lockMethod = 3
|
||||
)
|
||||
noteshopRepository.updateShoppingList(updatedList)
|
||||
updateListDetails(updatedList) // Update the UI state
|
||||
} else {
|
||||
// PIN is blank, so we remove protection
|
||||
val updatedList = currentListDetails.toShoppingList().copy(
|
||||
protectionHash = "",
|
||||
protectionType = 0,
|
||||
lockMethod = 0
|
||||
)
|
||||
noteshopRepository.updateShoppingList(updatedList)
|
||||
updateListDetails(updatedList) // Update the UI state
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deleteList(list: ShoppingList) {
|
||||
noteshopRepository.deleteShoppingList(list)
|
||||
}
|
||||
@@ -474,10 +444,10 @@ class ShoppingListsViewModel(private val noteshopRepository: NoteshopRepository,
|
||||
return@launch
|
||||
}
|
||||
|
||||
val decryptedUsernameBytes = fileEncryptor.decrypt(java.util.Base64.getDecoder().decode(usernameEncrypted), secretKey)
|
||||
val decryptedUsernameBytes = fileEncryptor.decrypt(Base64.decode(usernameEncrypted, Base64.DEFAULT), secretKey)
|
||||
username = String(decryptedUsernameBytes, Charsets.UTF_8)
|
||||
|
||||
val decryptedPasswordBytes = fileEncryptor.decrypt(java.util.Base64.getDecoder().decode(passwordEncrypted), secretKey)
|
||||
val decryptedPasswordBytes = fileEncryptor.decrypt(Base64.decode(passwordEncrypted, Base64.DEFAULT), secretKey)
|
||||
password = String(decryptedPasswordBytes, Charsets.UTF_8)
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(getApplication(), getApplication<Application>().getString(de.lxtools.noteshop.R.string.failed_to_decrypt_credentials_generic, e.message), Toast.LENGTH_LONG).show()
|
||||
|
||||
@@ -3,7 +3,7 @@ package de.lxtools.noteshop.ui.webapp
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
|
||||
import androidx.compose.material.icons.filled.Visibility
|
||||
import androidx.compose.material.icons.filled.VisibilityOff
|
||||
import androidx.compose.foundation.layout.*
|
||||
@@ -25,7 +25,7 @@ import de.lxtools.noteshop.R
|
||||
@Composable
|
||||
fun WebAppIntegrationScreen(
|
||||
viewModel: WebAppIntegrationViewModel,
|
||||
onNavigateUp: () -> Unit,
|
||||
|
||||
padding: PaddingValues,
|
||||
onAuthenticateAndTogglePasswordVisibility: (Boolean) -> Unit // New parameter
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user