Compare commits

...

4 Commits

@ -60,6 +60,8 @@ dependencies {
implementation("androidx.compose.ui:ui-tooling-preview") implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3") implementation("androidx.compose.material3:material3")
implementation("androidx.compose.ui:ui-graphics-android:1.6.3") implementation("androidx.compose.ui:ui-graphics-android:1.6.3")
implementation("androidx.navigation:navigation-common-ktx:2.7.7")
implementation("androidx.navigation:navigation-compose:2.7.7")
testImplementation("junit:junit:4.13.2") testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

@ -1,7 +1,6 @@
package com.example.mathseduc package com.example.mathseduc
import android.os.Bundle import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable

@ -10,16 +10,27 @@ import androidx.activity.OnBackPressedCallback
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
@ -33,6 +44,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
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.controllers.ControllerChapter
import com.example.mathseduc.controllers.ControllerLobby import com.example.mathseduc.controllers.ControllerLobby
import com.example.mathseduc.controllers.ControllerPlayer import com.example.mathseduc.controllers.ControllerPlayer
import com.example.mathseduc.controllers.ControllerUtiliser import com.example.mathseduc.controllers.ControllerUtiliser
@ -81,17 +93,22 @@ class ServerDetailsActivity : ComponentActivity() {
finish() finish()
} }
@OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun ServerDetailPage() { fun ServerDetailPage() {
val context = LocalContext.current val context = LocalContext.current
val serverName = intent.getStringExtra("serverName") val serverName = intent.getStringExtra("serverName")
val lobbyId = intent.getIntExtra("lobbyId",-1) val lobbyId = intent.getIntExtra("lobbyId",-1)
val chapterId = intent.getIntExtra("chapterId",-1)
val nbPlayers = intent.getIntExtra("nbPlayers",-1)
val lobbyDifficulty = intent.getIntExtra("lobbyDifficulty",-1)
var isCreator by rememberSaveable { mutableStateOf(false) } var isCreator by rememberSaveable { mutableStateOf(false) }
var playerListInfos: List<Player> by rememberSaveable { mutableStateOf(emptyList()) } var playerListInfos: List<Player> by rememberSaveable { mutableStateOf(emptyList()) }
var playerList by rememberSaveable { mutableStateOf(ControllerPlayer.getPlayersIdFromLobbyId(lobbyId.toString()) ?: emptyList()) } var playerList by rememberSaveable { mutableStateOf(ControllerPlayer.getPlayersIdFromLobbyId(lobbyId.toString()) ?: emptyList()) }
var refreshState by rememberSaveable { mutableStateOf(true) } var refreshState by rememberSaveable { mutableStateOf(true) }
var showDialog by rememberSaveable { mutableStateOf(false) }
DisposableEffect(refreshState) { DisposableEffect(refreshState) {
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
@ -109,6 +126,9 @@ class ServerDetailsActivity : ComponentActivity() {
val intent = Intent(context, QuizMultiActivity::class.java) val intent = Intent(context, QuizMultiActivity::class.java)
intent.putExtra("serverName", serverName) intent.putExtra("serverName", serverName)
intent.putExtra("lobbyId", lobbyId) intent.putExtra("lobbyId", lobbyId)
intent.putExtra("chapterId", chapterId)
intent.putExtra("nbPlayers", nbPlayers)
intent.putExtra("lobbyDifficulty", lobbyDifficulty)
context.startActivity(intent) context.startActivity(intent)
refreshState = false refreshState = false
} }
@ -128,6 +148,26 @@ class ServerDetailsActivity : ComponentActivity() {
} }
} }
TopAppBar(
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color.Transparent,
),
title = {},
navigationIcon = {
IconButton(
onClick = { showDialog = true },
modifier = Modifier.size(60.dp)
) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = "Retour",
modifier = Modifier.size(36.dp),
tint = Color.White
)
}
},
)
val modifier = Modifier val modifier = Modifier
.fillMaxSize() .fillMaxSize()
.padding(16.dp) .padding(16.dp)
@ -139,13 +179,55 @@ class ServerDetailsActivity : ComponentActivity() {
) { ) {
Text( Text(
text = serverName!!, text = serverName!!,
color = Color.White,
fontSize = 30.sp,
fontWeight = FontWeight.Bold
)
Spacer(modifier = Modifier.height(25.dp))
Text(
text = "Lobby Settings",
fontSize = 23.sp,
color = Color.White, color = Color.White,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
Text(
text = "Chapter : ${ControllerChapter.getChapterNameById(chapterId).toString()}",
fontSize = 20.sp,
color = Color.White
)
Text(
text = "Players : ${ControllerLobby.getNbPlayerInLobby(lobbyId)}/${nbPlayers}",
fontSize = 20.sp,
color = (if(ControllerLobby.getNbPlayerInLobby(lobbyId)==nbPlayers) Color.Red else Color.White)
)
Text(
text = "Difficulty : $lobbyDifficulty",
fontSize = 20.sp,
color = Colors.White,
)
Spacer(modifier = Modifier.height(30.dp))
Text(
text = "Player Name",
fontSize = 20.sp,
color = Colors.White,
)
Divider(
color = Color.Gray,
thickness = 2.dp,
modifier = Modifier.fillMaxWidth()
)
LazyColumn( LazyColumn(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.weight(0.75f) .weight(0.75f)
.padding(top = 2.dp),
horizontalAlignment = Alignment.CenterHorizontally
) { ) {
items(playerListInfos) { player -> items(playerListInfos) { player ->
Text( Text(
@ -153,6 +235,7 @@ class ServerDetailsActivity : ComponentActivity() {
fontSize = 18.sp, fontSize = 18.sp,
color = Colors.White, color = Colors.White,
modifier = Modifier.weight(1f) modifier = Modifier.weight(1f)
.padding(top = 5.dp)
) )
} }
} }
@ -177,6 +260,40 @@ class ServerDetailsActivity : ComponentActivity() {
) )
} }
} }
if (showDialog) {
LeaveLobbyDialog(serverName, onConfirmLeave = {},onCancelLeave = { showDialog = false })
}
}
}
@Composable
fun LeaveLobbyDialog(namelobby: String, onConfirmLeave: () -> Unit, onCancelLeave: () -> Unit) {
val context = LocalContext.current
AlertDialog(
onDismissRequest = onCancelLeave,
title = { Text("Confirm leaving lobby") },
confirmButton = {
Button(
onClick = {
onConfirmLeave()
}
) {
Text("Leave")
}
},
dismissButton = {
Button(
onClick = {
onCancelLeave()
}
) {
Text("Cancel")
}
},
text = {
Text("Are you sure you want to leave the lobby $namelobby?")
} }
)
} }
} }

