add congrats dialog
This commit is contained in:
parent
4329f3f91d
commit
b347bf01f1
3 changed files with 21 additions and 2 deletions
|
@ -47,6 +47,7 @@ fun PlayScreen(
|
||||||
val reponse by model.proposedAnswer
|
val reponse by model.proposedAnswer
|
||||||
val correction by model.evaluatedAnswer
|
val correction by model.evaluatedAnswer
|
||||||
var giveup by model.showAnswer
|
var giveup by model.showAnswer
|
||||||
|
val gameEnded by model.end
|
||||||
|
|
||||||
val cpt by model.compteurSb
|
val cpt by model.compteurSb
|
||||||
if (correction != null) {
|
if (correction != null) {
|
||||||
|
@ -62,6 +63,10 @@ fun PlayScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gameEnded) {
|
||||||
|
EndDialog { navController.navigate(HOME) }
|
||||||
|
}
|
||||||
|
|
||||||
if (giveup && question != null) {
|
if (giveup && question != null) {
|
||||||
SolutionDialog(question!!.reponse, model::newQuestion)
|
SolutionDialog(question!!.reponse, model::newQuestion)
|
||||||
}
|
}
|
||||||
|
@ -128,3 +133,13 @@ fun SolutionDialog(reponse: String, next: () -> Unit) =
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
Button(onClick = next) { Text(text = LocalContext.current.getString(R.string.ok)) }
|
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)) }
|
||||||
|
})
|
||||||
|
|
|
@ -21,6 +21,7 @@ class PlayViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
private var timestampQuestion = mutableStateOf(System.currentTimeMillis())
|
private var timestampQuestion = mutableStateOf(System.currentTimeMillis())
|
||||||
private var currentTime = mutableStateOf(System.currentTimeMillis())
|
private var currentTime = mutableStateOf(System.currentTimeMillis())
|
||||||
var showAnswer = mutableStateOf(false)
|
var showAnswer = mutableStateOf(false)
|
||||||
|
val end = mutableStateOf(false)
|
||||||
|
|
||||||
fun updateQuestionList(setId: Int) {
|
fun updateQuestionList(setId: Int) {
|
||||||
if (currentQuestion.value == null) {
|
if (currentQuestion.value == null) {
|
||||||
|
@ -39,11 +40,12 @@ class PlayViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
} else {
|
} else {
|
||||||
if (index.value >= questions.value.size) {
|
if (index.value >= questions.value.size) {
|
||||||
/* Fin des questions */
|
/* Fin des questions */
|
||||||
index.value = 0
|
end.value = true
|
||||||
}
|
} else {
|
||||||
currentQuestion.value = questions.value[index.value]
|
currentQuestion.value = questions.value[index.value]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun reset() {
|
private fun reset() {
|
||||||
proposedAnswer.value = ""
|
proposedAnswer.value = ""
|
||||||
|
|
|
@ -39,4 +39,6 @@
|
||||||
<string name="delete_db_desc">Voulez-vous 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="yes">Oui</string>
|
||||||
<string name="no">Non</string>
|
<string name="no">Non</string>
|
||||||
|
<string name="bravo">Bravo</string>
|
||||||
|
<string name="set_ended">Le set de questions est terminé !</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Reference in a new issue