feat : design pagelobby et debut nav

androidCompose
Maxence GUITARD 1 year ago
parent 6ee098482e
commit a14b817c5b

@ -60,6 +60,8 @@ dependencies {
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
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")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

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

@ -10,16 +10,27 @@ import androidx.activity.OnBackPressedCallback
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
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.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.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
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.unit.dp
import androidx.compose.ui.unit.sp
import com.example.mathseduc.controllers.ControllerChapter
import com.example.mathseduc.controllers.ControllerLobby
import com.example.mathseduc.controllers.ControllerPlayer
import com.example.mathseduc.controllers.ControllerUtiliser
@ -81,17 +93,22 @@ class ServerDetailsActivity : ComponentActivity() {
finish()
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ServerDetailPage() {
val context = LocalContext.current
val serverName = intent.getStringExtra("serverName")
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 playerListInfos: List<Player> by rememberSaveable { mutableStateOf(emptyList()) }
var playerList by rememberSaveable { mutableStateOf(ControllerPlayer.getPlayersIdFromLobbyId(lobbyId.toString()) ?: emptyList()) }
var refreshState by rememberSaveable { mutableStateOf(true) }
var showDialog by rememberSaveable { mutableStateOf(false) }
DisposableEffect(refreshState) {
val handler = Handler(Looper.getMainLooper())
@ -109,6 +126,9 @@ class ServerDetailsActivity : ComponentActivity() {
val intent = Intent(context, QuizMultiActivity::class.java)
intent.putExtra("serverName", serverName)
intent.putExtra("lobbyId", lobbyId)
intent.putExtra("chapterId", chapterId)
intent.putExtra("nbPlayers", nbPlayers)
intent.putExtra("lobbyDifficulty", lobbyDifficulty)
context.startActivity(intent)
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
.fillMaxSize()
.padding(16.dp)
@ -139,13 +179,55 @@ class ServerDetailsActivity : ComponentActivity() {
) {
Text(
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,
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(
modifier = Modifier
.fillMaxSize()
.weight(0.75f)
.padding(top = 2.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
items(playerListInfos) { player ->
Text(
@ -153,6 +235,7 @@ class ServerDetailsActivity : ComponentActivity() {
fontSize = 18.sp,
color = Colors.White,
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?")
}
)
}
}

@ -1,4 +1,35 @@
package com.example.mathseduc.navigation
class NavHost {
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.example.mathseduc.ui.HomePage
@Composable
fun NavHost() {
val navController = rememberNavController()
NavHost(
modifier = Modifier.fillMaxSize(),
navController = navController,
startDestination = "home"
) {
composable(route = "home") {
/*HomePage(
goToConnexion = {
navController.navigate("Connexion")
},
goToMulti = {
navController.navigate("Multi")
}
)*/
}
}
}

@ -263,6 +263,9 @@ fun CreateLobbyPage(activity: CreateLobbyActivity) {
val intent = Intent(context, ServerDetailsActivity::class.java)
intent.putExtra("lobbyId", lobbyId)
intent.putExtra("serverName", lobbyName)
intent.putExtra("chapterId", selectedChapter.id.toInt())
intent.putExtra("nbPlayers", nbPlayers.toInt())
intent.putExtra("lobbyDifficulty", difficultyNum)
context.startActivity(intent)
} else {
Toast.makeText(context, "Failed to create lobby. Please try again.", Toast.LENGTH_SHORT).show()

@ -89,7 +89,7 @@ fun MultiPage(activity: MultiActivity) {
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 !!!
// Hide the status bar and navigation bar FERME TA GUEULE !!!
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
@ -226,6 +226,9 @@ private suspend fun createUtiliserForLobby(context: Context, lobby: Lobby) {
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)
}
}

Loading…
Cancel
Save