Skip to content

Commit 8096bc1

Browse files
committed
corrected some "stringResource + values" in some text + added the strings for errors during backup/import
1 parent 391863e commit 8096bc1

6 files changed

Lines changed: 34 additions & 17 deletions

File tree

app/src/main/java/com/mouton/openwinemer/domain/usecase/BackupUseCase.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import java.io.OutputStreamWriter
1616
import java.text.SimpleDateFormat
1717
import java.util.Date
1818
import java.util.Locale
19+
import androidx.compose.ui.res.stringResource
20+
import com.mouton.openwinemer.R
1921

2022
/**
2123
* Cette classe gère :
@@ -54,12 +56,12 @@ class BackupUseCase(
5456

5557
// On accède au dossier choisi par l'utilisateur.
5658
val root = DocumentFile.fromTreeUri(context, treeUri)
57-
?: throw IllegalStateException("Impossible d'accéder au dossier sélectionné.")
59+
?: throw IllegalStateException(context.getString(R.string.cant_access_folder))
5860

5961
// On crée un fichier avec la date et l'heure dans le nom.
6062
val fileName = "openwinemer_backup_${currentTimestamp()}.json"
6163
val file = root.createFile("application/json", fileName)
62-
?: throw IllegalStateException("Impossible de créer le fichier dans ce dossier.")
64+
?: throw IllegalStateException(context.getString(R.string.cant_create_here))
6365

6466
// On écrit le contenu dans le fichier.
6567
context.contentResolver.openOutputStream(file.uri)?.use { out ->
@@ -72,7 +74,7 @@ class BackupUseCase(
7274
// ------------------------------------------------------------
7375
suspend fun importBackupFromUri(uri: Uri, password: String?) {
7476
val inputStream = context.contentResolver.openInputStream(uri)
75-
?: throw IllegalStateException("Impossible de lire le fichier sélectionné.")
77+
?: throw IllegalStateException(context.getString(R.string.cant_read_file))
7678

7779
val content = inputStream.readBytes().decodeToString()
7880

@@ -85,7 +87,7 @@ class BackupUseCase(
8587
try {
8688
BackupCrypto.decrypt(content, password)
8789
} catch (e: Exception) {
88-
throw IllegalStateException("Mot de passe incorrect ou fichier chiffré invalide")
90+
throw IllegalStateException(context.getString(R.string.wrong_pwd_or_file))
8991
}
9092
}
9193

@@ -97,7 +99,7 @@ class BackupUseCase(
9799
// Ici on tombe par exemple si :
98100
// - le fichier est chiffré mais password est vide
99101
// - le contenu n’est pas un JSON valide
100-
throw IllegalStateException("Fichier de sauvegarde invalide ou mot de passe incorrect")
102+
throw IllegalStateException(context.getString(R.string.invalid_save_file))
101103
}
102104

103105
// 3) Insérer en base
@@ -112,12 +114,12 @@ class BackupUseCase(
112114
val wines = wineDao.getAllWines().first()
113115

114116
val root = DocumentFile.fromTreeUri(context, treeUri)
115-
?: throw IllegalStateException("Impossible d'accéder au dossier sélectionné.")
117+
?: throw IllegalStateException(context.getString(R.string.cant_access_folder))
116118

117119
// Nom de fichier avec date et heure.
118120
val fileName = "openwinemer_export_${currentTimestamp()}.csv"
119121
val file = root.createFile("text/csv", fileName)
120-
?: throw IllegalStateException("Impossible de créer le fichier CSV.")
122+
?: throw IllegalStateException(context.getString(R.string.cant_make_csv))
121123

122124
context.contentResolver.openOutputStream(file.uri)?.use { out ->
123125
val writer = OutputStreamWriter(out)

app/src/main/java/com/mouton/openwinemer/ui/detail/WineDetailScreen.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fun WineDetailScreen(
4545
Scaffold(
4646
topBar = {
4747
TopAppBar(
48-
title = { Text("${wine?.name ?: stringResource(R.string.wine_details)}") },
48+
title = { Text((wine?.name ?: stringResource(R.string.wine_details))) },
4949
navigationIcon = {
5050
IconButton(onClick = onBack) { Text("<") }
5151
},
@@ -67,15 +67,18 @@ fun WineDetailScreen(
6767
.padding(16.dp)
6868
.fillMaxSize()
6969
) {
70-
Text(stringResource(R.string.name, " : ", current.name ?: "-"))
71-
Text(stringResource(R.string.wine_producer, " : ", current.producer ?: "-"))
72-
Text(stringResource(R.string.region_label, " : ", current.region ?: "-"))
73-
Text(stringResource(R.string.color_label, " : ", current.color ?: "-"))
74-
Text(stringResource(R.string.year_label, " : ", current.vintage ?: "-"))
70+
//"${wine?.name ?: stringResource(R.string.wine_details)}"
71+
Text(stringResource(R.string.name) + " : " + (current.name ?: "-"))
72+
Text(stringResource(R.string.wine_producer) + " : " + (current.producer ?: "-"))
73+
Text(stringResource(R.string.region_label) + " : " + (current.region ?: "-"))
74+
Text(stringResource(R.string.color_label) + " : " + (current.color ?: "-"))
75+
Text(stringResource(R.string.year_label) + " : " + (current.vintage ?: "-"))
76+
//(current.truc ?: "-") → si truc est null, on affiche -
7577

7678
Spacer(Modifier.height(16.dp))
7779

78-
Text(stringResource(R.string.wine_stock, " : ", current.stockQuantity ?: 0))
80+
Text(stringResource(R.string.wine_stock) + " : " + (current.stockQuantity ?: 0))
81+
// (current.stockQuantity ?: 0) → si stockQuantity est null, on affiche 0
7982
Row {
8083
Button(onClick = { viewModel.updateStock(-1) }) {
8184
Text("-")
@@ -88,7 +91,7 @@ fun WineDetailScreen(
8891

8992
Spacer(Modifier.height(24.dp))
9093

91-
Text(stringResource(R.string.wine_general_desc, " : ", current.generalDescription ?: "-"))
94+
Text(stringResource(R.string.wine_general_desc) + " : " + (current.generalDescription ?: "-"))
9295
}
9396
} ?: Box(
9497
modifier = Modifier

app/src/main/java/com/mouton/openwinemer/ui/list/FilterSortBar.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fun FilterSortBar(
3939
var expanded by remember { mutableStateOf(false) }
4040
Box {
4141
OutlinedButton(onClick = { expanded = true }) {
42-
Text(stringResource(R.string.sort_by_button, currentSort.field.name))
42+
Text(stringResource(R.string.sort_by_button) + (currentSort.field.name))
4343
}
4444
DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
4545
SortField.values().forEach { field ->

app/src/main/java/com/mouton/openwinemer/ui/settings/SettingsScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import androidx.compose.foundation.layout.*
1010
import androidx.compose.material3.*
1111
import androidx.compose.runtime.*
1212
import androidx.compose.ui.Modifier
13-
import androidx.compose.ui.res.stringResource
1413
import androidx.compose.ui.unit.dp
1514
import androidx.hilt.navigation.compose.hiltViewModel
1615
import kotlinx.coroutines.launch
16+
import androidx.compose.ui.res.stringResource
1717
import com.mouton.openwinemer.R
1818

1919
/**

app/src/main/res/values-en/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,10 @@
8484
<string name="delete_prompt">Delete this wine?</string>
8585
<string name="cannot_undo">This action cannot be undone!</string>
8686
<string name="cancel_button">Cancel</string>
87+
<string name="invalid_save_file">Invalid save file or incorrect password</string>
88+
<string name="cant_make_csv">Unable to create the CSV file.</string>
89+
<string name="cant_access_folder">Unable to access the selected folder.</string>
90+
<string name="wrong_pwd_or_file">Incorrect password or invalid encrypted file</string>
91+
<string name="cant_read_file">Unable to read the selected file.</string>
92+
<string name="cant_create_here">Unable to create the file in this folder.</string>
8793
</resources>

app/src/main/res/values/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,10 @@
8484
<string name="delete_prompt">Supprimer ce vin ?</string>
8585
<string name="cannot_undo">Cette action est irréversible !</string>
8686
<string name="cancel_button">Annuler</string>
87+
<string name="invalid_save_file">Fichier de sauvegarde invalide ou mot de passe incorrect</string>
88+
<string name="cant_make_csv">Impossible de créer le fichier CSV.</string>
89+
<string name="cant_access_folder">Impossible d'accéder au dossier sélectionné.</string>
90+
<string name="wrong_pwd_or_file">Mot de passe incorrect ou fichier chiffré invalide</string>
91+
<string name="cant_read_file">Impossible de lire le fichier sélectionné.</string>
92+
<string name="cant_create_here">Impossible de créer le fichier dans ce dossier.</string>
8793
</resources>

0 commit comments

Comments
 (0)