|
|
|
@ -50,6 +50,7 @@ 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 com.example.mathseduc.CreateLobbyActivity
|
|
|
|
|
import com.example.mathseduc.MainActivity
|
|
|
|
|
import com.example.mathseduc.MultiActivity
|
|
|
|
@ -72,7 +73,6 @@ fun MultiPage(activity: MultiActivity) {
|
|
|
|
|
var selectedItem by rememberSaveable { mutableStateOf<Lobby?>(null) }
|
|
|
|
|
var lobbyList by remember { mutableStateOf<List<Lobby>>(emptyList()) }
|
|
|
|
|
val scope = rememberCoroutineScope()
|
|
|
|
|
var refreshState by remember { mutableStateOf(true) }
|
|
|
|
|
|
|
|
|
|
val isPortrait = LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT
|
|
|
|
|
|
|
|
|
@ -82,8 +82,11 @@ fun MultiPage(activity: MultiActivity) {
|
|
|
|
|
WindowCompat.getInsetsController(activity.window, activity.window.decorView)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hide the status bar
|
|
|
|
|
windowInsetsController?.hide(WindowInsetsCompat.Type.statusBars())
|
|
|
|
|
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
|
|
|
|
|
|
|
|
|
// Hide the status bar and navigation bar ET OU MAXENCE Y'A UNE OPTION POUR FAIRE LES DEUX DIRECTEMENT REGARDE LA DOC FDP !!!
|
|
|
|
|
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fonction pour actualiser la liste des lobbies
|
|
|
|
|
suspend fun refreshLobbyList() {
|
|
|
|
@ -94,14 +97,11 @@ fun MultiPage(activity: MultiActivity) {
|
|
|
|
|
Log.e("MainActivity", "Refreshed Lobby List")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DisposableEffect(refreshState) {
|
|
|
|
|
DisposableEffect(Unit) {
|
|
|
|
|
val refreshRunnable = {
|
|
|
|
|
scope.launch(Dispatchers.IO) {
|
|
|
|
|
try {
|
|
|
|
|
while (refreshState) {
|
|
|
|
|
delay(5000)
|
|
|
|
|
refreshLobbyList()
|
|
|
|
|
}
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
Log.e("MainActivity", "Error refreshing lobbies: ${e.message}")
|
|
|
|
|
}
|
|
|
|
@ -110,8 +110,7 @@ fun MultiPage(activity: MultiActivity) {
|
|
|
|
|
refreshRunnable.invoke()
|
|
|
|
|
|
|
|
|
|
onDispose {
|
|
|
|
|
Toast.makeText(context, "Au REVOIR UwU", Toast.LENGTH_SHORT).show()
|
|
|
|
|
refreshState = false
|
|
|
|
|
Toast.makeText(context, "Au REVOIR", Toast.LENGTH_SHORT).show()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -155,7 +154,6 @@ fun MultiPage(activity: MultiActivity) {
|
|
|
|
|
)
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
refreshState = false
|
|
|
|
|
val intent = Intent(context, CreateLobbyActivity::class.java)
|
|
|
|
|
context.startActivity(intent)
|
|
|
|
|
},
|
|
|
|
@ -172,13 +170,12 @@ fun MultiPage(activity: MultiActivity) {
|
|
|
|
|
LazyColumn(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxSize()
|
|
|
|
|
.border(2.dp, Color.White,shape = RoundedCornerShape(3))
|
|
|
|
|
.border(2.dp, Color.White, shape = RoundedCornerShape(3))
|
|
|
|
|
.weight(0.85f),
|
|
|
|
|
) {
|
|
|
|
|
items(lobbyList) { lobby ->
|
|
|
|
|
LobbyItem(lobby, selectedItem == lobby) {
|
|
|
|
|
selectedItem = it
|
|
|
|
|
refreshState = false
|
|
|
|
|
|
|
|
|
|
if (ControllerLobby.getNbPlayerInLobby(selectedItem!!.id) < selectedItem!!.nbplayers) {
|
|
|
|
|
// Créer un Utiliser si le lobby n'est pas plein
|
|
|
|
@ -197,10 +194,24 @@ fun MultiPage(activity: MultiActivity) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
scope.launch {
|
|
|
|
|
refreshLobbyList()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth(),
|
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Blue)
|
|
|
|
|
) {
|
|
|
|
|
Text(text = "Actualiser")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fonction pour créer un Utiliser pour le lobby sélectionné
|
|
|
|
|
|
|
|
|
|
private suspend fun createUtiliserForLobby(context: Context, lobby: Lobby) {
|
|
|
|
|
withContext(Dispatchers.IO) {
|
|
|
|
|
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
|
|
|
|
|