diff --git a/What_The_Fantasy/app/build.gradle.kts b/What_The_Fantasy/app/build.gradle.kts index 4b7e70e..eb95a8a 100644 --- a/What_The_Fantasy/app/build.gradle.kts +++ b/What_The_Fantasy/app/build.gradle.kts @@ -1,6 +1,7 @@ plugins { alias(libs.plugins.android.application) alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlinx.serialization) } android { diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/BackBar.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/BackBar.kt new file mode 100644 index 0000000..c2deeda --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/BackBar.kt @@ -0,0 +1,64 @@ +package com.example.what_the_fantasy.ui.components + +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.size +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.AccountCircle +import androidx.compose.material.icons.rounded.ArrowBack +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.IconButtonColors +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.dp +import com.example.what_the_fantasy.R +import com.example.what_the_fantasy.ui.theme.colorButtonNav +import com.example.what_the_fantasy.ui.theme.colorNavBar + +@Composable +fun BackBar(navBack : () ->Unit , + content : @Composable ()-> Unit ){ + Column( + modifier = Modifier + .fillMaxSize() + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .height(70.dp) + .background(colorNavBar), + Arrangement.SpaceBetween, + verticalAlignment = Alignment.Bottom + ) { + IconButton(onClick = {navBack()}, + modifier = Modifier + .size(60.dp) + ) { + Icon(Icons.Rounded.ArrowBack, + contentDescription = "Back", + modifier = Modifier + .size(60.dp) + ) + } + + } + + Box(modifier = Modifier.background(Color.Black).fillMaxHeight()) { + content() + } + } +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/NavBar.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/NavBar.kt index 49cc408..8d89f41 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/NavBar.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/NavBar.kt @@ -1,36 +1,37 @@ package com.example.what_the_fantasy.ui.components -import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column - +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.rounded.* -import androidx.compose.material3.Button -import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.BottomAppBar import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.IconButtonColors -import androidx.compose.material3.Text +import androidx.compose.material3.IconToggleButton +import androidx.compose.material3.NavigationBar import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp import com.example.what_the_fantasy.R -import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.ui.theme.* @Composable @@ -44,117 +45,108 @@ fun NavBar(onProfile : Boolean = false , navControllerAccueil: (Int) -> Unit, navControllerQuiz: (Int) -> Unit, - content : @Composable ()-> Unit ) { + var theme by remember { mutableStateOf(true) } Column( modifier = Modifier .fillMaxSize() ) { - Row( + NavigationBar( modifier = Modifier - .fillMaxWidth() - .height(70.dp) - .background(colorNavBar), - Arrangement.SpaceBetween, - verticalAlignment = Alignment.Bottom + .fillMaxWidth(), + containerColor = colorNavBar ) { - ButtonIconVectorInt(Icons.Rounded.AccountCircle,"Profile",navControllerProfil,index,onProfile) - - - Button(onClick = {}, - colors = ButtonDefaults.buttonColors(containerColor = Color.Transparent) + Row( + modifier = Modifier + .fillMaxWidth(), + Arrangement.SpaceBetween, + verticalAlignment = Alignment.Bottom ) { - Image( - painter = painterResource(id = R.drawable.toggle), - contentDescription = "Theme" - ) - } + ButtonIconVectorInt(Icons.Rounded.AccountCircle,"Profile",navControllerProfil,index,onProfile) + + + IconButton(onClick = { theme=!theme}, + modifier = Modifier.size(60.dp) + .clip(RoundedCornerShape(0)) + ) { + Icon(painterResource( + if(theme)R.drawable.dark_mode_toggle_icon + else R.drawable.light_mode_toggle_icon), + contentDescription = "Dark mode", + modifier = Modifier.fillMaxSize(), + tint = Color.White + ) + } + } } - Box(modifier = Modifier.background(Color.Black).fillMaxHeight(0.92f)){ + Box(modifier = Modifier.background(Color.Black).fillMaxHeight(0.90f)){ content() } - Row(modifier = Modifier - .background(colorNavBar) + BottomAppBar (modifier = Modifier .fillMaxSize(), - horizontalArrangement = Arrangement.SpaceAround, - verticalAlignment = Alignment.CenterVertically + containerColor = colorNavBar ) { + Row(modifier = Modifier + .fillMaxSize(), + horizontalArrangement = Arrangement.SpaceAround, + verticalAlignment = Alignment.CenterVertically + ) { + + ButtonIconPainterInt(painterResource( + if(onFavorite)R.drawable.favorite_button_full + else R.drawable.favorite_button_empty + ),"Favorite",navControllerFavorite,index,onFavorite) - ButtonIconVectorInt(Icons.Rounded.Favorite,"Favorite",navControllerFavorite,index,onFavorite) + ButtonIconPainterInt(painterResource( + if(onAccueil)R.drawable.home_button_full + else R.drawable.home_button_empty + ),"Accueil",navControllerAccueil,index,onAccueil) - ButtonIconPainterInt(painterResource(R.mipmap.ic_launcher_foreground),"Accueil",navControllerAccueil,index,onAccueil) + ButtonIconPainterInt(painterResource( + if(onQuiz)R.drawable.quiz_button_full + else R.drawable.quiz_button_empty + ),"Quiz",navControllerQuiz,index,onQuiz) - ButtonIconVectorInt(Icons.Rounded.Create,"Quiz",navControllerQuiz,index,onQuiz) + } } } } -@Composable -fun ButtonIconVector(img : ImageVector, name : String, nav : ()->Unit ,onPage : Boolean){ - IconButton(onClick = {nav()}, - enabled = !onPage, - colors = IconButtonColors(Color.Transparent,Color.White,//couleur quand il n'est pas selectionné - Color.Transparent, colorButtonNav),//couleur quand il est selectionné - modifier = Modifier - .size(60.dp) - ) { - Icon(img, - contentDescription = name, - modifier = Modifier - .size(60.dp) - ) - } -} + @Composable fun ButtonIconVectorInt(img : ImageVector, name : String, nav : (Int)->Unit ,index: Int,onPage : Boolean){ IconButton(onClick = {nav(index)}, enabled = !onPage, - colors = IconButtonColors(Color.Transparent,Color.White,//couleur quand il n'est pas selectionné - Color.Transparent, colorButtonNav),//couleur quand il est selectionné + colors = IconButtonColors(Color.Transparent, colorButtonNav,//couleur quand il n'est pas selectionné + Color.Transparent, colorButtonNavSelected),//couleur quand il est selectionné modifier = Modifier .size(60.dp) ) { Icon(img, contentDescription = name, modifier = Modifier - .size(60.dp) + .fillMaxSize() ) } } -@Composable -fun ButtonIconPainter(img : Painter, name : String, nav : ()->Unit,onPage : Boolean){ - IconButton(onClick = {nav()}, - enabled = !onPage, - colors = IconButtonColors(Color.Transparent,Color.White,//couleur quand il n'est pas selectionné - Color.Transparent, colorButtonNav),//couleur quand il est selectionné - modifier = Modifier - .size(60.dp) - ) { - Icon(img, - contentDescription = name, - modifier = Modifier - .size(60.dp) - ) - } -} @Composable fun ButtonIconPainterInt(img : Painter, name : String, nav : (Int)->Unit,index: Int,onPage : Boolean){ IconButton(onClick = {nav(index)}, enabled = !onPage, - colors = IconButtonColors(Color.Transparent,Color.White,//couleur quand il n'est pas selectionné - Color.Transparent, colorButtonNav),//couleur quand il est selectionné + colors = IconButtonColors(Color.Transparent,colorButtonNav,//couleur quand il n'est pas selectionné + Color.Transparent, colorButtonNavSelected),//couleur quand il est selectionné modifier = Modifier .size(60.dp) ) { Icon(img, contentDescription = name, modifier = Modifier - .size(60.dp) + .fillMaxSize() ) } } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt index 8b9186b..1425e65 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt @@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController +import androidx.navigation.toRoute import com.example.what_the_fantasy.data.services.ServicesStub import com.example.what_the_fantasy.ui.screens.AccueilPage import com.example.what_the_fantasy.ui.screens.FavoritePage @@ -16,155 +17,128 @@ import com.example.what_the_fantasy.ui.screens.QuotePage import com.example.what_the_fantasy.ui.screens.SearchPage import com.example.what_the_fantasy.ui.screens.SignUpPage import com.example.what_the_fantasy.ui.screens.SubmitQuotePage +import kotlinx.serialization.Serializable +@Serializable +data class Accueil(val userIndex: Int) +@Serializable +data object Login +@Serializable +data class Favorite(val userIndex: Int) +@Serializable +data class Profil(val userIndex: Int) +@Serializable +data class QuizMenu(val userIndex: Int) +@Serializable +data class Quiz(val userIndex : Int, val idQuiz : Int) +@Serializable +data class QuizEnd(val userIndex : Int, val idQuiz : Int,val pts : Int) +@Serializable +data object Quote +@Serializable +data object Search +@Serializable +data object SignUp +@Serializable +data object SubmitQuote -sealed class Destination(val route: String) { - data object Login : Destination("Login") - data object Accueil : Destination("Accueil/{userIndex}") { // Ajout du paramètre userIndex - fun createRoute(userIndex: Int) = "Accueil/$userIndex" // Fonction pour créer la route avec l'index - } - data object Favorite : Destination("Favorite/{userIndex}") { // Ajout du paramètre userIndex - fun createRoute(userIndex: Int) = "Favorite/$userIndex" // Fonction pour créer la route avec l'index - } - data object Profil : Destination("Profil/{userIndex}") { // Ajout du paramètre userIndex - fun createRoute(userIndex: Int) = "Profil/$userIndex" // Fonction pour créer la route avec l'index - } - data object QuizMenu : Destination("QuizMenu/{userIndex}") { // Ajout du paramètre userIndex - fun createRoute(userIndex: Int) = "QuizMenu/$userIndex" // Fonction pour créer la route avec l'index - } - data object Quiz : Destination("Quiz/{idQuiz}") { - // Ajout paramètre idQuiz - fun createId(idQuiz : Int) = "Quiz/$idQuiz" - } - data object QuizEnd : Destination("QuizEnd/{idQuiz}/{pts}") { - // Ajout paramètres idQuiz et pts - fun createIdAndPts(idQuiz : Int, pts : Int) = "QuizEnd/$idQuiz/$pts" - } - data object Quote : Destination("Quote") - data object Search : Destination("Search") - data object SignUp : Destination("SignUp") - data object SubmitQuote : Destination("SubmitQuote") -} - @Composable fun AppNavigator() { val navController = rememberNavController() val services = ServicesStub() - NavHost(navController, startDestination = Destination.Login.route) { - composable(Destination.Login.route) { + NavHost(navController, startDestination = Login) { + composable { LoginPage( - navControllerSignUp = { - navController.navigate(Destination.SignUp.route) - }, + navControllerSignUp = { navController.navigate(SignUp) }, navControllerProfil = { userIndex -> - navController.navigate(Destination.Profil.createRoute(userIndex)) { + navController.navigate(Profil(userIndex)) { // Vider pile de navigation pour empêcher le retour à la page Login - popUpTo(Destination.Login.route) { inclusive = true } + popUpTo(Login) { inclusive = true } } }, - services + services = services ) } - composable(Destination.Accueil.route) { - val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 + composable { + val accueil: Accueil = it.toRoute() AccueilPage( - index = userIndex, - navFavorite = { userIndex -> - navController.navigate(Destination.Favorite.createRoute(userIndex)) // Passe l'index à Profil - }, - navQuiz = { userIndex -> - navController.navigate(Destination.QuizMenu.createRoute(userIndex)) // Passe l'index à Profil - }, - navProfil = { userIndex -> - navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil - } + index = accueil.userIndex, + navFavorite = { navController.navigate(Favorite(accueil.userIndex)) }, + navQuiz = { navController.navigate(QuizMenu(accueil.userIndex)) }, + navProfil = { navController.navigate(Profil(accueil.userIndex)) } ) } - composable(Destination.Favorite.route) { - val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 + composable { + val favorite: Favorite = it.toRoute() FavoritePage( - index = userIndex, - navAccueil ={ userIndex -> - navController.navigate(Destination.Accueil.createRoute(userIndex)) // Passe l'index à Profil - }, - navQuiz = { userIndex -> - navController.navigate(Destination.QuizMenu.createRoute(userIndex)) // Passe l'index à Profil - }, - navProfil = { userIndex -> - navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil - } + index = favorite.userIndex, + navAccueil ={ navController.navigate( Accueil(favorite.userIndex) ) }, + navQuiz = { navController.navigate(QuizMenu(favorite.userIndex)) }, + navProfil = { navController.navigate(Profil(favorite.userIndex)) } ) } - composable(Destination.Profil.route) { - // Récupère l'index passé dans la route - val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 + composable{ + val profil:Profil = it.toRoute() ProfilPage( - index = userIndex, - navFavorite = { userIndex -> - navController.navigate(Destination.Favorite.createRoute(userIndex)) // Passe l'index à Profil - }, - navAccueil ={ userIndex -> - navController.navigate(Destination.Accueil.createRoute(userIndex)) // Passe l'index à Profil - }, - navQuiz = { userIndex -> - navController.navigate(Destination.QuizMenu.createRoute(userIndex)) // Passe l'index à Profil - }, + index = profil.userIndex, + navFavorite = { navController.navigate(Favorite(profil.userIndex)) }, + navAccueil ={ navController.navigate( Accueil(profil.userIndex) ) }, + navQuiz = { navController.navigate( QuizMenu(profil.userIndex)) }, navUnLog = { - navController.navigate(Destination.Login.route) { + navController.navigate(Login) { // Vider pile de navigation pour empêcher le retour à la page profil - popUpTo(Destination.Profil.route) { inclusive = true } + popUpTo(profil) { inclusive = true } } }, services = services ) } - composable(Destination.Quote.route) { QuotePage() } - composable(Destination.Search.route) { SearchPage() } - composable(Destination.SignUp.route) { SignUpPage( + composable { QuotePage() } + composable { SearchPage() } + composable { SignUpPage( navControllerLogin = { - navController.navigate(Destination.Login.route){ + navController.navigate(Login){ // Vider pile de navigation pour empêcher le retour à la page Sign up - popUpTo(Destination.Login.route) { inclusive = true } + popUpTo(Login) { inclusive = true } } },services) } - composable(Destination.SubmitQuote.route) { SubmitQuotePage() } + composable { SubmitQuotePage() } - composable(Destination.QuizMenu.route) { - //val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 + composable { + val quizMenu:QuizMenu=it.toRoute() QuizMenu( - //index = userIndex, -// navAccueil = { userIndex -> -// navController.navigate(Destination.Accueil.createRoute(userIndex)) // Passe l'index à Profil -// }, -// navFavorite = { userIndex -> -// navController.navigate(Destination.Favorite.createRoute(userIndex)) // Passe l'index à Profil -// }, -// navProfil = { userIndex -> -// navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil -// }, - navControllerQuiz = { id -> - navController.navigate(Destination.Quiz.createId(id)) + index = quizMenu.userIndex, + navAccueil = { navController.navigate( Accueil(quizMenu.userIndex) ) }, + navFavorite = { navController.navigate(Favorite(quizMenu.userIndex)) }, + navProfil = { navController.navigate(Profil(quizMenu.userIndex)) }, + navControllerQuiz = { idQuiz -> + navController.navigate(Quiz(quizMenu.userIndex,idQuiz)) } ) } - composable(Destination.Quiz.route) { backStackEntry -> - val idQuiz = backStackEntry.arguments?.getString("idQuiz")?.toInt() ?: 0 + composable { + val quiz:Quiz=it.toRoute() QuizPage( + index = quiz.userIndex, + navAccueil = { navController.navigate( Accueil(quiz.userIndex) ) }, + navFavorite = { navController.navigate(Favorite(quiz.userIndex)) }, + navProfil = { navController.navigate(Profil(quiz.userIndex)) }, + navQuiz = { navController.navigate(QuizMenu(quiz.userIndex)) }, navControllerQuizEnd = { idQuiz, pts -> - navController.navigate(Destination.QuizEnd.createIdAndPts(idQuiz, pts)) + navController.navigate(QuizEnd(quiz.userIndex,idQuiz, pts)) }, - navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) }, - navControllerMenu = { navController.navigate(Destination.Accueil.route) }, - idQuiz + idQuiz = quiz.idQuiz ) } - composable(Destination.QuizEnd.route) { backStackEntry -> - val idQuiz = backStackEntry.arguments?.getString("idQuiz")?.toInt() ?: 0 - val pts = backStackEntry.arguments?.getString("pts")?.toInt() ?: 0 + composable { + val quizEnd: QuizEnd = it.toRoute() QuizEndPage( - idQuiz, - pts, - navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) }, - navControllerMenu = { navController.navigate(Destination.Accueil.route) } + idQuiz = quizEnd.idQuiz, + points = quizEnd.pts, + index = quizEnd.userIndex, + navAccueil = { navController.navigate( Accueil(quizEnd.userIndex) ) }, + navFavorite = { navController.navigate(Favorite(quizEnd.userIndex)) }, + navProfil = { navController.navigate(Profil(quizEnd.userIndex)) }, + navQuiz = { navController.navigate(QuizMenu(quizEnd.userIndex)) } ) } } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt index 69fb7a4..6578b17 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt @@ -26,6 +26,7 @@ import androidx.compose.ui.unit.sp import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.QuestionStub import com.example.what_the_fantasy.data.local.QuizStub +import com.example.what_the_fantasy.ui.components.NavBar val gradient = Brush.linearGradient( colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)), @@ -37,132 +38,107 @@ val gradient = Brush.linearGradient( fun QuizEndPage( idQuiz: Int, points: Int, - navControllerQuizMenu: () -> Unit, - navControllerMenu: () -> Unit + index: Int, + navFavorite: (Int) -> Unit, + navAccueil: (Int) -> Unit, + navProfil:(Int) -> Unit, + navQuiz: (Int) -> Unit, ) { - Column( - modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B)) - ) { - // Bandeau supérieur - Row( - modifier = Modifier - .fillMaxWidth() - .weight(0.1f) - .padding(20.dp), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - Image( - painter = painterResource(id = R.drawable.profile_icon), - contentDescription = "Profil", - modifier = Modifier.size(50.dp) - ) - Image( - painter = painterResource(id = R.drawable.toggle), - contentDescription = "Profil" - ) - } - - // Contenu principal + NavBar(onQuiz = true, + index = index, + navControllerFavorite = navFavorite, + navControllerAccueil = navAccueil, + navControllerProfil = navProfil, + navControllerQuiz = navQuiz) { Column( - modifier = Modifier - .weight(0.8f) - .padding(horizontal = 50.dp, vertical = 20.dp) - .fillMaxWidth(), - horizontalAlignment = Alignment.CenterHorizontally + modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B)) ) { - Text( - text = "▶ Résultats ◀", - color = Color.White, - style = TextStyle(fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center) - ) - Spacer(modifier = Modifier.height(16.dp)) - Column ( + + // Contenu principal + Column( modifier = Modifier - .background(brush = gradient, shape = RoundedCornerShape(20.dp)) - .padding(30.dp) - .fillMaxSize(), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.SpaceEvenly + .weight(0.8f) + .padding(horizontal = 50.dp, vertical = 20.dp) + .fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally ) { - val quiz = QuizStub.getQuizById(idQuiz) - val nbQuestions = quiz?.questions?.size - Text ( - text = "${quiz?.name}", + Text( + text = "▶ Résultats ◀", color = Color.White, - style = TextStyle(fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center) - ) - Text ( - text = "Nombres de Questions : $nbQuestions", - color = Color.White, - style = TextStyle(fontSize = 15.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center) - ) - Text ( - text = "Nombres de bonnes réponses : $points", - color = Color.White, - style = TextStyle(fontSize = 15.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center) + style = TextStyle( + fontSize = 25.sp, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center + ) ) - - val pourcentage = (points.toDouble() / nbQuestions!!) * 100 - - val note = when { - pourcentage == 100.0 -> "S" - pourcentage >= 70.0 -> "A" - pourcentage >= 40.0 -> "B" - else -> "C" - } - - println("Note obtenue : $note") - - Box( - contentAlignment = Alignment.Center, + Spacer(modifier = Modifier.height(16.dp)) + Column( modifier = Modifier - .size(100.dp) - .background(Color.White, shape = RoundedCornerShape(50.dp)) + .background(brush = gradient, shape = RoundedCornerShape(20.dp)) + .padding(30.dp) + .fillMaxSize(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.SpaceEvenly ) { + val quiz = QuizStub.getQuizById(idQuiz) + val nbQuestions = quiz?.questions?.size Text( - text = note, - color = Color.Red, + text = "${quiz?.name}", + color = Color.White, style = TextStyle( - fontSize = 40.sp, + fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center ) ) + Text( + text = "Nombres de Questions : $nbQuestions", + color = Color.White, + style = TextStyle( + fontSize = 15.sp, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center + ) + ) + Text( + text = "Nombres de bonnes réponses : $points", + color = Color.White, + style = TextStyle( + fontSize = 15.sp, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center + ) + ) + + val pourcentage = (points.toDouble() / nbQuestions!!) * 100 + + val note = when { + pourcentage == 100.0 -> "S" + pourcentage >= 70.0 -> "A" + pourcentage >= 40.0 -> "B" + else -> "C" + } + + println("Note obtenue : $note") + + Box( + contentAlignment = Alignment.Center, + modifier = Modifier + .size(100.dp) + .background(Color.White, shape = RoundedCornerShape(50.dp)) + ) { + Text( + text = note, + color = Color.Red, + style = TextStyle( + fontSize = 40.sp, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center + ) + ) + } } } } - - // Bandeau inférieur - Row( - modifier = Modifier - .fillMaxWidth() - .weight(0.1f) - .background(Color(0xFF300052)) - .padding(20.dp), - horizontalArrangement = Arrangement.SpaceAround, - verticalAlignment = Alignment.CenterVertically - ) { - // Bouton Likes - Image( - painter = painterResource(id = R.drawable.like_icon), - contentDescription = "Bouton", - modifier = Modifier.size(50.dp) - ) - // Bouton WhatTheFantasy - Image( - painter = painterResource(R.drawable.wf_logo), - contentDescription = "Menu Button", - Modifier.clickable { navControllerMenu() } - ) - // Bouton Menu Quiz - Image( - painter = painterResource(id = R.drawable.quiz_icon), - contentDescription = "Bouton", - modifier = Modifier - .size(50.dp) - .clickable { navControllerQuizMenu() } - ) - } } } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt index 4625a8c..99c50af 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt @@ -41,123 +41,92 @@ import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun QuizMenu(navControllerQuiz: (Int) -> Unit) { - - Column ( - modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B)) +fun QuizMenu( index: Int, + navFavorite: (Int) -> Unit, + navAccueil: (Int) -> Unit, + navProfil:(Int) -> Unit, + navControllerQuiz: (Int) -> Unit +) { + NavBar(onQuiz = true, + index = index, + navControllerFavorite = navFavorite, + navControllerAccueil = navAccueil, + navControllerProfil = navProfil, + navControllerQuiz = { } ) { - // Bandeau supérieur - Row( - modifier = Modifier - .fillMaxWidth() - .weight(0.1f) - //background(Color(0xFF300052)) - .padding(20.dp), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - Image( - painter = painterResource(id = R.drawable.profile_icon), - contentDescription = "Profil" - ) - Image( - painter = painterResource(id = R.drawable.toggle), - contentDescription = "Profil" - ) - } - // Contenu princiapl Column( - modifier = Modifier - .weight(0.9f) - .fillMaxSize() - .padding(20.dp), - horizontalAlignment = Alignment.CenterHorizontally + modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B)) ) { - Text( - text = "▶ Menu des Quiz ◀", - color = Color.White, - style = TextStyle(fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center) - ) - Spacer(Modifier.height(20.dp)) - Column ( + // Contenu princiapl + Column( modifier = Modifier - .background(brush = gradient, shape = RoundedCornerShape(20.dp)) + .weight(0.9f) .fillMaxSize() - .padding(vertical = 30.dp) - .verticalScroll(rememberScrollState()), + .padding(20.dp), horizontalAlignment = Alignment.CenterHorizontally ) { - val quizzes = QuizStub.allQuizzes.chunked(2) - val context = LocalContext.current - for (rowQuizzes in quizzes) { - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceEvenly - ) { - for (quiz in rowQuizzes) { - val imageResId = context.resources.getIdentifier( - quiz.img, - "drawable", - context.packageName - ) - Column ( - modifier = Modifier - .size(width = 150.dp, height = 145.dp) - .clickable { navControllerQuiz(quiz.id) }, - ) { - Image( - painter = painterResource(id = imageResId), - contentDescription = quiz.name, - modifier = Modifier - .size(width = 150.dp, height = 100.dp) - .clip(shape = RoundedCornerShape(20.dp)), - contentScale = ContentScale.Crop + Text( + text = "▶ Menu des Quiz ◀", + color = Color.White, + style = TextStyle( + fontSize = 25.sp, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center + ) + ) + Spacer(Modifier.height(20.dp)) + Column( + modifier = Modifier + .background(brush = gradient, shape = RoundedCornerShape(20.dp)) + .fillMaxSize() + .padding(vertical = 30.dp) + .verticalScroll(rememberScrollState()), + horizontalAlignment = Alignment.CenterHorizontally + ) { + val quizzes = QuizStub.allQuizzes.chunked(2) + val context = LocalContext.current + for (rowQuizzes in quizzes) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceEvenly + ) { + for (quiz in rowQuizzes) { + val imageResId = context.resources.getIdentifier( + quiz.img, + "drawable", + context.packageName ) - Spacer(Modifier.height(10.dp)) - Text( - text = quiz.name, - style = TextStyle( - fontSize = 17.sp, - fontWeight = FontWeight.Medium, - textAlign = TextAlign.Center, - color = Color.White + Column( + modifier = Modifier + .size(width = 150.dp, height = 145.dp) + .clickable { navControllerQuiz(quiz.id) }, + ) { + Image( + painter = painterResource(id = imageResId), + contentDescription = quiz.name, + modifier = Modifier + .size(width = 150.dp, height = 100.dp) + .clip(shape = RoundedCornerShape(20.dp)), + contentScale = ContentScale.Crop ) - ) + Spacer(Modifier.height(10.dp)) + Text( + text = quiz.name, + style = TextStyle( + fontSize = 17.sp, + fontWeight = FontWeight.Medium, + textAlign = TextAlign.Center, + color = Color.White + ) + ) + } } } + Spacer(Modifier.height(30.dp)) } - Spacer(Modifier.height(30.dp)) } } } - - // Bandeau inférieur - Row( - modifier = Modifier - .fillMaxWidth() - .weight(0.1f) - .background(Color(0xFF300052)) - .padding(20.dp), - horizontalArrangement = Arrangement.SpaceAround, - verticalAlignment = Alignment.CenterVertically - ) { - // Bouton Likes - Image( - painter = painterResource(id = R.drawable.like_icon), - contentDescription = "Bouton" - ) - // Bouton WhatTheFantasy - Image( - painter = painterResource(R.drawable.wf_logo), - contentDescription = "Menu Button", - Modifier.clickable { } - ) - // Bouton Quiz - Image( - painter = painterResource(id = R.drawable.quiz_icon), - contentDescription = "Bouton" - ) - } } } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizPage.kt index 68cae66..e20a5f2 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizPage.kt @@ -22,12 +22,19 @@ import androidx.compose.ui.unit.sp import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.QuestionStub import com.example.what_the_fantasy.data.local.QuizStub +import com.example.what_the_fantasy.ui.components.BackBar +import com.example.what_the_fantasy.ui.components.NavBar @Composable fun QuizPage( + index: Int, + navFavorite: (Int) -> Unit, + navAccueil: (Int) -> Unit, + navProfil:(Int) -> Unit, + navQuiz: (Int) -> Unit, + navControllerQuizEnd: (Int, Int) -> Unit, - navControllerQuizMenu: () -> Unit, - navControllerMenu: () -> Unit, + idQuiz: Int ) { val quiz = QuizStub.getQuizById(idQuiz) @@ -54,128 +61,90 @@ fun QuizPage( if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++ else navControllerQuizEnd(idQuiz, pts) // Retour menu } - - Column ( + NavBar(onQuiz = true, + index = index, + navControllerFavorite = navFavorite, + navControllerAccueil = navAccueil, + navControllerProfil = navProfil, + navControllerQuiz = navQuiz + ){ + Column ( modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B)) ) { - // Bandeau supérieur - Row( - modifier = Modifier - .fillMaxWidth() - .weight(0.1f) - //.background(Color(0xFF300052)) - .padding(20.dp), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - Image( - painter = painterResource(id = R.drawable.profile_icon), - contentDescription = "Profil" - ) - Image( - painter = painterResource(id = R.drawable.toggle), - contentDescription = "Profil" - ) - } - - // Contenu princiapl - Column( - modifier = Modifier - .weight(0.8f) - .fillMaxWidth() - .padding(horizontal = 50.dp, vertical = 20.dp), - horizontalAlignment = Alignment.CenterHorizontally - ) { - val question = questions[idCurrentQuestion] - + // Contenu princiapl Column( - horizontalAlignment = Alignment.CenterHorizontally, + modifier = Modifier + .weight(0.8f) + .fillMaxWidth() + .padding(horizontal = 50.dp, vertical = 20.dp), + horizontalAlignment = Alignment.CenterHorizontally ) { - if (quiz != null) { - Text( - text = "▶ ${quiz.name} ◀", - color = Color.White, - style = TextStyle(fontSize = 20.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center) - ) - } - Spacer(Modifier.height(20.dp)) - Column ( - modifier = Modifier - .background(brush = gradient, shape = RoundedCornerShape(20.dp)), - horizontalAlignment = Alignment.CenterHorizontally + val question = questions[idCurrentQuestion] + + Column( + horizontalAlignment = Alignment.CenterHorizontally, ) { - Text( - "Question ${idCurrentQuestion+1}", - color = Color.White, - fontSize = 18.sp, - modifier = Modifier.padding(top = 20.dp), - style = TextStyle( - fontSize = 25.sp, - fontWeight = FontWeight.Bold, - textAlign = TextAlign.Center + if (quiz != null) { + Text( + text = "▶ ${quiz.name} ◀", + color = Color.White, + style = TextStyle( + fontSize = 20.sp, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center + ) ) - ) - Text( - question.question, - color = Color.White, - fontSize = 22.sp, - modifier = Modifier.padding(40.dp) - ) + } + Spacer(Modifier.height(20.dp)) Column( modifier = Modifier - .padding(top = 30.dp) + .background(brush = gradient, shape = RoundedCornerShape(20.dp)), + horizontalAlignment = Alignment.CenterHorizontally ) { - listOf( - question.ansA, - question.ansB, - question.ansC, - question.ansD - ).forEach { answer -> - Box( - modifier = Modifier - .width(220.dp) - .height(50.dp) - .background(Color.White, shape = RoundedCornerShape(16.dp)) - .clickable { onAnswerSelected(answer) } - .padding(horizontal = 8.dp), - contentAlignment = Alignment.Center - ) { - Text(answer, color = Color.Black, fontSize = 18.sp) + Text( + "Question ${idCurrentQuestion + 1}", + color = Color.White, + fontSize = 18.sp, + modifier = Modifier.padding(top = 20.dp), + style = TextStyle( + fontSize = 25.sp, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center + ) + ) + Text( + question.question, + color = Color.White, + fontSize = 22.sp, + modifier = Modifier.padding(40.dp) + ) + Column( + modifier = Modifier + .padding(top = 30.dp) + ) { + listOf( + question.ansA, + question.ansB, + question.ansC, + question.ansD + ).forEach { answer -> + Box( + modifier = Modifier + .width(220.dp) + .height(50.dp) + .background(Color.White, shape = RoundedCornerShape(16.dp)) + .clickable { onAnswerSelected(answer) } + .padding(horizontal = 8.dp), + contentAlignment = Alignment.Center + ) { + Text(answer, color = Color.Black, fontSize = 18.sp) + } + Spacer(modifier = Modifier.height(60.dp)) } - Spacer(modifier = Modifier.height(60.dp)) } } } } } - - // Bandeau inférieur - Row( - modifier = Modifier - .fillMaxWidth() - .weight(0.1f) - .background(Color(0xFF300052)) - .padding(20.dp), - horizontalArrangement = Arrangement.SpaceAround, - verticalAlignment = Alignment.CenterVertically - ) { - // Bouton Likes - Image( - painter = painterResource(id = R.drawable.like_icon), - contentDescription = "Bouton" - ) - // Bouton WhatTheFantasy - Image( - painter = painterResource(R.drawable.wf_logo), - contentDescription = "Menu Button", - Modifier.clickable { navControllerMenu() } - ) - // Bouton Menu Quiz - Image( - painter = painterResource(id = R.drawable.quiz_icon), - contentDescription = "Bouton", - Modifier.clickable { navControllerQuizMenu() } - ) - } } } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/theme/Color.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/theme/Color.kt index dcced89..d8343f5 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/theme/Color.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/theme/Color.kt @@ -19,5 +19,8 @@ val gradienBox = Brush.linearGradient( end = Offset(1000f, 0f) // Fin en haut à droite ) val colorBackground = Color(0xFF100C1B) -val colorNavBar = Color(0xFF2F0E62) -val colorButtonNav = Color.Cyan \ No newline at end of file + +val colorNavBar = Color.Black + +val colorButtonNavSelected= Color(0xFFC8C8C8) +val colorButtonNav = Color.White \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/res/drawable/dark_mode_toggle_icon.xml b/What_The_Fantasy/app/src/main/res/drawable/dark_mode_toggle_icon.xml new file mode 100644 index 0000000..752f388 --- /dev/null +++ b/What_The_Fantasy/app/src/main/res/drawable/dark_mode_toggle_icon.xml @@ -0,0 +1,9 @@ + + + diff --git a/What_The_Fantasy/app/src/main/res/drawable/favorite_button_empty.xml b/What_The_Fantasy/app/src/main/res/drawable/favorite_button_empty.xml new file mode 100644 index 0000000..33a5dda --- /dev/null +++ b/What_The_Fantasy/app/src/main/res/drawable/favorite_button_empty.xml @@ -0,0 +1,12 @@ + + + diff --git a/What_The_Fantasy/app/src/main/res/drawable/favorite_button_full.xml b/What_The_Fantasy/app/src/main/res/drawable/favorite_button_full.xml new file mode 100644 index 0000000..3443b39 --- /dev/null +++ b/What_The_Fantasy/app/src/main/res/drawable/favorite_button_full.xml @@ -0,0 +1,10 @@ + + + diff --git a/What_The_Fantasy/app/src/main/res/drawable/home_button_empty.xml b/What_The_Fantasy/app/src/main/res/drawable/home_button_empty.xml new file mode 100644 index 0000000..1eba6f8 --- /dev/null +++ b/What_The_Fantasy/app/src/main/res/drawable/home_button_empty.xml @@ -0,0 +1,23 @@ + + + + + + + + + + diff --git a/What_The_Fantasy/app/src/main/res/drawable/home_button_full.xml b/What_The_Fantasy/app/src/main/res/drawable/home_button_full.xml new file mode 100644 index 0000000..c2959b3 --- /dev/null +++ b/What_The_Fantasy/app/src/main/res/drawable/home_button_full.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/What_The_Fantasy/app/src/main/res/drawable/light_mode_toggle_icon.xml b/What_The_Fantasy/app/src/main/res/drawable/light_mode_toggle_icon.xml new file mode 100644 index 0000000..8e171be --- /dev/null +++ b/What_The_Fantasy/app/src/main/res/drawable/light_mode_toggle_icon.xml @@ -0,0 +1,10 @@ + + + diff --git a/What_The_Fantasy/app/src/main/res/drawable/like_icon.png b/What_The_Fantasy/app/src/main/res/drawable/like_icon.png deleted file mode 100644 index 6d62a6c..0000000 Binary files a/What_The_Fantasy/app/src/main/res/drawable/like_icon.png and /dev/null differ diff --git a/What_The_Fantasy/app/src/main/res/drawable/profile_icon.png b/What_The_Fantasy/app/src/main/res/drawable/profile_icon.png deleted file mode 100644 index 4fe3158..0000000 Binary files a/What_The_Fantasy/app/src/main/res/drawable/profile_icon.png and /dev/null differ diff --git a/What_The_Fantasy/app/src/main/res/drawable/quiz_button_empty.xml b/What_The_Fantasy/app/src/main/res/drawable/quiz_button_empty.xml new file mode 100644 index 0000000..a1e039a --- /dev/null +++ b/What_The_Fantasy/app/src/main/res/drawable/quiz_button_empty.xml @@ -0,0 +1,11 @@ + + + diff --git a/What_The_Fantasy/app/src/main/res/drawable/quiz_button_full.xml b/What_The_Fantasy/app/src/main/res/drawable/quiz_button_full.xml new file mode 100644 index 0000000..dd8a0a4 --- /dev/null +++ b/What_The_Fantasy/app/src/main/res/drawable/quiz_button_full.xml @@ -0,0 +1,9 @@ + + + diff --git a/What_The_Fantasy/app/src/main/res/drawable/quiz_icon.png b/What_The_Fantasy/app/src/main/res/drawable/quiz_icon.png deleted file mode 100644 index a4aca0e..0000000 Binary files a/What_The_Fantasy/app/src/main/res/drawable/quiz_icon.png and /dev/null differ diff --git a/What_The_Fantasy/app/src/main/res/drawable/toggle.png b/What_The_Fantasy/app/src/main/res/drawable/toggle.png deleted file mode 100644 index a21a368..0000000 Binary files a/What_The_Fantasy/app/src/main/res/drawable/toggle.png and /dev/null differ diff --git a/What_The_Fantasy/app/src/main/res/drawable/wf_logo.png b/What_The_Fantasy/app/src/main/res/drawable/wf_logo.png deleted file mode 100644 index 7388be9..0000000 Binary files a/What_The_Fantasy/app/src/main/res/drawable/wf_logo.png and /dev/null differ diff --git a/What_The_Fantasy/gradle/libs.versions.toml b/What_The_Fantasy/gradle/libs.versions.toml index 258393f..2c630fb 100644 --- a/What_The_Fantasy/gradle/libs.versions.toml +++ b/What_The_Fantasy/gradle/libs.versions.toml @@ -38,4 +38,4 @@ androidx-navigation-common-android = { group = "androidx.navigation", name = "na [plugins] android-application = { id = "com.android.application", version.ref = "agp" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } - +kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin"}