feat : question, bar et chrono ajusté + sycro multi
continuous-integration/drone/push Build is passing Details

androidCompose
Jeremy DUCOURTHIAL 1 year ago
parent 14d05c7dd1
commit ab3563723e

@ -129,6 +129,8 @@ fun ConnexionPlayerContent(activity: ConnexionPlayerActivity) {
if (isAuthenticated != -1) { if (isAuthenticated != -1) {
MainActivity.idPlayerConnected = isAuthenticated MainActivity.idPlayerConnected = isAuthenticated
Toast.makeText(context, "Connexion réussie, bienvenue $nickname !", Toast.LENGTH_SHORT).show() Toast.makeText(context, "Connexion réussie, bienvenue $nickname !", Toast.LENGTH_SHORT).show()
val intent = Intent(context, MainActivity::class.java)
context.startActivity(intent)
} else { } else {
Toast.makeText(context, "Connexion échouée. Veuillez réessayer.", Toast.LENGTH_SHORT).show() Toast.makeText(context, "Connexion échouée. Veuillez réessayer.", Toast.LENGTH_SHORT).show()
} }

@ -21,7 +21,9 @@ class QuizMultiActivity : ComponentActivity() {
setContent { setContent {
MathsEducTheme { MathsEducTheme {
val lobbyId = intent.getIntExtra("lobbyId",-1) val lobbyId = intent.getIntExtra("lobbyId",-1)
QuizMultiScreen(lobbyId) //TODO sus val serverName = intent.getStringExtra("serverName")
QuizMultiScreen(lobbyId, serverName!!) //TODO sus
} }
} }
} }

