feat: Add reset functionality and localize Toast messages in WebAppIntegration

- Implemented a "Reset" button with a confirmation dialog in WebAppIntegrationScreen.
- Added resetWebAppIntegration() to WebAppIntegrationViewModel to clear stored credentials.
- Localized all Toast messages in WebAppIntegrationViewModel by using string resources.
- Added corresponding string resources and German translations.
This commit is contained in:
2025-10-30 14:37:38 +01:00
parent 2f36954c2a
commit 2cd2e616d4
4 changed files with 69 additions and 2 deletions

View File

@@ -7,6 +7,10 @@ import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
@@ -63,5 +67,40 @@ fun WebAppIntegrationScreen(
) {
Text(stringResource(R.string.save_and_test_connection_button))
}
Spacer(modifier = Modifier.height(8.dp)) // Add some space between buttons
var showResetConfirmationDialog by remember { mutableStateOf(false) }
Button(
onClick = { showResetConfirmationDialog = true },
modifier = Modifier.fillMaxWidth(),
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.error)
) {
Text(stringResource(R.string.reset_web_app_integration))
}
if (showResetConfirmationDialog) {
AlertDialog(
onDismissRequest = { showResetConfirmationDialog = false },
title = { Text(stringResource(R.string.reset_web_app_integration)) },
text = { Text(stringResource(R.string.reset_web_app_integration_confirmation)) },
confirmButton = {
Button(
onClick = {
viewModel.resetWebAppIntegration()
showResetConfirmationDialog = false
}
) {
Text(stringResource(R.string.delete)) // Using existing "Delete" string for confirmation
}
},
dismissButton = {
TextButton(onClick = { showResetConfirmationDialog = false }) {
Text(stringResource(R.string.cancel))
}
}
)
}
}
}

View File

@@ -68,7 +68,7 @@ class WebAppIntegrationViewModel(private val repository: NoteshopRepository, app
password = String(decrypted)
}
} catch (e: Exception) {
Toast.makeText(getApplication(), "Failed to decrypt credentials", Toast.LENGTH_SHORT).show()
Toast.makeText(getApplication(), getApplication<Application>().getString(de.lxtools.noteshop.R.string.failed_to_decrypt_credentials), Toast.LENGTH_SHORT).show()
}
}
}
@@ -77,7 +77,7 @@ class WebAppIntegrationViewModel(private val repository: NoteshopRepository, app
fun saveAndTestConnection() {
viewModelScope.launch {
if (deletePassword.isBlank()) {
Toast.makeText(getApplication(), "Deletion password cannot be empty", Toast.LENGTH_SHORT).show()
Toast.makeText(getApplication(), getApplication<Application>().getString(de.lxtools.noteshop.R.string.deletion_password_cannot_be_empty), Toast.LENGTH_SHORT).show()
return@launch
}
@@ -101,4 +101,22 @@ class WebAppIntegrationViewModel(private val repository: NoteshopRepository, app
}
}
}
fun resetWebAppIntegration() {
viewModelScope.launch {
webAppUrl = ""
username = ""
password = ""
deletePassword = ""
sharedPrefs.edit().apply {
remove("webapp_url")
remove("username_encrypted")
remove("password_encrypted")
remove("key_pass")
apply()
}
Toast.makeText(getApplication(), getApplication<Application>().getString(de.lxtools.noteshop.R.string.web_app_integration_reset_successful), Toast.LENGTH_SHORT).show()
}
}
}

View File

@@ -297,4 +297,9 @@
<string name="import_from_web_app">Von Web-App importieren</string>
<string name="connection_successful">Verbindung erfolgreich und Zugangsdaten gespeichert</string>
<string name="import_successful">Artikel erfolgreich importiert</string>
<string name="reset_web_app_integration">Web-App-Integration zurücksetzen</string>
<string name="reset_web_app_integration_confirmation">Möchten Sie die Web-App-Integration wirklich zurücksetzen? Dadurch werden alle gespeicherten Anmeldeinformationen gelöscht.</string>
<string name="web_app_integration_reset_successful">Web-App-Integration erfolgreich zurückgesetzt</string>
<string name="failed_to_decrypt_credentials">Fehler beim Entschlüsseln der Zugangsdaten</string>
<string name="deletion_password_cannot_be_empty">Löschpasswort darf nicht leer sein</string>
</resources>

View File

@@ -297,4 +297,9 @@
<string name="import_from_web_app">Import from Web App</string>
<string name="connection_successful">Connection successful and credentials saved</string>
<string name="import_successful">Items imported successfully</string>
<string name="reset_web_app_integration">Reset Web App Integration</string>
<string name="reset_web_app_integration_confirmation">Are you sure you want to reset the Web App Integration? This will delete all stored credentials.</string>
<string name="web_app_integration_reset_successful">Web App Integration reset successfully</string>
<string name="failed_to_decrypt_credentials">Failed to decrypt credentials</string>
<string name="deletion_password_cannot_be_empty">Deletion password cannot be empty</string>
</resources>