From a14b817c5b98fca4add45c852b1e0c5ca3af2f30 Mon Sep 17 00:00:00 2001 From: "maxence.guitard" Date: Thu, 28 Mar 2024 10:05:52 +0100 Subject: [PATCH] feat : design pagelobby et debut nav --- Android/app/build.gradle.kts | 2 + .../com/example/mathseduc/MainActivity.kt | 1 - .../mathseduc/ServerDetailsActivity.kt | 129 +++++++++++++++++- .../example/mathseduc/navigation/NavHost.kt | 33 ++++- .../mathseduc/ui/activity_create_lobby.kt | 3 + .../example/mathseduc/ui/activity_multi.kt | 5 +- 6 files changed, 164 insertions(+), 9 deletions(-) diff --git a/Android/app/build.gradle.kts b/Android/app/build.gradle.kts index 39a398f..da47354 100644 --- a/Android/app/build.gradle.kts +++ b/Android/app/build.gradle.kts @@ -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") diff --git a/Android/app/src/main/java/com/example/mathseduc/MainActivity.kt b/Android/app/src/main/java/com/example/mathseduc/MainActivity.kt index 427313e..3f03ee3 100644 --- a/Android/app/src/main/java/com/example/mathseduc/MainActivity.kt +++ b/Android/app/src/main/java/com/example/mathseduc/MainActivity.kt @@ -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 diff --git a/Android/app/src/main/java/com/example/mathseduc/ServerDetailsActivity.kt b/Android/app/src/main/java/com/example/mathseduc/ServerDetailsActivity.kt index 8c4715b..2a06919 100644 --- a/Android/app/src/main/java/com/example/mathseduc/ServerDetailsActivity.kt +++ b/Android/app/src/main/java/com/example/mathseduc/ServerDetailsActivity.kt @@ -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 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,9 +148,29 @@ 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) + .fillMaxSize() + .padding(16.dp) Column( modifier = modifier, @@ -140,12 +180,54 @@ 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) + .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) ) } } @@ -167,8 +250,8 @@ class ServerDetailsActivity : ComponentActivity() { enabled = isCreator, colors = ButtonDefaults.buttonColors(Colors.Green), modifier = Modifier - .fillMaxWidth() - .height(48.dp) + .fillMaxWidth() + .height(48.dp) ) { Text( text = "LAUNCH", @@ -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?") + } + ) + } + } diff --git a/Android/app/src/main/java/com/example/mathseduc/navigation/NavHost.kt b/Android/app/src/main/java/com/example/mathseduc/navigation/NavHost.kt index e9f09fe..bd4c439 100644 --- a/Android/app/src/main/java/com/example/mathseduc/navigation/NavHost.kt +++ b/Android/app/src/main/java/com/example/mathseduc/navigation/NavHost.kt @@ -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") + } + )*/ + } + } } \ No newline at end of file diff --git a/Android/app/src/main/java/com/example/mathseduc/ui/activity_create_lobby.kt b/Android/app/src/main/java/com/example/mathseduc/ui/activity_create_lobby.kt index 79b38dc..20a8731 100644 --- a/Android/app/src/main/java/com/example/mathseduc/ui/activity_create_lobby.kt +++ b/Android/app/src/main/java/com/example/mathseduc/ui/activity_create_lobby.kt @@ -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() diff --git a/Android/app/src/main/java/com/example/mathseduc/ui/activity_multi.kt b/Android/app/src/main/java/com/example/mathseduc/ui/activity_multi.kt index bcbf10b..d6614d4 100644 --- a/Android/app/src/main/java/com/example/mathseduc/ui/activity_multi.kt +++ b/Android/app/src/main/java/com/example/mathseduc/ui/activity_multi.kt @@ -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) } }