@ -60,54 +60,6 @@ class ServerDetailsActivity : ComponentActivity() {
setContent { setContent {
ServerDetailPage() ServerDetailPage()
} }
/*
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
//setContentView(R.layout.activity_server_details)
val serverName = intent.getStringExtra("serverName")
val serverNameTextView = findViewById<TextView>(R.id.titleServerDetails)
serverNameTextView.text = serverName
val lobbyId = intent.getIntExtra("lobbyId", -1)
if (savedInstanceState != null) {
playerList = savedInstanceState?.getParcelableArrayList("playerList") ?: emptyList()
} else {
val playerId = ControllerPlayer.getPlayersIdFromLobbyId(lobbyId)
if (playerId != null) {
playerList = playerId.mapNotNull { playerId ->
ControllerPlayer.getPlayerInfoById(playerId.toString())
}
}
}
val listViewPlayers = findViewById<ListView>(R.id.listViewPlayers)
playerAdapter = PlayerAdapter(this, playerList)
listViewPlayers.adapter = playerAdapter
handler.postDelayed(refreshRunnable, refreshInterval)
val btnLaunchQuiz = findViewById<Button>(R.id.btnLaunchQuiz)
if (ControllerLobby.playerCreatorIdPresentInLobby(MainActivity.idPlayerConnected, lobbyId)) {
btnLaunchQuiz.visibility = View.VISIBLE
btnLaunchQuiz.setOnClickListener {
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
formDataBuilder.addFormDataPart("launched", "1")
ControllerLobby.updateLobbyLauched(lobbyId,formDataBuilder)
val intent = Intent(this, QuizMultiActivity::class.java)
intent.putExtra("lobbyId", lobbyId)
startActivity(intent)
}
} else {
btnLaunchQuiz.visibility = View.GONE
}
*/
} }
private fun myBackPressed() { private fun myBackPressed() {
@ -126,7 +78,6 @@ class ServerDetailsActivity : ComponentActivity() {
ControllerLobby.updateLobbyIdCreatorLobby(lobbyId, formDataBuilder) ControllerLobby.updateLobbyIdCreatorLobby(lobbyId, formDataBuilder)
} }
} }
//handler.removeCallbacks(refreshRunnable)
finish() finish()
} }
@ -134,7 +85,7 @@ class ServerDetailsActivity : ComponentActivity() {
fun ServerDetailPage() { fun ServerDetailPage() {
val context = LocalContext.current val context = LocalContext.current
val lobbyName = intent.getStringExtra("serverName") val serverName = intent.getStringExtra("serverName")
val lobbyId = intent.getIntExtra("lobbyId",-1) val lobbyId = intent.getIntExtra("lobbyId",-1)
var isCreator by rememberSaveable { mutableStateOf(false) } var isCreator by rememberSaveable { mutableStateOf(false) }
@ -156,6 +107,7 @@ class ServerDetailsActivity : ComponentActivity() {
if(ControllerLobby.lobbyIsLaunched(lobbyId)){ if(ControllerLobby.lobbyIsLaunched(lobbyId)){
val intent = Intent(context, QuizMultiActivity::class.java) val intent = Intent(context, QuizMultiActivity::class.java)
intent.putExtra("serverName", serverName)
intent.putExtra("lobbyId", lobbyId) intent.putExtra("lobbyId", lobbyId)
context.startActivity(intent) context.startActivity(intent)
refreshState = false refreshState = false
@ -186,7 +138,7 @@ class ServerDetailsActivity : ComponentActivity() {
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
Text( Text(
text = lobbyName!!, text = serverName!!,
color = Color.White, color = Color.White,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )

@ -162,7 +162,6 @@ class ControllerLobby {
Log.e("deleteLobby", "Error deleting lobby", e) Log.e("deleteLobby", "Error deleting lobby", e)
} }
} }
fun updateLobbyIdCreatorLobby(lobbyId: Int,lobbyData: MultipartBody.Builder) { fun updateLobbyIdCreatorLobby(lobbyId: Int,lobbyData: MultipartBody.Builder) {
try { try {
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build() val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
@ -175,7 +174,64 @@ class ControllerLobby {
val updateRequest = Request.Builder() val updateRequest = Request.Builder()
.url("https://trusting-panini.87-106-126-109.plesk.page/api/update/lobbies/idplayercreator/$lobbyId/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO") .url("https://trusting-panini.87-106-126-109.plesk.page/api/update/lobbies/idplayercreator/$lobbyId/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO")
// Ajoutez d'autres paramètres ou données pour la mise à jour si nécessaire // Ajoutez d'autres paramètres ou données pour la mise à jour si nécessaire
.post(lobbyData.build()) //TODO attention api pb .post(lobbyData.build())
.build()
// API Response
val updateResponse: Response = client.newCall(updateRequest).execute()
// Vérifier si la mise à jour a réussi
if (!updateResponse.isSuccessful) {
Log.e("updateLobby", "Error updating lobby")
}
} catch (e: Exception) {
// Log en cas d'erreur
Log.e("updateLobby", "Error updating lobby", e)
}
}
fun getLobbyUtiliserPlayerTime(lobbyId: Int, playerId: Int): Int {
try {
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy)
// Client HTTP API
val client = OkHttpClient()
// API Access - Mise à jour du lobby
val request = Request.Builder()
.url("https://trusting-panini.87-106-126-109.plesk.page/api/lobbies/utiliser/playertime/$lobbyId/$playerId/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO")
.build()
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw IOException("Unexpected code $response")
// Gson deserialization
val gson = Gson()
val typeTokenProduct = object : TypeToken<ArrayList<Utiliser>>() {}.type
val utiliser: ArrayList<Utiliser> = gson.fromJson(response.body!!.string(), typeTokenProduct)
return utiliser[0].playertime
}
} catch (e: Exception) {
// Log en cas d'erreur
Log.e("updateLobby", "Error updating lobby", e)
return -1
}
}
fun updateLobbyUtiliserPlayerTime(lobbyId: Int,playerId: Int,lobbyData: MultipartBody.Builder) {
try {
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy)
// Client HTTP API
val client = OkHttpClient()
// API Access - Mise à jour du lobby
val updateRequest = Request.Builder()
.url("https://trusting-panini.87-106-126-109.plesk.page/api/update/lobbies/utiliser/playertime/$lobbyId/$playerId/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO\n")
.post(lobbyData.build())
.build() .build()
// API Response // API Response
@ -203,7 +259,7 @@ class ControllerLobby {
val updateRequest = Request.Builder() val updateRequest = Request.Builder()
.url("https://trusting-panini.87-106-126-109.plesk.page/api/update/lobbies/launched/$lobbyId/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO") .url("https://trusting-panini.87-106-126-109.plesk.page/api/update/lobbies/launched/$lobbyId/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO")
// Ajoutez d'autres paramètres ou données pour la mise à jour si nécessaire // Ajoutez d'autres paramètres ou données pour la mise à jour si nécessaire
.post(lobbyData.build()) //TODO attention api pb .post(lobbyData.build())
.build() .build()
// API Response // API Response
@ -246,6 +302,30 @@ class ControllerLobby {
return -1 return -1
} }
fun getPlayerInLobby(lobbyId: Int): List<Utiliser> {
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy)
// Client HTTP API
val client = OkHttpClient()
// API Access
val request = Request.Builder()
.url("https://trusting-panini.87-106-126-109.plesk.page/api/utiliser/$lobbyId/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO")
.build()
// API Response
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw IOException("Unexpected code $response")
// Gson deserialization
val gson = Gson()
val typeTokenProduct = object : TypeToken<List<Utiliser>>() {}.type
return gson.fromJson(response.body!!.string(), typeTokenProduct)
}
}
fun lobbyIsLaunched(lobbyId: Int): Boolean { fun lobbyIsLaunched(lobbyId: Int): Boolean {
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build() val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()

@ -25,7 +25,6 @@ class ControllerQuestion {
return if (questions.isNotEmpty()) questions else null return if (questions.isNotEmpty()) questions else null
} }
@SuppressLint("SuspiciousIndentation")
private fun getQuestionById(questionId: String): Question? { private fun getQuestionById(questionId: String): Question? {
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build() val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy) StrictMode.setThreadPolicy(policy)

@ -1,5 +1,4 @@
package com.example.mathseduc.models package com.example.mathseduc.models
data class Utiliser ( data class Utiliser (
val idlobby: Int, val idlobby: Int,
val idplayer: Int, val idplayer: Int,

@ -1,5 +1,6 @@
package com.example.mathseduc.ui package com.example.mathseduc.ui
import android.content.Intent
import android.widget.Toast 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
@ -28,29 +29,49 @@ 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
import com.example.mathseduc.MainActivity
import com.example.mathseduc.ServerDetailsActivity
import com.example.mathseduc.controllers.ControllerLobby import com.example.mathseduc.controllers.ControllerLobby
import com.example.mathseduc.controllers.ControllerQuestion import com.example.mathseduc.controllers.ControllerQuestion
import com.example.mathseduc.ui.theme.Colors import com.example.mathseduc.ui.theme.Colors
import kotlinx.coroutines.channels.ticker import kotlinx.coroutines.channels.ticker
import okhttp3.MultipartBody
@Composable @Composable
fun QuizMultiScreen(lobbyId: Int) { fun QuizMultiScreen(lobbyId: Int,serverName: String) {
val context = LocalContext.current val context = LocalContext.current
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 listPlayer by remember { mutableStateOf(ControllerLobby.getPlayerInLobby(lobbyId)) }
var currentQuestionIndex by remember { mutableIntStateOf(0) } 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
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 if (quizFinished) break
for ((index, player) in listPlayer.withIndex()) {
progressBarValues[index] += 0.1f
}
chronoValue += 0.1f chronoValue += 0.1f
if (chronoValue >= 30f) { if (chronoValue >= 30f) {
currentQuestionIndex++ currentQuestionIndex++
break chronoValue = 0.0f
}
}
}
LaunchedEffect(Unit) {
val timer = ticker(delayMillis = 3000)
for (tick in timer) {
if (quizFinished) break
var valueBD = ControllerLobby.getPlayerInLobby(lobbyId)
for ((index, player) in listPlayer.withIndex()) {
progressBarTotalValues[index] = progressBarValues[index] + valueBD[index].playertime
} }
} }
} }
@ -62,8 +83,9 @@ fun QuizMultiScreen(lobbyId: Int) {
verticalArrangement = Arrangement.SpaceBetween verticalArrangement = Arrangement.SpaceBetween
) { ) {
// ProgressBar1 for ((index, player) in listPlayer.withIndex()) {
CustomProgressBar(progressBar1Value) CustomProgressBar(progressBarTotalValues[index])
}
// Chrono ProgressBar // Chrono ProgressBar
ChronoProgressBar(chronoValue) ChronoProgressBar(chronoValue)
@ -114,7 +136,12 @@ fun QuizMultiScreen(lobbyId: Int) {
onClick = { onClick = {
if (answer.id == currentQuestion.idanswergood) { if (answer.id == currentQuestion.idanswergood) {
Toast.makeText(context, "Oh ouii !!", Toast.LENGTH_SHORT).show() Toast.makeText(context, "Oh ouii !!", Toast.LENGTH_SHORT).show()
progressBar1Value += 10f
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
val playertime = ControllerLobby.getLobbyUtiliserPlayerTime(lobbyId,MainActivity.idPlayerConnected) + 10
formDataBuilder.addFormDataPart("playertime", playertime.toString())
ControllerLobby.updateLobbyUtiliserPlayerTime(lobbyId,MainActivity.idPlayerConnected,formDataBuilder)
} else { } else {
Toast.makeText(context, "Oh nan !!", Toast.LENGTH_SHORT).show() Toast.makeText(context, "Oh nan !!", Toast.LENGTH_SHORT).show()
} }
@ -152,6 +179,11 @@ fun QuizMultiScreen(lobbyId: Int) {
} }
} else { } else {
Toast.makeText(context, "Fini !!", Toast.LENGTH_SHORT).show() 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)
quizFinished = true
} }
} }
} }

Loading…
Cancel
Save