|
|
@ -1,5 +1,6 @@
|
|
|
|
package com.example.mathseduc.ui
|
|
|
|
package com.example.mathseduc.ui
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.widget.Toast
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
@ -18,10 +19,12 @@ import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
|
|
|
|
import androidx.compose.runtime.mutableIntStateOf
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.runtime.setValue
|
|
|
|
import androidx.compose.runtime.setValue
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
@ -33,17 +36,20 @@ import kotlinx.coroutines.channels.ticker
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun QuizMultiScreen(lobbyId: Int) {
|
|
|
|
fun QuizMultiScreen(lobbyId: Int) {
|
|
|
|
|
|
|
|
val context = LocalContext.current
|
|
|
|
|
|
|
|
|
|
|
|
var progressBar1Value by remember { mutableStateOf(0.0f) }
|
|
|
|
var progressBar1Value by remember { mutableStateOf(0.0f) }
|
|
|
|
var chronoValue by remember { mutableStateOf(0.0f) }
|
|
|
|
var chronoValue by remember { mutableStateOf(0.0f) }
|
|
|
|
var listQuestion by remember { mutableStateOf(ControllerQuestion.getQuestionsForLobby(ControllerLobby.getIdQuestionsLobby(lobbyId))) }
|
|
|
|
var listQuestion by remember { mutableStateOf(ControllerQuestion.getQuestionsForLobby(ControllerLobby.getIdQuestionsLobby(lobbyId))) }
|
|
|
|
|
|
|
|
var currentQuestionIndex by remember { mutableIntStateOf(0) }
|
|
|
|
|
|
|
|
|
|
|
|
LaunchedEffect(Unit) {
|
|
|
|
LaunchedEffect(Unit) {
|
|
|
|
val timer = ticker(delayMillis = 100) // Update every 100 milliseconds
|
|
|
|
val timer = ticker(delayMillis = 100) // Update every 100 milliseconds
|
|
|
|
for (tick in timer) {
|
|
|
|
for (tick in timer) {
|
|
|
|
progressBar1Value += 0.1f // Increment ProgressBar1 value every 100ms
|
|
|
|
progressBar1Value += 0.1f
|
|
|
|
chronoValue += 0.1f // Increment Chrono value every 100ms
|
|
|
|
chronoValue += 0.1f
|
|
|
|
if (chronoValue >= 30f) {
|
|
|
|
if (chronoValue >= 30f) {
|
|
|
|
// Time's up, do something
|
|
|
|
currentQuestionIndex++
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -62,6 +68,15 @@ fun QuizMultiScreen(lobbyId: Int) {
|
|
|
|
// Chrono ProgressBar
|
|
|
|
// Chrono ProgressBar
|
|
|
|
ChronoProgressBar(chronoValue)
|
|
|
|
ChronoProgressBar(chronoValue)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentQuestionIndex < listQuestion!!.size) {
|
|
|
|
|
|
|
|
val currentQuestion = listQuestion!![currentQuestionIndex]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Column(
|
|
|
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
|
|
|
.fillMaxSize()
|
|
|
|
|
|
|
|
.padding(8.dp),
|
|
|
|
|
|
|
|
verticalArrangement = Arrangement.SpaceBetween
|
|
|
|
|
|
|
|
) {
|
|
|
|
Row(
|
|
|
|
Row(
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.weight(2f)
|
|
|
|
.weight(2f)
|
|
|
@ -75,9 +90,8 @@ fun QuizMultiScreen(lobbyId: Int) {
|
|
|
|
.background(color = Colors.Grey, shape = RoundedCornerShape(8.dp))
|
|
|
|
.background(color = Colors.Grey, shape = RoundedCornerShape(8.dp))
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Text(
|
|
|
|
Text(
|
|
|
|
text = "test",
|
|
|
|
text = currentQuestion.content,
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier.padding(16.dp),
|
|
|
|
.padding(16.dp),
|
|
|
|
|
|
|
|
color = Colors.White,
|
|
|
|
color = Colors.White,
|
|
|
|
fontSize = 20.sp,
|
|
|
|
fontSize = 20.sp,
|
|
|
|
textAlign = TextAlign.Center
|
|
|
|
textAlign = TextAlign.Center
|
|
|
@ -88,68 +102,33 @@ fun QuizMultiScreen(lobbyId: Int) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Column(modifier = Modifier.weight(1f)) {
|
|
|
|
Column(modifier = Modifier.weight(1f)) {
|
|
|
|
Row(
|
|
|
|
currentQuestion.answers.forEachIndexed { index, answer ->
|
|
|
|
modifier = Modifier
|
|
|
|
val buttonBackgroundColor = when (index) {
|
|
|
|
.fillMaxWidth()
|
|
|
|
0 -> Colors.Red
|
|
|
|
.padding(bottom = 10.dp)
|
|
|
|
1 -> Colors.Blue
|
|
|
|
) {
|
|
|
|
2 -> Colors.Green
|
|
|
|
Spacer(modifier = Modifier.weight(0.25f))
|
|
|
|
else -> Colors.Cyan
|
|
|
|
|
|
|
|
|
|
|
|
Button(
|
|
|
|
|
|
|
|
onClick = { /* Handle button click */ },
|
|
|
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
|
|
|
.weight(2f),
|
|
|
|
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Blue),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text(text = "Answer1")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.weight(0.5f))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Button(
|
|
|
|
Button(
|
|
|
|
onClick = { /* Handle button click */ },
|
|
|
|
onClick = {
|
|
|
|
modifier = Modifier
|
|
|
|
if (answer.id == currentQuestion.idanswergood) {
|
|
|
|
.weight(2f),
|
|
|
|
Toast.makeText(context, "Oh ouii !!", Toast.LENGTH_SHORT).show()
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
progressBar1Value += 10f
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Green),
|
|
|
|
} else {
|
|
|
|
) {
|
|
|
|
Toast.makeText(context, "Oh nan !!", Toast.LENGTH_SHORT).show()
|
|
|
|
Text(text = "Answer2")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.weight(0.25f))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentQuestionIndex++
|
|
|
|
Row(
|
|
|
|
},
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.fillMaxWidth()
|
|
|
|
.fillMaxWidth()
|
|
|
|
) {
|
|
|
|
.padding(bottom = 10.dp),
|
|
|
|
Spacer(modifier = Modifier.weight(0.25f))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Button(
|
|
|
|
|
|
|
|
onClick = { /* Handle button click */ },
|
|
|
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
|
|
|
.weight(2f),
|
|
|
|
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Orange),
|
|
|
|
colors = ButtonDefaults.buttonColors(buttonBackgroundColor)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Text(text = "Answer3")
|
|
|
|
Text(text = answer.content)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.weight(0.5f))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Button(
|
|
|
|
|
|
|
|
onClick = { /* Handle button click */ },
|
|
|
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
|
|
|
.weight(2f),
|
|
|
|
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Purple500),
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text(text = "Answer4")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.weight(0.25f))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -159,33 +138,20 @@ fun QuizMultiScreen(lobbyId: Int) {
|
|
|
|
.weight(1f)
|
|
|
|
.weight(1f)
|
|
|
|
.padding(vertical = 10.dp)
|
|
|
|
.padding(vertical = 10.dp)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Spacer(modifier = Modifier.weight(1f))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Button(
|
|
|
|
|
|
|
|
onClick = { /* Handle button click (Passer) */ },
|
|
|
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
|
|
|
.weight(2f),
|
|
|
|
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Red),
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text(text = "Passer")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.weight(0.15f))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Button(
|
|
|
|
Button(
|
|
|
|
onClick = {
|
|
|
|
onClick = {
|
|
|
|
progressBar1Value += 3f
|
|
|
|
currentQuestionIndex++
|
|
|
|
},
|
|
|
|
},
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.weight(2f),
|
|
|
|
.weight(2f),
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Green),
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Grey),
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Text(text = "Valider")
|
|
|
|
Text(text = "Passer")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
Spacer(modifier = Modifier.weight(1f))
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Toast.makeText(context, "Fini !!", Toast.LENGTH_SHORT).show()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|