[FIX] Context recup dans composant

RepositoryAndroid
Renaud BEURET 1 year ago
parent b306915e68
commit 50d4a03973

@ -14,22 +14,30 @@ class KahootViewModel: ViewModel() {
private val handler = Handler(Looper.getMainLooper()) private val handler = Handler(Looper.getMainLooper())
fun lancerPartie() { fun lancerPartie() {
var nbPoints: Int
var tpsReponse = 10_000
handler.postDelayed( handler.postDelayed(
{ {
Log.d("KahootViewModel","J'actualise les questions") Log.d("KahootViewModel","J'actualise les questions")
nbPoints = if(uiState.value.reponseChoisie) { uiState.value = KahootUIState(StubQuestionWithReponses2,
duréePartie = uiState.value.duréePartie,
nbPoints = uiState.value.nbPoints,
reponseChoisie = false)
},
uiState.value.duréePartie * 1000
)
}
// NOTE : tpsReponse en ms
fun ajouterPoints(tpsReponse: Int) {
val nbPoints = if(uiState.value.reponseChoisie) {
10_000 - tpsReponse 10_000 - tpsReponse
} else { } else {
0 0
} }
uiState.value = KahootUIState(StubQuestionWithReponses2, uiState.value = KahootUIState(uiState.value.question,
duréePartie = uiState.value.duréePartie, duréePartie = uiState.value.duréePartie,
nbPoints = uiState.value.nbPoints + nbPoints, nbPoints = uiState.value.nbPoints + nbPoints,
reponseChoisie = false) reponseChoisie = false)
}, Log.d("KahootViewModel","Le joueur à ${uiState.value.reponseChoisie}")
uiState.value.duréePartie * 1000
)
} }
} }

@ -19,7 +19,7 @@ import fr.iut.sciencequest.view.scientifiques.scientifiqueListeScreen
@Composable @Composable
fun NavHost(context: Context) { fun NavHost() {
val navController = rememberNavController() val navController = rememberNavController()
NavHost( NavHost(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
@ -72,8 +72,7 @@ fun NavHost(context: Context) {
}, },
goToHome = { goToHome = {
navController.navigate("home") navController.navigate("home")
}, }
context = context
) )
} }

Loading…
Cancel
Save