@ -266,6 +266,9 @@ fun CreateLobbyPage(navController: NavController) {
val intent = Intent(context, ServerDetailsActivity::class.java) val intent = Intent(context, ServerDetailsActivity::class.java)
intent.putExtra("lobbyId", lobbyId) intent.putExtra("lobbyId", lobbyId)
intent.putExtra("serverName", lobbyName) intent.putExtra("serverName", lobbyName)
intent.putExtra("chapterId", selectedChapter.id.toInt())
intent.putExtra("nbPlayers", nbPlayers.toInt())
intent.putExtra("lobbyDifficulty", difficultyNum)
context.startActivity(intent) 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()

@ -91,6 +91,7 @@ fun MultiPage(navController: NavController) {
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
// Hide the status bar and navigation bar FERME TA GUEULE !!!
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
@ -223,7 +224,14 @@ private suspend fun createUtiliserForLobby(context: Context, lobby: Lobby, navCo
ControllerUtiliser.createUtiliserByIdLobby(formDataBuilder) ControllerUtiliser.createUtiliserByIdLobby(formDataBuilder)
// Naviguer vers l'activité ServerDetails avec les détails du lobby // Naviguer vers l'activité ServerDetails avec les détails du lobby
navController.navigate("serverDetails/${lobby.name}/${lobby.id}") val intent = Intent(context, ServerDetailsActivity::class.java)
intent.putExtra("serverName", lobby.name)
intent.putExtra("lobbyId", lobby.id)
intent.putExtra("chapterId", lobby.idchapter)
intent.putExtra("nbPlayers", lobby.nbplayers)
intent.putExtra("lobbyDifficulty", lobby.difficulty)
context.startActivity(intent)
//navController.navigate("serverDetails/${lobby.name}/${lobby.id}")
} }
} }

Loading…
Cancel
Save