Refactor: Clean up unused code and fix warnings
This commit addresses several linter warnings and removes unused code to improve maintainability. - Removed unused function and property in . - Removed unused parameter from , , and . - Fixed a variable shadowing issue with in . - Inlined a redundant variable in .
This commit is contained in:
@@ -125,11 +125,7 @@ class BiometricAuthenticator(private val context: Context) {
|
||||
|
||||
private lateinit var promptInfo: BiometricPrompt.PromptInfo
|
||||
|
||||
private val biometricManager = BiometricManager.from(context)
|
||||
|
||||
fun isBiometricAuthAvailable(): Boolean {
|
||||
return biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG or BiometricManager.Authenticators.DEVICE_CREDENTIAL) == BiometricManager.BIOMETRIC_SUCCESS
|
||||
}
|
||||
|
||||
fun promptBiometricAuth(
|
||||
title: String,
|
||||
|
||||
@@ -204,47 +204,7 @@ fun AppShell(
|
||||
setShowPasswordDialog(true)
|
||||
}
|
||||
|
||||
val onRemoveEncryption: () -> Unit = {
|
||||
val activity = context.findActivity() as FragmentActivity
|
||||
val cipher = keyManager.getDecryptionCipher()
|
||||
if (cipher == null) {
|
||||
// This can happen if no key is set. In this case, just disable the feature.
|
||||
setHasEncryptionPassword(false)
|
||||
setIsEncryptionEnabled(false)
|
||||
sharedPrefs.edit {
|
||||
putBoolean("encryption_enabled", false)
|
||||
remove("biometric_unlock_enabled")
|
||||
}
|
||||
}
|
||||
val crypto = androidx.biometric.BiometricPrompt.CryptoObject(cipher!!)
|
||||
|
||||
biometricAuthenticator.promptBiometricAuth(
|
||||
title = context.getString(R.string.remove_encryption),
|
||||
subtitle = context.getString(R.string.confirm_to_remove_encryption),
|
||||
fragmentActivity = activity,
|
||||
crypto = crypto,
|
||||
onSuccess = { result ->
|
||||
result.cryptoObject?.cipher?.let { authenticatedCipher ->
|
||||
scope.launch {
|
||||
keyManager.getSecretKeyFromAuthenticatedCipher(authenticatedCipher)
|
||||
// Decrypt all items in all ViewModels
|
||||
// Decryption of individual items is no longer needed.
|
||||
|
||||
// Now it's safe to delete the key
|
||||
keyManager.deleteKey()
|
||||
setHasEncryptionPassword(false)
|
||||
setIsEncryptionEnabled(false)
|
||||
sharedPrefs.edit {
|
||||
putBoolean("encryption_enabled", false)
|
||||
remove("biometric_unlock_enabled")
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onFailed = {},
|
||||
onError = { _, _ -> }
|
||||
)
|
||||
}
|
||||
|
||||
val performAutomaticExport: suspend (Context, SecretKey?) -> Unit =
|
||||
remember(notesViewModel, shoppingListsViewModel, recipesViewModel, syncFolderUri) {
|
||||
@@ -1096,7 +1056,7 @@ fun AppShell(
|
||||
isEncryptionEnabled = isEncryptionEnabled,
|
||||
onEncryptionToggle = onEncryptionToggle,
|
||||
onSetEncryptionPassword = onSetEncryptionPassword,
|
||||
onRemoveEncryption = onRemoveEncryption,
|
||||
|
||||
hasEncryptionPassword = hasEncryptionPassword,
|
||||
biometricAuthenticator = biometricAuthenticator,
|
||||
sharedPrefs = sharedPrefs,
|
||||
|
||||
@@ -34,7 +34,6 @@ import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import de.lxtools.noteshop.R
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.biometric.BiometricManager
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import de.lxtools.noteshop.ui.theme.*
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
@@ -64,7 +63,7 @@ fun SettingsScreen(
|
||||
isEncryptionEnabled: Boolean,
|
||||
onEncryptionToggle: (Boolean) -> Unit,
|
||||
onSetEncryptionPassword: () -> Unit,
|
||||
onRemoveEncryption: () -> Unit,
|
||||
|
||||
hasEncryptionPassword: Boolean,
|
||||
biometricAuthenticator: BiometricAuthenticator,
|
||||
sharedPrefs: SharedPreferences,
|
||||
@@ -85,10 +84,7 @@ fun SettingsScreen(
|
||||
val currentStartScreenName = startScreenOptions[currentStartScreen] ?: stringResource(R.string.start_screen_last)
|
||||
var isBiometricUnlockEnabled by remember { mutableStateOf(sharedPrefs.getBoolean("biometric_unlock_enabled", false)) }
|
||||
val context = LocalContext.current
|
||||
val biometricManager = BiometricManager.from(context)
|
||||
val canUseBiometrics = remember {
|
||||
biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG) == BiometricManager.BIOMETRIC_SUCCESS
|
||||
}
|
||||
|
||||
val listState = rememberLazyListState()
|
||||
|
||||
val authenticateAndProceed: ((() -> Unit) -> Unit) = { successAction ->
|
||||
@@ -289,9 +285,8 @@ fun SettingsScreen(
|
||||
Switch(
|
||||
checked = isBiometricUnlockEnabled,
|
||||
onCheckedChange = {
|
||||
val newValue = it
|
||||
sharedPrefs.edit { putBoolean("biometric_unlock_enabled", newValue) }
|
||||
isBiometricUnlockEnabled = newValue
|
||||
sharedPrefs.edit { putBoolean ("biometric_unlock_enabled", it) }
|
||||
isBiometricUnlockEnabled = it
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ fun AppContent(
|
||||
isEncryptionEnabled: Boolean,
|
||||
onEncryptionToggle: (Boolean) -> Unit,
|
||||
onSetEncryptionPassword: () -> Unit,
|
||||
onRemoveEncryption: () -> Unit,
|
||||
|
||||
hasEncryptionPassword: Boolean,
|
||||
biometricAuthenticator: BiometricAuthenticator,
|
||||
sharedPrefs: android.content.SharedPreferences,
|
||||
@@ -186,7 +186,7 @@ fun AppContent(
|
||||
isEncryptionEnabled = isEncryptionEnabled,
|
||||
onEncryptionToggle = onEncryptionToggle,
|
||||
onSetEncryptionPassword = onSetEncryptionPassword,
|
||||
onRemoveEncryption = onRemoveEncryption,
|
||||
|
||||
hasEncryptionPassword = hasEncryptionPassword,
|
||||
biometricAuthenticator = biometricAuthenticator,
|
||||
sharedPrefs = sharedPrefs,
|
||||
|
||||
Reference in New Issue
Block a user