fix(#7): localize import snackbar strings and drop class.simpleName fallback
The three snackbar strings in ImportBankStatementScreenModel were hardcoded English while the rest of the app uses stringResource. Move them to res/values/strings.xml. Also drop the error::class.simpleName fallback in the failure branch — it surfaced Kotlin class names like NotImplementedError to end users. Now falls back to the localized 'Import failed' string.
This commit is contained in:
+7
-5
@@ -1,9 +1,11 @@
|
||||
package dev.achmad.ledgerr.ui.screens.import_bank_statement
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import cafe.adriel.voyager.core.model.ScreenModel
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import cafe.adriel.voyager.navigator.Navigator
|
||||
import dev.achmad.ledgerr.R
|
||||
import dev.achmad.ledgerr.di.util.inject
|
||||
import dev.achmad.ledgerr.domain.bankstatement.interactor.BankStatementImporter
|
||||
import dev.achmad.ledgerr.domain.bankstatement.model.PendingImportExpense
|
||||
@@ -38,6 +40,7 @@ class ImportBankStatementScreenModel(
|
||||
private val importers: List<BankStatementImporter> = inject(),
|
||||
private val getCategories: GetCategories = inject(),
|
||||
private val insertExpenses: InsertExpenses = inject(),
|
||||
private val context: Context = inject(),
|
||||
) : ScreenModel {
|
||||
|
||||
private val _state = MutableStateFlow<ImportState>(ImportState.BankPicker(importers))
|
||||
@@ -66,16 +69,15 @@ class ImportBankStatementScreenModel(
|
||||
.onSuccess { rows ->
|
||||
if (rows.isEmpty()) {
|
||||
_state.value = ImportState.BankPicker(importers)
|
||||
_snackbar.tryEmit("No transactions found in PDF")
|
||||
_snackbar.tryEmit(context.getString(R.string.import_no_transactions))
|
||||
} else {
|
||||
_state.value = ImportState.Confirmation(importer.bankName, rows)
|
||||
}
|
||||
}
|
||||
.onFailure { error ->
|
||||
_state.value = ImportState.BankPicker(importers)
|
||||
val message = error.message
|
||||
?: error::class.simpleName
|
||||
?: "Import failed"
|
||||
val message = error.message?.takeIf { it.isNotBlank() }
|
||||
?: context.getString(R.string.import_failed)
|
||||
_snackbar.tryEmit(message)
|
||||
}
|
||||
}
|
||||
@@ -113,7 +115,7 @@ class ImportBankStatementScreenModel(
|
||||
val confirmation = _state.value as? ImportState.Confirmation ?: return@launch
|
||||
val selected = confirmation.rows.filter { it.isSelected }
|
||||
if (selected.isEmpty()) {
|
||||
_snackbar.tryEmit("No items selected")
|
||||
_snackbar.tryEmit(context.getString(R.string.import_no_items_selected))
|
||||
return@launch
|
||||
}
|
||||
withContext(Dispatchers.IO) {
|
||||
|
||||
@@ -39,6 +39,9 @@
|
||||
<string name="import_amount">Amount</string>
|
||||
<string name="import_date">Date (yyyy-MM-dd)</string>
|
||||
<string name="import_description">Description</string>
|
||||
<string name="import_no_transactions">No transactions found in PDF</string>
|
||||
<string name="import_failed">Import failed</string>
|
||||
<string name="import_no_items_selected">No items selected</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings_title">Settings</string>
|
||||
|
||||
Reference in New Issue
Block a user