|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
package com.example.mathseduc.ui
|
|
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.app.Activity
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
@ -26,15 +26,15 @@ import androidx.compose.runtime.remember
|
|
|
|
|
import androidx.compose.runtime.setValue
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
|
|
import androidx.compose.ui.platform.LocalView
|
|
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
import androidx.core.view.WindowCompat
|
|
|
|
|
import androidx.core.view.WindowInsetsCompat
|
|
|
|
|
import androidx.core.view.WindowInsetsControllerCompat
|
|
|
|
|
import androidx.navigation.NavController
|
|
|
|
|
import com.example.mathseduc.MainActivity
|
|
|
|
|
import com.example.mathseduc.QuizMultiActivity
|
|
|
|
|
import com.example.mathseduc.ServerDetailsActivity
|
|
|
|
|
import com.example.mathseduc.controllers.ControllerLobby
|
|
|
|
|
import com.example.mathseduc.controllers.ControllerQuestion
|
|
|
|
|
import com.example.mathseduc.ui.theme.Colors
|
|
|
|
@ -43,16 +43,17 @@ import okhttp3.MultipartBody
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun QuizMultiScreen(lobbyId: Int,serverName: String,activity: QuizMultiActivity) {
|
|
|
|
|
fun QuizMultiScreen(navController: NavController, lobbyId: Int?) {
|
|
|
|
|
val context = LocalContext.current
|
|
|
|
|
val activity = LocalView.current.context as Activity
|
|
|
|
|
|
|
|
|
|
var chronoValue by remember { mutableStateOf(0.0f) }
|
|
|
|
|
var listQuestion by remember { mutableStateOf(ControllerQuestion.getQuestionsForLobby(ControllerLobby.getIdQuestionsLobby(lobbyId))) }
|
|
|
|
|
var listPlayer by remember { mutableStateOf(ControllerLobby.getPlayerInLobby(lobbyId)) }
|
|
|
|
|
var listQuestion by remember { mutableStateOf(ControllerQuestion.getQuestionsForLobby(ControllerLobby.getIdQuestionsLobby(lobbyId!!))) }
|
|
|
|
|
var listPlayer by remember { mutableStateOf(ControllerLobby.getPlayerInLobby(lobbyId!!)) }
|
|
|
|
|
var currentQuestionIndex by remember { mutableIntStateOf(0) }
|
|
|
|
|
val progressBarValues by remember { mutableStateOf(Array(listPlayer.size) { 0.0f }) }
|
|
|
|
|
val progressBarTotalValues by remember { mutableStateOf(Array(listPlayer.size) { 0.0f }) }
|
|
|
|
|
var quizFinished by remember { mutableStateOf(false) } // Variable pour indiquer si le quiz est terminé ou non
|
|
|
|
|
var quizFinished by remember { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
val windowInsetsController = remember {
|
|
|
|
|
WindowCompat.getInsetsController(activity.window, activity.window.decorView)
|
|
|
|
@ -81,7 +82,7 @@ fun QuizMultiScreen(lobbyId: Int,serverName: String,activity: QuizMultiActivity)
|
|
|
|
|
val timer = ticker(delayMillis = 3000)
|
|
|
|
|
for (tick in timer) {
|
|
|
|
|
if (quizFinished) break
|
|
|
|
|
var valueBD = ControllerLobby.getPlayerInLobby(lobbyId)
|
|
|
|
|
var valueBD = ControllerLobby.getPlayerInLobby(lobbyId!!)
|
|
|
|
|
for ((index, player) in listPlayer.withIndex()) {
|
|
|
|
|
progressBarTotalValues[index] = progressBarValues[index] + valueBD[index].playertime
|
|
|
|
|
}
|
|
|
|
@ -150,7 +151,7 @@ fun QuizMultiScreen(lobbyId: Int,serverName: String,activity: QuizMultiActivity)
|
|
|
|
|
Toast.makeText(context, "Oh ouii !!", Toast.LENGTH_SHORT).show()
|
|
|
|
|
|
|
|
|
|
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
|
|
|
|
|
val playertime = ControllerLobby.getLobbyUtiliserPlayerTime(lobbyId,MainActivity.idPlayerConnected) + 10
|
|
|
|
|
val playertime = ControllerLobby.getLobbyUtiliserPlayerTime(lobbyId!!,MainActivity.idPlayerConnected) + 10
|
|
|
|
|
formDataBuilder.addFormDataPart("playertime", playertime.toString())
|
|
|
|
|
|
|
|
|
|
ControllerLobby.updateLobbyUtiliserPlayerTime(lobbyId,MainActivity.idPlayerConnected,formDataBuilder)
|
|
|
|
@ -191,10 +192,7 @@ fun QuizMultiScreen(lobbyId: Int,serverName: String,activity: QuizMultiActivity)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(context, "Fini !!", Toast.LENGTH_SHORT).show()
|
|
|
|
|
val intent = Intent(context, MainActivity::class.java)
|
|
|
|
|
//intent.putExtra("serverName", serverName)
|
|
|
|
|
//intent.putExtra("lobbyId", lobbyId)
|
|
|
|
|
context.startActivity(intent)
|
|
|
|
|
navController.navigate("home")
|
|
|
|
|
quizFinished = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|