|
|
|
@ -2,19 +2,13 @@ package fr.iut.sciencequest.viewModels
|
|
|
|
|
|
|
|
|
|
import android.os.Handler
|
|
|
|
|
import android.os.Looper
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import androidx.lifecycle.ViewModel
|
|
|
|
|
import androidx.lifecycle.ViewModelProvider
|
|
|
|
|
import androidx.lifecycle.viewModelScope
|
|
|
|
|
import fr.iut.sciencequest.model.dto.extensions.ToModel
|
|
|
|
|
import fr.iut.sciencequest.model.repositories.question.IQuestionRepository
|
|
|
|
|
import fr.iut.sciencequest.model.repositories.question.QuestionAPIRepository
|
|
|
|
|
import fr.iut.sciencequest.model.repositories.question.QuestionStubRepository
|
|
|
|
|
import fr.iut.sciencequest.stub.StubQuestionWithReponses
|
|
|
|
|
import fr.iut.sciencequest.stub.StubQuestionWithReponses2
|
|
|
|
|
import fr.iut.sciencequest.viewModels.uixStates.KahootUIState
|
|
|
|
|
import kotlinx.coroutines.flow.MutableStateFlow
|
|
|
|
|
import kotlinx.coroutines.flow.StateFlow
|
|
|
|
|
import kotlinx.coroutines.flow.asStateFlow
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
|
|
|
@ -32,7 +26,7 @@ class KahootViewModel(
|
|
|
|
|
|
|
|
|
|
_uiState.value = KahootUIState(
|
|
|
|
|
questionRepo.questions.value.get(0),
|
|
|
|
|
duréePartie = uiState.value.duréePartie,
|
|
|
|
|
dureePartie = uiState.value.dureePartie,
|
|
|
|
|
nbPoints = uiState.value.nbPoints,
|
|
|
|
|
reponseChoisie = false
|
|
|
|
|
)
|
|
|
|
@ -41,12 +35,12 @@ class KahootViewModel(
|
|
|
|
|
{
|
|
|
|
|
_uiState.value = KahootUIState(
|
|
|
|
|
questionRepo.questions.value.get(index),
|
|
|
|
|
duréePartie = uiState.value.duréePartie,
|
|
|
|
|
dureePartie = uiState.value.dureePartie,
|
|
|
|
|
nbPoints = uiState.value.nbPoints,
|
|
|
|
|
reponseChoisie = false
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
uiState.value.duréePartie * index
|
|
|
|
|
uiState.value.dureePartie * index
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -54,12 +48,17 @@ class KahootViewModel(
|
|
|
|
|
|
|
|
|
|
// NOTE : tpsReponse en ms
|
|
|
|
|
fun ajouterPoints(tpsReponse: Long) {
|
|
|
|
|
if (tpsReponse < 0) {
|
|
|
|
|
throw IllegalArgumentException("ERREUR: Temps négatif donné à l'ajout de points")
|
|
|
|
|
} else if (tpsReponse > uiState.value.dureePartie) {
|
|
|
|
|
throw IllegalArgumentException("ERREUR: Utilsateur à répondu trop lentement")
|
|
|
|
|
}
|
|
|
|
|
if (uiState.value.reponseChoisie) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
val nbPoints: Int = (10_000 - tpsReponse).toInt()
|
|
|
|
|
val nbPoints: Int = (uiState.value.dureePartie - tpsReponse).toInt()
|
|
|
|
|
_uiState.value = KahootUIState(uiState.value.question,
|
|
|
|
|
duréePartie = uiState.value.duréePartie,
|
|
|
|
|
dureePartie = uiState.value.dureePartie,
|
|
|
|
|
nbPoints = uiState.value.nbPoints + nbPoints,
|
|
|
|
|
reponseChoisie = true)
|
|
|
|
|
}
|
|
|
|
|