From b347bf01f1ef2694db6da6db7460da153f81be02 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 4 Jan 2024 18:46:22 +0100 Subject: [PATCH] add congrats dialog --- .../memorisationapplication/PlayScreen.kt | 15 +++++++++++++++ .../memorisationapplication/ui/PlayViewModel.kt | 6 ++++-- app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/PlayScreen.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/PlayScreen.kt index a132187..6c0589f 100644 --- a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/PlayScreen.kt +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/PlayScreen.kt @@ -47,6 +47,7 @@ fun PlayScreen( val reponse by model.proposedAnswer val correction by model.evaluatedAnswer var giveup by model.showAnswer + val gameEnded by model.end val cpt by model.compteurSb if (correction != null) { @@ -62,6 +63,10 @@ fun PlayScreen( } } + if (gameEnded) { + EndDialog { navController.navigate(HOME) } + } + if (giveup && question != null) { SolutionDialog(question!!.reponse, model::newQuestion) } @@ -128,3 +133,13 @@ fun SolutionDialog(reponse: String, next: () -> Unit) = confirmButton = { Button(onClick = next) { Text(text = LocalContext.current.getString(R.string.ok)) } }) + +@Composable +fun EndDialog(next: () -> Unit) = + AlertDialog( + onDismissRequest = next, + title = { Text(text = LocalContext.current.getString(R.string.bravo)) }, + text = { Text(text = LocalContext.current.getString(R.string.set_ended)) }, + confirmButton = { + Button(onClick = next) { Text(text = LocalContext.current.getString(R.string.ok)) } + }) diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ui/PlayViewModel.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ui/PlayViewModel.kt index 3b88306..92c8857 100644 --- a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ui/PlayViewModel.kt +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ui/PlayViewModel.kt @@ -21,6 +21,7 @@ class PlayViewModel(application: Application) : AndroidViewModel(application) { private var timestampQuestion = mutableStateOf(System.currentTimeMillis()) private var currentTime = mutableStateOf(System.currentTimeMillis()) var showAnswer = mutableStateOf(false) + val end = mutableStateOf(false) fun updateQuestionList(setId: Int) { if (currentQuestion.value == null) { @@ -39,9 +40,10 @@ class PlayViewModel(application: Application) : AndroidViewModel(application) { } else { if (index.value >= questions.value.size) { /* Fin des questions */ - index.value = 0 + end.value = true + } else { + currentQuestion.value = questions.value[index.value] } - currentQuestion.value = questions.value[index.value] } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2b089e1..609afb9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -39,4 +39,6 @@ Voulez-vous supprimer la base de données ? Oui Non + Bravo + Le set de questions est terminé !