fix : correction de divers problemes sur les changements de pages et la creation des lobbies
continuous-integration/drone/push Build is passing Details

androidCompose
Yvan CALATAYUD 1 year ago
parent d687d2cf96
commit 10a5fbfc23

@ -30,8 +30,6 @@ class QuizMultiActivity : ComponentActivity() {
// Stop the CountDownTimer to avoid memory leaks // Stop the CountDownTimer to avoid memory leaks
countDownTimer?.cancel() countDownTimer?.cancel()
} }
} }
@Preview(showBackground = true) @Preview(showBackground = true)
@ -40,5 +38,4 @@ fun QuizMultiScreenPreview() {
MathsEducTheme { MathsEducTheme {
QuizMultiScreen() QuizMultiScreen()
} }
} }

@ -1,9 +1,10 @@
package com.example.mathseduc package com.example.mathseduc
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.widget.Toast import android.util.Log
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.OnBackPressedCallback import androidx.activity.OnBackPressedCallback
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
@ -146,30 +147,31 @@ class ServerDetailsActivity : ComponentActivity() {
val refreshRunnable = object : Runnable { val refreshRunnable = object : Runnable {
override fun run() { override fun run() {
playerList = ControllerPlayer.getPlayersIdFromLobbyId(lobbyId.toString())!! playerList = ControllerPlayer.getPlayersIdFromLobbyId(lobbyId.toString())!!
handler.post(this)
if (playerList != null) { playerListInfos = playerList.mapNotNull { playerId ->
playerListInfos = playerList.mapNotNull { playerId -> ControllerPlayer.getPlayerInfoById(playerId.toString())
ControllerPlayer.getPlayerInfoById(playerId.toString())
}
} }
isCreator = ControllerLobby.playerCreatorIdPresentInLobby(MainActivity.idPlayerConnected, lobbyId!!.toInt()) isCreator = ControllerLobby.playerCreatorIdPresentInLobby(MainActivity.idPlayerConnected, lobbyId)
Toast.makeText(context, "TOTO", Toast.LENGTH_SHORT).show()
if(ControllerLobby.lobbyIsLaunched(lobbyId!!.toInt())){ if(ControllerLobby.lobbyIsLaunched(lobbyId)){
//val intent = Intent(this@ServerDetailsActivity, QuizMultiActivity::class.java) val intent = Intent(context, QuizMultiActivity::class.java)
//intent.putExtra("lobbyId", lobbyId) intent.putExtra("lobbyId", lobbyId)
//startActivity(intent) context.startActivity(intent)
Toast.makeText(context, isCreator.toString(), Toast.LENGTH_SHORT).show() refreshState = false
return }
if (refreshState){
handler.postDelayed(this,3000)
Log.e("MainActivity", "Refresh ServerDetails")
} }
} }
} }
handler.postDelayed(refreshRunnable, 2000) handler.post(refreshRunnable)
onDispose { onDispose {
refreshState = false
handler.removeCallbacks(refreshRunnable) handler.removeCallbacks(refreshRunnable)
} }
} }
@ -203,9 +205,11 @@ class ServerDetailsActivity : ComponentActivity() {
} }
} }
if (isCreator) { if (isCreator) {
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
formDataBuilder.addFormDataPart("launched", "1")
Button( Button(
onClick = { onClick = {
Toast.makeText(context, "TOTOGOGOCREATOR", Toast.LENGTH_SHORT).show() ControllerLobby.updateLobbyLauched(lobbyId,formDataBuilder)
}, },
shape = RoundedCornerShape(15), shape = RoundedCornerShape(15),
enabled = isCreator, enabled = isCreator,

@ -7,4 +7,30 @@ data class Player(
val id: Int, val id: Int,
val nickname: String, val nickname: String,
val password: String val password: String
) ) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readString() ?: "",
parcel.readString() ?: ""
)
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(id)
parcel.writeString(nickname)
parcel.writeString(password)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Player> {
override fun createFromParcel(parcel: Parcel): Player {
return Player(parcel)
}
override fun newArray(size: Int): Array<Player?> {
return arrayOfNulls(size)
}
}
}

@ -1,6 +1,7 @@
package com.example.mathseduc.ui package com.example.mathseduc.ui
import android.content.Intent
import android.util.Log import android.util.Log
import android.widget.Toast import android.widget.Toast
import androidx.compose.foundation.background import androidx.compose.foundation.background
@ -37,8 +38,10 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.example.mathseduc.MainActivity import com.example.mathseduc.MainActivity
import com.example.mathseduc.ServerDetailsActivity
import com.example.mathseduc.controllers.ControllerChapter import com.example.mathseduc.controllers.ControllerChapter
import com.example.mathseduc.controllers.ControllerLobby import com.example.mathseduc.controllers.ControllerLobby
import com.example.mathseduc.controllers.ControllerUtiliser
import com.example.mathseduc.ui.theme.Colors import com.example.mathseduc.ui.theme.Colors
import okhttp3.MultipartBody import okhttp3.MultipartBody
@ -237,10 +240,18 @@ fun CreateLobbyPage() {
// Check if lobby creation is successful // Check if lobby creation is successful
if (lobbyId != -1) { if (lobbyId != -1) {
val formDataBuilderConnexion = MultipartBody.Builder().setType(MultipartBody.FORM)
formDataBuilderConnexion.addFormDataPart("idplayer", MainActivity.idPlayerConnected.toString())
formDataBuilderConnexion.addFormDataPart("idlobby", lobbyId.toString())
formDataBuilderConnexion.addFormDataPart("playertime", "0")
ControllerUtiliser.createUtiliserByIdLobby(formDataBuilderConnexion)
Toast.makeText(context, "Lobby created successfully!", Toast.LENGTH_SHORT).show() Toast.makeText(context, "Lobby created successfully!", Toast.LENGTH_SHORT).show()
// val intent = Intent(context, LobbyDetailsActivity::class.java) val intent = Intent(context, ServerDetailsActivity::class.java)
// intent.putExtra("lobbyId", lobbyId) intent.putExtra("lobbyId", lobbyId)
// context.startActivity(intent) intent.putExtra("serverName", lobbyName)
context.startActivity(intent)
} else { } else {
Toast.makeText(context, "Failed to create lobby. Please try again.", Toast.LENGTH_SHORT).show() Toast.makeText(context, "Failed to create lobby. Please try again.", Toast.LENGTH_SHORT).show()
} }

@ -67,10 +67,10 @@ fun MultiPage() {
} }
} }
handler.postDelayed(refreshRunnable, 3000) handler.post(refreshRunnable)
onDispose { onDispose {
Toast.makeText(context, "TOTO", Toast.LENGTH_SHORT).show() Toast.makeText(context, "Au REVOIR UwU", Toast.LENGTH_SHORT).show()
refreshState = false refreshState = false
handler.removeCallbacks(refreshRunnable) handler.removeCallbacks(refreshRunnable)
} }
@ -140,6 +140,8 @@ fun MultiPage() {
LobbyItem(lobby, selectedItem == lobby) { LobbyItem(lobby, selectedItem == lobby) {
selectedItem = it selectedItem = it
refreshState = false
if (ControllerLobby.getNbPlayerInLobby(selectedItem!!.id) < selectedItem!!.nbplayers){ if (ControllerLobby.getNbPlayerInLobby(selectedItem!!.id) < selectedItem!!.nbplayers){
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM) val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
formDataBuilder.addFormDataPart("idplayer", MainActivity.idPlayerConnected.toString()) formDataBuilder.addFormDataPart("idplayer", MainActivity.idPlayerConnected.toString())

@ -29,6 +29,7 @@ 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.compose.ui.unit.sp
import com.example.mathseduc.QuizMultiActivity import com.example.mathseduc.QuizMultiActivity
import com.example.mathseduc.controllers.ControllerLobby
import com.example.mathseduc.ui.theme.Colors import com.example.mathseduc.ui.theme.Colors
import com.example.mathseduc.ui.theme.MathsEducTheme import com.example.mathseduc.ui.theme.MathsEducTheme
@ -40,10 +41,14 @@ fun QuizMultiPreview() {
QuizMultiScreen() QuizMultiScreen()
} }
} }
@Composable @Composable
fun QuizMultiScreen() { fun QuizMultiScreen() {
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) }
//val lobbyId = intent.getIntExtra("lobbyId",-1)
//var listQuestion = ControllerLobby.getIdQuestionsLobby()
Column( Column(
modifier = Modifier modifier = Modifier

Loading…
Cancel
Save