fix some crashes related to playground, add edit button in playground
This commit is contained in:
parent
547dd051be
commit
86b4339734
4 changed files with 64 additions and 32 deletions
|
@ -11,14 +11,14 @@
|
||||||
- [x] Créer des questions
|
- [x] Créer des questions
|
||||||
- [x] Supprimer des questions
|
- [x] Supprimer des questions
|
||||||
- [x] Choisir / Sélection
|
- [x] Choisir / Sélection
|
||||||
- [ ] Commencer un jeu
|
- [x] Commencer un jeu
|
||||||
- [ ] Reprendre la progression d'un jeu
|
- [ ] Reprendre la progression d'un jeu
|
||||||
- [ ] Afficher les statistiques de tous les jeux
|
- [ ] Afficher les statistiques de tous les jeux
|
||||||
- Dans un jeu
|
- Dans un jeu
|
||||||
- [ ] Consulter la réponse à une question trop difficile
|
- [x] Consulter la réponse à une question trop difficile
|
||||||
- [ ] Choisir le statut d'une question
|
- [ ] Choisir le statut d'une question
|
||||||
- [ ] Modifier la question
|
- [x] Modifier la question
|
||||||
- [ ] Supprimer la question
|
- [x] Supprimer la question
|
||||||
- [ ] Afficher les statistiques du jeu de question en cours
|
- [ ] Afficher les statistiques du jeu de question en cours
|
||||||
- [ ] Notification
|
- [ ] Notification
|
||||||
- une fois par jour
|
- une fois par jour
|
||||||
|
|
|
@ -84,6 +84,7 @@ fun MainScreen() {
|
||||||
it.arguments?.getString(PLAY_SET_ARG)?.let { idSet ->
|
it.arguments?.getString(PLAY_SET_ARG)?.let { idSet ->
|
||||||
PlayScreen(
|
PlayScreen(
|
||||||
padding,
|
padding,
|
||||||
|
navController,
|
||||||
snackbarHostState,
|
snackbarHostState,
|
||||||
idSet.toInt()
|
idSet.toInt()
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
|
@ -19,7 +20,11 @@ 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.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import androidx.navigation.NavController
|
||||||
import fr.uparis.diamantkennel.memorisationapplication.ui.AnswerType
|
import fr.uparis.diamantkennel.memorisationapplication.ui.AnswerType
|
||||||
import fr.uparis.diamantkennel.memorisationapplication.ui.PlayViewModel
|
import fr.uparis.diamantkennel.memorisationapplication.ui.PlayViewModel
|
||||||
|
|
||||||
|
@ -27,6 +32,7 @@ import fr.uparis.diamantkennel.memorisationapplication.ui.PlayViewModel
|
||||||
@Composable
|
@Composable
|
||||||
fun PlayScreen(
|
fun PlayScreen(
|
||||||
padding: PaddingValues,
|
padding: PaddingValues,
|
||||||
|
navController: NavController,
|
||||||
snackbarHostState: SnackbarHostState,
|
snackbarHostState: SnackbarHostState,
|
||||||
idSet: Int,
|
idSet: Int,
|
||||||
model: PlayViewModel = viewModel()
|
model: PlayViewModel = viewModel()
|
||||||
|
@ -35,9 +41,6 @@ fun PlayScreen(
|
||||||
model.updateQuestionList(idSet)
|
model.updateQuestionList(idSet)
|
||||||
|
|
||||||
val question by model.currentQuestion
|
val question by model.currentQuestion
|
||||||
if (question == null) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
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
|
||||||
|
@ -56,12 +59,12 @@ fun PlayScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (giveup) {
|
if (giveup && question != null) {
|
||||||
SolutionDialog(question!!.reponse, model::newQuestion)
|
SolutionDialog(question!!.reponse, model::newQuestion)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update timer if needed
|
// Update timer if needed
|
||||||
if (!model.isDelayElapsed()) {
|
if (!model.isDelayElapsed() && question != null) {
|
||||||
model.updateTime(System.currentTimeMillis())
|
model.updateTime(System.currentTimeMillis())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,14 +72,25 @@ fun PlayScreen(
|
||||||
modifier = Modifier.padding(padding),
|
modifier = Modifier.padding(padding),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
Text(text = question!!.enonce)
|
if (question == null) {
|
||||||
|
Text("Ce set n'a aucune question", fontSize = 30.sp, textAlign = TextAlign.Center)
|
||||||
|
} else {
|
||||||
|
Text(text = question!!.enonce, fontSize = 30.sp, textAlign = TextAlign.Center)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.padding(top = 20.dp))
|
||||||
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = reponse,
|
value = reponse,
|
||||||
label = { Text(text = "Réponse") },
|
label = { Text(text = "Réponse") },
|
||||||
onValueChange = model::updateAnswer
|
onValueChange = model::updateAnswer
|
||||||
)
|
)
|
||||||
|
|
||||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceEvenly) {
|
Spacer(modifier = Modifier.padding(top = 20.dp))
|
||||||
|
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceEvenly
|
||||||
|
) {
|
||||||
Button(
|
Button(
|
||||||
enabled = reponse.isNotBlank() && correction == null,
|
enabled = reponse.isNotBlank() && correction == null,
|
||||||
onClick = model::checkAnswer
|
onClick = model::checkAnswer
|
||||||
|
@ -91,6 +105,14 @@ fun PlayScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
|
||||||
|
Button(
|
||||||
|
onClick = { navController.navigate("$MODIFY_SET/$idSet") }) {
|
||||||
|
Text(text = "Modifier le set")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
|
@ -24,7 +24,7 @@ class PlayViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
|
|
||||||
fun updateQuestionList(setId: Int) {
|
fun updateQuestionList(setId: Int) {
|
||||||
if (currentQuestion.value == null) {
|
if (currentQuestion.value == null) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.Main) {
|
||||||
dao.loadQuestions(setId).collect { questionList ->
|
dao.loadQuestions(setId).collect { questionList ->
|
||||||
questions.value = questionList.shuffled()
|
questions.value = questionList.shuffled()
|
||||||
updateQuestion()
|
updateQuestion()
|
||||||
|
@ -34,12 +34,16 @@ class PlayViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateQuestion() {
|
private fun updateQuestion() {
|
||||||
|
if (questions.value.isEmpty()) {
|
||||||
|
currentQuestion.value = null
|
||||||
|
} else {
|
||||||
if (index.value >= questions.value.size) {
|
if (index.value >= questions.value.size) {
|
||||||
/* Fin des questions */
|
/* Fin des questions */
|
||||||
index.value = 0
|
index.value = 0
|
||||||
}
|
}
|
||||||
currentQuestion.value = questions.value[index.value]
|
currentQuestion.value = questions.value[index.value]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun reset() {
|
private fun reset() {
|
||||||
proposedAnswer.value = ""
|
proposedAnswer.value = ""
|
||||||
|
@ -84,8 +88,13 @@ class PlayViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
|
|
||||||
fun sbUpdate() {
|
fun sbUpdate() {
|
||||||
when (evaluatedAnswer.value!!) {
|
when (evaluatedAnswer.value!!) {
|
||||||
AnswerType.GOOD -> newQuestion()
|
AnswerType.GOOD -> {
|
||||||
AnswerType.BAD -> reset()
|
newQuestion()
|
||||||
|
}
|
||||||
|
|
||||||
|
AnswerType.BAD -> {
|
||||||
|
reset()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue