RepositoryAndroid^2
Lilian BRETON 1 year ago
parent 3288aa1ee1
commit fe4e875c93

@ -21,7 +21,7 @@ import fr.iut.sciencequest.view.scientifiques.scientifiqueListeScreen
@Composable @Composable
fun NavHost(kahotVM: KahootViewModel = viewModel()) { fun NavHost(kahootVM: KahootViewModel = viewModel()) {
val navController = rememberNavController() val navController = rememberNavController()
NavHost( NavHost(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
@ -40,7 +40,7 @@ fun NavHost(kahotVM: KahootViewModel = viewModel()) {
navController.navigate("pendu") navController.navigate("pendu")
}, },
goToKahoot = { goToKahoot = {
kahotVM.lancerPartie() kahootVM.lancerPartie()
navController.navigate("kahoot") navController.navigate("kahoot")
} }
) )
@ -80,17 +80,20 @@ fun NavHost(kahotVM: KahootViewModel = viewModel()) {
} }
composable(route= "kahoot"){ composable(route= "kahoot"){
KahootScreen( goToAccount = { KahootScreen(
goToAccount = {
navController.navigate("account") navController.navigate("account")
}, },
goToHome = { goToHome = {
navController.navigate("home") navController.navigate("home")
}, },
viewModel = kahotVM) viewModel = kahootVM
)
} }
composable(route = "listeScientifiques") { composable(route = "listeScientifiques") {
scientifiqueListeScreen(goToAccount = { scientifiqueListeScreen(
goToAccount = {
navController.navigate("account") navController.navigate("account")
}, },
goToHome = { goToHome = {

@ -4,6 +4,7 @@ import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement 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.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
@ -18,6 +19,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp 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 fr.iut.sciencequest.R import fr.iut.sciencequest.R
import fr.iut.sciencequest.ViewModels.KahootViewModel import fr.iut.sciencequest.ViewModels.KahootViewModel
@ -25,7 +27,6 @@ import fr.iut.sciencequest.model.dto.question.QuestionWithSimpleResponseDTO
import fr.iut.sciencequest.model.dto.reponse.ReponseSimpleDTO import fr.iut.sciencequest.model.dto.reponse.ReponseSimpleDTO
import fr.iut.sciencequest.stub.StubQuestionWithReponses import fr.iut.sciencequest.stub.StubQuestionWithReponses
import fr.iut.sciencequest.view.TopBar import fr.iut.sciencequest.view.TopBar
import java.util.Timer
@Composable @Composable
fun KahootScreen(viewModel: KahootViewModel = viewModel(), fun KahootScreen(viewModel: KahootViewModel = viewModel(),
@ -34,6 +35,7 @@ fun KahootScreen(viewModel: KahootViewModel = viewModel(),
val state = viewModel.uiState.collectAsState() val state = viewModel.uiState.collectAsState()
Column(modifier = Modifier.fillMaxWidth()) { Column(modifier = Modifier.fillMaxWidth()) {
TopBar(goToAccount, goToHome, stringResource(id = R.string.kahoot)) TopBar(goToAccount, goToHome, stringResource(id = R.string.kahoot))
KahootPlayer(state.value.question) { KahootPlayer(state.value.question) {
viewModel.ajouterPoints(it) viewModel.ajouterPoints(it)
} }
@ -57,13 +59,17 @@ fun KahootPlayerPreview(){
@Composable @Composable
fun KahootPlayer(question: QuestionWithSimpleResponseDTO, fun KahootPlayer(question: QuestionWithSimpleResponseDTO,
sendReponse: (Long) -> Unit){ sendResponse: (Long) -> Unit){
val context = LocalContext.current; val context = LocalContext.current;
val currTime = System.currentTimeMillis() val currTime = System.currentTimeMillis()
Column (horizontalAlignment = Alignment.CenterHorizontally){ Column (
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.SpaceEvenly,
modifier = Modifier.fillMaxHeight()
) {
KahootQuestion(question = question.question) KahootQuestion(question = question.question)
KahootReponses(reponses = question.reponses) { KahootReponses(reponses = question.reponses) {
sendReponse(currTime - System.currentTimeMillis()) sendResponse(currTime - System.currentTimeMillis())
Toast.makeText(context, it.reponse, Toast.LENGTH_SHORT).show() Toast.makeText(context, it.reponse, Toast.LENGTH_SHORT).show()
} }
} }
@ -88,5 +94,5 @@ fun KahootReponses(reponses : List<ReponseSimpleDTO>, action: (ReponseSimpleDTO)
@Composable @Composable
fun KahootQuestion(question: String){ fun KahootQuestion(question: String){
Text(question, textAlign = TextAlign.Center) Text(question, textAlign = TextAlign.Center, fontSize = 20.sp)
} }

@ -2,10 +2,16 @@ package fr.iut.sciencequest.view.games
import android.content.Context import android.content.Context
import android.widget.Toast import android.widget.Toast
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextField import androidx.compose.material3.TextField
@ -15,8 +21,11 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp 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 fr.iut.sciencequest.R import fr.iut.sciencequest.R
import fr.iut.sciencequest.ViewModels.PenduViewModel import fr.iut.sciencequest.ViewModels.PenduViewModel
@ -25,23 +34,33 @@ import fr.iut.sciencequest.view.TopBar
@Composable @Composable
fun PenduScreen(viewModel: PenduViewModel = viewModel(), fun PenduScreen(viewModel: PenduViewModel = viewModel(),
goToAccount: () -> Unit, goToAccount: () -> Unit,
goToHome: () -> Unit) { goToHome: () -> Unit
) {
val state = viewModel.uiState.collectAsState() val state = viewModel.uiState.collectAsState()
val context = LocalContext.current; val context = LocalContext.current;
Column(modifier = Modifier.fillMaxWidth()) { Column(modifier = Modifier.fillMaxWidth()) {
TopBar(goToAccount, goToHome, stringResource(id = R.string.pendu)) TopBar(goToAccount, goToHome, stringResource(id = R.string.pendu))
//Text(text = stringResource(id = R.string.pendu), modifier = Modifier.padding(top=10.dp)) //Text(text = stringResource(id = R.string.pendu), modifier = Modifier.padding(top=10.dp))
Column(modifier = Modifier.align(Alignment.CenterHorizontally)) Column(
{ horizontalAlignment = Alignment.CenterHorizontally,
Text(text = state.value.motATrou) verticalArrangement = Arrangement.SpaceAround,
TextField(value = "", modifier = Modifier.fillMaxSize()
onValueChange = { onLetterEntered(it, viewModel, context, goToHome) }, ) {
modifier = Modifier.padding(20.dp)) Text(text = state.value.motATrou, fontSize = 20.sp)
afficherVies(state.value.nbViesRestantes) Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.SpaceBetween,
) {
TextField(value = "",
onValueChange = { onLetterEntered(it, viewModel, context, goToHome) },
modifier = Modifier.padding(20.dp),
)
afficherVies(state.value.nbViesRestantes)
Text("Lettres utilisées: " + state.value.lettresUtilises)
}
Button(onClick = { viewModel.InitPartie() }) { Button(onClick = { viewModel.InitPartie() }) {
Text(text = stringResource(id = R.string.reset_game)) Text(text = stringResource(id = R.string.reset_game))
} }
Text("Lettres utilisées: " + state.value.lettresUtilises)
} }
} }
} }

Loading…
Cancel
Save