strings madness

This commit is contained in:
Mylloon 2024-01-04 18:27:12 +01:00
parent e7c511f5e4
commit 4329f3f91d
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
5 changed files with 88 additions and 48 deletions

View file

@ -135,13 +135,13 @@ private fun ActionRow(context: Context, model: HomeViewModel, navController: Nav
Button( Button(
enabled = selection != null, enabled = selection != null,
onClick = { navController.navigate("$MODIFY_SET/${selection?.idSet}") }) { onClick = { navController.navigate("$MODIFY_SET/${selection?.idSet}") }) {
Text(text = context.getString(R.string.main_button_modify)) Text(text = context.getString(R.string.modify))
} }
Spacer(modifier = Modifier.padding(2.dp)) Spacer(modifier = Modifier.padding(2.dp))
Button(onClick = { model.doAction(ActionHome.IMPORTATION) }) { Button(onClick = { model.doAction(ActionHome.IMPORTATION) }) {
Text(text = context.getString(R.string.main_button_import)) Text(text = context.getString(R.string.importation))
} }
} }
} }
@ -151,16 +151,24 @@ private fun ActionRow(context: Context, model: HomeViewModel, navController: Nav
fun CreationDialog( fun CreationDialog(
dismiss: () -> Unit, model: HomeViewModel = viewModel() dismiss: () -> Unit, model: HomeViewModel = viewModel()
) { ) {
val context = LocalContext.current
val sujet by model.sujet val sujet by model.sujet
AlertDialog(onDismissRequest = dismiss, title = { Text(text = "Créer un sujet") }, text = { AlertDialog(
onDismissRequest = dismiss,
title = { Text(text = context.getString(R.string.create_subject)) },
text = {
OutlinedTextField( OutlinedTextField(
sujet, label = { Text("Nouveau sujet") }, onValueChange = model::onSujetChange sujet,
label = { Text(context.getString(R.string.new_subject)) },
onValueChange = model::onSujetChange
) )
}, confirmButton = { },
Button(onClick = model::addSet, content = { Text("Ajouter") }) confirmButton = {
}, dismissButton = { Button(onClick = model::addSet, content = { Text(context.getString(R.string.add)) })
Button(onClick = dismiss, content = { Text("Annuler") }) },
dismissButton = {
Button(onClick = dismiss, content = { Text(context.getString(R.string.cancel)) })
}) })
} }
@ -171,6 +179,7 @@ fun ImportDialog(
) { ) {
val (selectedOption, onOptionSelected) = remember { mutableStateOf(ActionImport.FILE) } val (selectedOption, onOptionSelected) = remember { mutableStateOf(ActionImport.FILE) }
val context = LocalContext.current
var lien by remember { mutableStateOf("") } var lien by remember { mutableStateOf("") }
val ctx = LocalContext.current val ctx = LocalContext.current
@ -184,7 +193,7 @@ fun ImportDialog(
} }
AlertDialog(onDismissRequest = dismiss, AlertDialog(onDismissRequest = dismiss,
title = { Text(text = "Importer un jeu de question") }, title = { Text(text = context.getString(R.string.import_set_qestions)) },
text = { text = {
Column { Column {
Column(Modifier.selectableGroup()) { Column(Modifier.selectableGroup()) {
@ -218,7 +227,7 @@ fun ImportDialog(
) )
}) { }) {
Text( Text(
text = "Explorateur", text = context.getString(R.string.explorer),
style = MaterialTheme.typography.labelSmall style = MaterialTheme.typography.labelSmall
) )
} }
@ -230,30 +239,30 @@ fun ImportDialog(
OutlinedTextField(enabled = selectedOption == ActionImport.INTERNET, OutlinedTextField(enabled = selectedOption == ActionImport.INTERNET,
value = lien, value = lien,
onValueChange = { newTextValue -> lien = newTextValue }, onValueChange = { newTextValue -> lien = newTextValue },
label = { Text(text = "Lien") }) label = { Text(text = context.getString(R.string.link)) })
} }
}, },
confirmButton = { confirmButton = {
Button(onClick = { GlobalScope.launch { model.import(ctx, lien) } }, Button(onClick = { GlobalScope.launch { model.import(ctx, lien) } },
content = { Text("Importer") }) content = { Text(context.getString(R.string.importation)) })
}, },
dismissButton = { dismissButton = {
Button(onClick = dismiss, content = { Text("Annuler") }) Button(onClick = dismiss, content = { Text(context.getString(R.string.cancel)) })
}) })
} }
@Composable @Composable
fun ErrorDialog(errMsg: String, dismiss: () -> Unit) = AlertDialog(onDismissRequest = dismiss, fun ErrorDialog(errMsg: String, dismiss: () -> Unit) = AlertDialog(onDismissRequest = dismiss,
title = { Text(text = "Erreur") }, title = { Text(text = LocalContext.current.getString(R.string.error)) },
text = { Text(text = errMsg) }, text = { Text(text = errMsg) },
confirmButton = { Button(onClick = dismiss) { Text(text = "Ok") } }) confirmButton = { Button(onClick = dismiss) { Text(text = LocalContext.current.getString(R.string.ok)) } })
@Composable @Composable
fun DeletionDialog(dismiss: () -> Unit, confirm: () -> Unit) = fun DeletionDialog(dismiss: () -> Unit, confirm: () -> Unit) =
AlertDialog(onDismissRequest = dismiss, AlertDialog(onDismissRequest = dismiss,
title = { Text(text = "Supprimer un jeu de question") }, title = { Text(text = LocalContext.current.getString(R.string.delete_set_questions)) },
text = { Text(text = "Voulez-vous supprimer ce jeu de question ?") }, text = { Text(text = LocalContext.current.getString(R.string.delete_set_qestions_desc)) },
confirmButton = { Button(onClick = confirm) { Text(text = "Ok") } }) confirmButton = { Button(onClick = confirm) { Text(text = LocalContext.current.getString(R.string.ok)) } })
@Composable @Composable
fun ShowList( fun ShowList(

View file

@ -72,13 +72,13 @@ fun ModifySetScreen(
Button( Button(
enabled = currentSelection != null, enabled = currentSelection != null,
onClick = { action = ActionModifySet.MODIFICATION }) { onClick = { action = ActionModifySet.MODIFICATION }) {
Text(text = context.getString(R.string.modify_button_modify)) Text(text = context.getString(R.string.modify))
} }
Spacer(modifier = Modifier.padding(2.dp)) Spacer(modifier = Modifier.padding(2.dp))
Button(onClick = { action = ActionModifySet.AJOUT }) { Button(onClick = { action = ActionModifySet.AJOUT }) {
Text(text = context.getString(R.string.modify_button_add)) Text(text = context.getString(R.string.add))
} }
Spacer(modifier = Modifier.padding(2.dp)) Spacer(modifier = Modifier.padding(2.dp))
@ -149,6 +149,8 @@ fun AjoutModifDialog(
confirm: (String, String) -> Unit, confirm: (String, String) -> Unit,
dismiss: () -> Unit dismiss: () -> Unit
) { ) {
val context = LocalContext.current
var enonce by remember { var enonce by remember {
mutableStateOf( mutableStateOf(
if (type == ActionModifySet.MODIFICATION) { if (type == ActionModifySet.MODIFICATION) {
@ -172,9 +174,9 @@ fun AjoutModifDialog(
title = { title = {
Text( Text(
text = if (selection != null) { text = if (selection != null) {
"Mettre à jour la question" context.getString(R.string.update_question)
} else { } else {
"Ajouter une question" context.getString(R.string.add_question)
} }
) )
}, },
@ -184,14 +186,14 @@ fun AjoutModifDialog(
OutlinedTextField( OutlinedTextField(
value = enonce, value = enonce,
onValueChange = { enonce = it }, onValueChange = { enonce = it },
label = { Text(text = "Question") }) label = { Text(text = context.getString(R.string.question)) })
} }
Row { Row {
OutlinedTextField( OutlinedTextField(
value = reponse, value = reponse,
onValueChange = { reponse = it }, onValueChange = { reponse = it },
label = { Text(text = "Réponse") }) label = { Text(text = context.getString(R.string.reponse)) })
} }
} }
}, },
@ -199,18 +201,18 @@ fun AjoutModifDialog(
Button(onClick = { Button(onClick = {
confirm(enonce, reponse) confirm(enonce, reponse)
dismiss() dismiss()
}) { Text(text = "Ok") } }) { Text(text = context.getString(R.string.ok)) }
}) })
} }
@Composable @Composable
fun RemoveDialog(confirm: () -> Unit, dismiss: () -> Unit) = fun RemoveDialog(confirm: () -> Unit, dismiss: () -> Unit) =
AlertDialog(onDismissRequest = dismiss, AlertDialog(onDismissRequest = dismiss,
title = { Text(text = "Supprimer la question") }, title = { Text(text = LocalContext.current.getString(R.string.delete_question)) },
text = { Text(text = "Voulez-vous supprimer la question ?") }, text = { Text(text = LocalContext.current.getString(R.string.delete_question_desc)) },
confirmButton = { confirmButton = {
Button(onClick = { Button(onClick = {
confirm() confirm()
dismiss() dismiss()
}) { Text(text = "Ok") } }) { Text(text = LocalContext.current.getString(R.string.ok)) }
}) })

View file

@ -20,6 +20,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
@ -40,6 +41,8 @@ fun PlayScreen(
// First update the list of questions // First update the list of questions
model.updateQuestionList(idSet) model.updateQuestionList(idSet)
val context = LocalContext.current
val question by model.currentQuestion val question by model.currentQuestion
val reponse by model.proposedAnswer val reponse by model.proposedAnswer
val correction by model.evaluatedAnswer val correction by model.evaluatedAnswer
@ -51,8 +54,8 @@ fun PlayScreen(
model.sbUpdate() model.sbUpdate()
snackbarHostState.showSnackbar( snackbarHostState.showSnackbar(
when (correction!!) { when (correction!!) {
AnswerType.GOOD -> "Bonnne réponse !" AnswerType.GOOD -> context.getString(R.string.good_answer)
AnswerType.BAD -> "Mauvaise réponse !" AnswerType.BAD -> context.getString(R.string.bad_answer)
}, duration = SnackbarDuration.Short }, duration = SnackbarDuration.Short
) )
model.resetAfterSb() model.resetAfterSb()
@ -74,7 +77,7 @@ fun PlayScreen(
) { ) {
if (question == null) { if (question == null) {
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) { Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
Text("Ce set n'a aucune question", fontSize = 30.sp) Text(context.getString(R.string.no_question), fontSize = 30.sp)
} }
} else { } else {
Text(text = question!!.enonce, fontSize = 30.sp, textAlign = TextAlign.Center) Text(text = question!!.enonce, fontSize = 30.sp, textAlign = TextAlign.Center)
@ -83,7 +86,7 @@ fun PlayScreen(
OutlinedTextField( OutlinedTextField(
value = reponse, value = reponse,
label = { Text(text = "Réponse") }, label = { Text(text = context.getString(R.string.reponse)) },
onValueChange = model::updateAnswer onValueChange = model::updateAnswer
) )
@ -97,13 +100,13 @@ fun PlayScreen(
enabled = reponse.isNotBlank() && correction == null, enabled = reponse.isNotBlank() && correction == null,
onClick = model::checkAnswer onClick = model::checkAnswer
) { ) {
Text(text = "Répondre") Text(text = context.getString(R.string.to_answer))
} }
Button( Button(
enabled = model.isDelayElapsed(), enabled = model.isDelayElapsed(),
onClick = { giveup = true }) { onClick = { giveup = true }) {
Text(text = "Voir réponse") Text(text = context.getString(R.string.see_answer))
} }
} }
} }
@ -112,7 +115,7 @@ fun PlayScreen(
Button( Button(
onClick = { navController.navigate("$MODIFY_SET/$idSet") }) { onClick = { navController.navigate("$MODIFY_SET/$idSet") }) {
Text(text = "Modifier le set") Text(text = context.getString(R.string.modify_set))
} }
} }
} }
@ -120,8 +123,8 @@ fun PlayScreen(
@Composable @Composable
fun SolutionDialog(reponse: String, next: () -> Unit) = fun SolutionDialog(reponse: String, next: () -> Unit) =
AlertDialog(onDismissRequest = next, AlertDialog(onDismissRequest = next,
title = { Text(text = "Solution") }, title = { Text(text = LocalContext.current.getString(R.string.solution)) },
text = { Text(text = reponse) }, text = { Text(text = reponse) },
confirmButton = { confirmButton = {
Button(onClick = next) { Text(text = "Ok") } Button(onClick = next) { Text(text = LocalContext.current.getString(R.string.ok)) }
}) })

View file

@ -49,9 +49,9 @@ fun SettingsScreen(padding: PaddingValues, model: SettingsViewModel = viewModel(
@Composable @Composable
fun DeletionDBDialog(confirm: () -> Unit, dismiss: () -> Unit) = fun DeletionDBDialog(confirm: () -> Unit, dismiss: () -> Unit) =
AlertDialog(onDismissRequest = dismiss, AlertDialog(onDismissRequest = dismiss,
title = { Text(text = "Supprimer la base de données") }, title = { Text(text = LocalContext.current.getString(R.string.delete_db)) },
text = { Text(text = "Voulez-vous supprimer la base de données ?") }, text = { Text(text = LocalContext.current.getString(R.string.delete_db_desc)) },
confirmButton = { confirmButton = {
Button(onClick = confirm) { Text(text = "Oui") } Button(onClick = confirm) { Text(text = LocalContext.current.getString(R.string.yes)) }
}, },
dismissButton = { Button(onClick = dismiss) { Text(text = "Non") } }) dismissButton = { Button(onClick = dismiss) { Text(text = LocalContext.current.getString(R.string.no)) } })

View file

@ -3,14 +3,40 @@
<string name="home_button">Page principale</string> <string name="home_button">Page principale</string>
<string name="settings_button">Paramètres</string> <string name="settings_button">Paramètres</string>
<string name="main_button_create">Créer</string> <string name="main_button_create">Créer</string>
<string name="main_button_modify">Modifier</string>
<string name="main_button_import">Importer</string>
<string name="main_button_deletebase">Supprimer base</string> <string name="main_button_deletebase">Supprimer base</string>
<string name="main_button_delete">Supprimer sélection</string> <string name="main_button_delete">Supprimer sélection</string>
<string name="main_button_start">Lancer</string> <string name="main_button_start">Lancer</string>
<string name="error_bad_entry">Erreur : entrée invalide</string> <string name="error_bad_entry">Erreur : entrée invalide</string>
<string name="error_duplicate">Erreur : doublon</string> <string name="error_duplicate">Erreur : doublon</string>
<string name="modify_button_add">Ajouter</string> <string name="modify">Modifier</string>
<string name="modify_button_modify">Modifier</string>
<string name="modify_button_delete">Supprimer</string> <string name="modify_button_delete">Supprimer</string>
<string name="create_subject">Créer un sujet</string>
<string name="new_subject">Nouveau sujet</string>
<string name="add">Ajouter</string>
<string name="cancel">Annuler</string>
<string name="import_set_qestions">Importer un jeu de question</string>
<string name="explorer">Explorateur</string>
<string name="link">Lien</string>
<string name="importation">Importer</string>
<string name="error">Erreur</string>
<string name="delete_set_questions">Supprimer un jeu de question</string>
<string name="delete_set_qestions_desc">Voulez-vous supprimer ce jeu de question ?</string>
<string name="ok">Ok</string>
<string name="update_question">Mettre à jour la question</string>
<string name="add_question">Ajouter une question</string>
<string name="question">Question</string>
<string name="reponse">Réponse</string>
<string name="delete_question">Supprimer la question</string>
<string name="delete_question_desc">Voulez-vous supprimer la question ?</string>
<string name="good_answer">Bonnne réponse !</string>
<string name="bad_answer">Mauvaise réponse !</string>
<string name="no_question">Ce set n\'a aucune question</string>
<string name="to_answer">Répondre</string>
<string name="see_answer">Voir réponse</string>
<string name="modify_set">Modifier le set</string>
<string name="solution">Solution</string>
<string name="delete_db">Supprimer la base de données</string>
<string name="delete_db_desc">Voulez-vous supprimer la base de données ?</string>
<string name="yes">Oui</string>
<string name="no">Non</string>
</resources> </resources>