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é !