From c0301aa604019565accf9c7b973e96247ee439d4 Mon Sep 17 00:00:00 2001 From: brongniart Date: Thu, 20 Feb 2025 12:00:04 +0100 Subject: [PATCH 1/7] =?UTF-8?q?cr=C3=A9ation=20navbar=20a=20finir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../what_the_fantasy/ui/components/NavBar.kt | 30 ++++++++++++++++++- .../what_the_fantasy/ui/screens/LoginPage.kt | 3 ++ .../what_the_fantasy/ui/theme/Color.kt | 4 ++- 3 files changed, 35 insertions(+), 2 deletions(-) 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 dedbd00..14dba5f 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,4 +1,32 @@ package com.example.what_the_fantasy.ui.components -class NavBar { +import android.widget.ImageView +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.FlowRow + +import androidx.compose.foundation.layout.Row +import androidx.compose.material3.BottomAppBar +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import com.example.what_the_fantasy.R +import com.example.what_the_fantasy.ui.theme.colorNavBar + + +@Composable +fun NavBar(actualPage :String) { + FlowRow(modifier = Modifier + .background(colorNavBar), + Arrangement.SpaceAround + ){ + Text("Favorie") + Image( painter = painterResource(R.mipmap.ic_launcher_foreground), contentDescription = "Accueil") + Text("Quiz") + + } + } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt index f6e1023..86c06ff 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt @@ -38,6 +38,7 @@ import androidx.navigation.compose.composable import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.UserStub import com.example.what_the_fantasy.data.model.User +import com.example.what_the_fantasy.ui.components.NavBar import com.example.what_the_fantasy.ui.components.SpaceHeightComponent import com.example.what_the_fantasy.ui.components.TitlePageComponent import com.example.what_the_fantasy.ui.theme.colorBackground @@ -56,6 +57,7 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: () -> Unit) .background(colorBackground), contentAlignment = Alignment.Center ){ + Column( modifier = Modifier .fillMaxWidth(0.9f) @@ -74,6 +76,7 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: () -> Unit) SpaceHeightComponent(16) CreateAccountButton(R.string.ButtonCreateLogin,12, Color.White, navControllerSignUp) } + NavBar("") } } 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 41c8deb..64ce917 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 @@ -16,4 +16,6 @@ val gradienBox = Brush.linearGradient( start = Offset(0f, 1000f), // Départ en bas à gauche end = Offset(1000f, 0f) // Fin en haut à droite ) -val colorBackground = Color(0xFF100C1B) \ No newline at end of file +val colorBackground = Color(0xFF100C1B) + +val colorNavBar = Color(0xFF2F0E62) \ No newline at end of file From 0224bbf149b51b8b2dca6a213f47489ecd25830f Mon Sep 17 00:00:00 2001 From: brongniart Date: Thu, 20 Feb 2025 15:53:25 +0100 Subject: [PATCH 2/7] =?UTF-8?q?NavBar=20inf=C3=A9rieur=20et=20sup=C3=A9rie?= =?UTF-8?q?ur=20faite=20style=20bouton=20a=20corig=C3=A9=20&=20mettre=20la?= =?UTF-8?q?=20nav=20dans=20les=20onclick?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../what_the_fantasy/ui/components/NavBar.kt | 81 +++++++++++-- .../ui/screens/AccueilPage.kt | 7 +- .../ui/screens/FavoritePage.kt | 7 +- .../what_the_fantasy/ui/screens/LoginPage.kt | 4 +- .../what_the_fantasy/ui/screens/ProfilPage.kt | 78 ++++++------- .../what_the_fantasy/ui/screens/QuizPage.kt | 106 +++++++++--------- .../what_the_fantasy/ui/screens/QuotePage.kt | 7 +- .../what_the_fantasy/ui/screens/SearchPage.kt | 7 +- .../ui/screens/SubmitQuotePage.kt | 7 +- 9 files changed, 198 insertions(+), 106 deletions(-) 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 14dba5f..a922a8e 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 @@ -4,29 +4,92 @@ import android.widget.ImageView import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.FlowRow +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.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.BottomAppBar +import androidx.compose.material3.Button import androidx.compose.material3.Text import androidx.compose.runtime.Composable 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.layout.onGloballyPositioned import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.TextUnit +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.ui.navigations.AppNavigator import com.example.what_the_fantasy.ui.theme.colorNavBar @Composable -fun NavBar(actualPage :String) { - FlowRow(modifier = Modifier - .background(colorNavBar), - Arrangement.SpaceAround - ){ - Text("Favorie") - Image( painter = painterResource(R.mipmap.ic_launcher_foreground), contentDescription = "Accueil") - Text("Quiz") +fun NavBar(content : @Composable ()-> Unit ) { + val nav = AppNavigator() + + Column( + modifier = Modifier + .fillMaxSize() + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .height(55.dp) + .background(colorNavBar) + .padding(10.dp), + Arrangement.SpaceBetween, + verticalAlignment = Alignment.Bottom + ) { + Button(onClick = {}, Modifier.background(Color.Unspecified)) { + Text("Profile", fontSize = 25.sp, color = Color.White) + } + Button(onClick = {}) { + Text("Theme", fontSize = 25.sp, color = Color.White) + } + + } + + Box(modifier = Modifier.background(Color.Black).fillMaxHeight(0.92f)){ + content() + } + + Row(modifier = Modifier + .background(colorNavBar) + .fillMaxSize(), + horizontalArrangement = Arrangement.SpaceAround, + verticalAlignment = Alignment.CenterVertically + ) { + + Button(onClick = {}) { + Text("Favorie", fontSize = 25.sp, color = Color.White) + } + + Button(onClick = {}) { + Image( + painter = painterResource(R.mipmap.ic_launcher_foreground), + contentDescription = "Accueil", + modifier = Modifier + .size(100.dp) + ) + } + + Button(onClick = {}) { + Text("Quiz", fontSize = 25.sp, color = Color.White) + } } + + } } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt index 8fd4c97..4f5b249 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt @@ -1,6 +1,11 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.runtime.Composable +import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun AccueilPage() {} \ No newline at end of file +fun AccueilPage() { + NavBar { + + } +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt index 72c2e72..8945f9e 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt @@ -1,6 +1,11 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.runtime.Composable +import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun FavoritePage() {} \ No newline at end of file +fun FavoritePage() { + NavBar { + + } +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt index 86c06ff..ab97777 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt @@ -50,7 +50,6 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: () -> Unit) val users = UserStub.allUsers; - Box( modifier = Modifier .fillMaxSize() @@ -76,8 +75,9 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: () -> Unit) SpaceHeightComponent(16) CreateAccountButton(R.string.ButtonCreateLogin,12, Color.White, navControllerSignUp) } - NavBar("") + } + } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt index cdfbec9..e9ab71f 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt @@ -62,6 +62,7 @@ import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.QuestionStub import com.example.what_the_fantasy.data.local.UserStub import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent +import com.example.what_the_fantasy.ui.components.NavBar import com.example.what_the_fantasy.ui.components.SpaceHeightComponent import com.example.what_the_fantasy.ui.components.TitlePageComponent import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme @@ -75,47 +76,48 @@ fun ProfilPage(navController: NavController) { ) val user = UserStub.allUsers val index = 2 // Pour changer l'utilisateur pour le moment - - Box( - modifier = Modifier - .fillMaxSize() - .background(Color(0xFF100C1B)), - contentAlignment = Alignment.Center - ) { - Column( + NavBar { + Box( modifier = Modifier - .fillMaxWidth(0.9f) - .padding(20.dp) - .clip(RoundedCornerShape(16.dp)) - .background(gradient) - .padding(20.dp), - horizontalAlignment = Alignment.CenterHorizontally + .fillMaxSize() + .background(Color(0xFF100C1B)), + contentAlignment = Alignment.Center ) { + Column( + modifier = Modifier + .fillMaxWidth(0.9f) + .padding(20.dp) + .clip(RoundedCornerShape(16.dp)) + .background(gradient) + .padding(20.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + + // Titre + TitlePageComponent(R.string.titleProfile, 20, Color.White) + SpaceHeightComponent(16) + + // Image de profil + ImageProfil(user[index].imgUrl, 120, 2, Color.White) + SpaceHeightComponent(16) + + EditUsername(user[index].username)// Édition du Username + SpaceHeightComponent(16) + + EditEmail(user[index].email)// Édition du Email + Spacer(modifier = Modifier.height(8.dp)) + + EditPasswd() + SpaceHeightComponent(16) + + // Bouton + ButtonProfile(R.string.ButtonAddQuoteprofile, 18, Color.Black, Color.White) + SpaceHeightComponent(16) + ButtonProfile(R.string.ButtonLanguageprofile, 18, Color.Black, Color.White) + SpaceHeightComponent(16) + ButtonProfile(R.string.ButtonUnlogprofile, 18, Color.Black, Color.White) - // Titre - TitlePageComponent(R.string.titleProfile, 20, Color.White) - SpaceHeightComponent(16) - - // Image de profil - ImageProfil(user[index].imgUrl, 120, 2, Color.White) - SpaceHeightComponent(16) - - EditUsername(user[index].username)// Édition du Username - SpaceHeightComponent(16) - - EditEmail(user[index].email)// Édition du Email - Spacer(modifier = Modifier.height(8.dp)) - - EditPasswd() - SpaceHeightComponent(16) - - // Bouton - ButtonProfile(R.string.ButtonAddQuoteprofile,18, Color.Black, Color.White) - SpaceHeightComponent(16) - ButtonProfile(R.string.ButtonLanguageprofile,18, Color.Black, Color.White) - SpaceHeightComponent(16) - ButtonProfile(R.string.ButtonUnlogprofile, 18, Color.Black, Color.White) - + } } } } 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 a342a02..0405ae3 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 @@ -27,6 +27,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.what_the_fantasy.data.local.QuestionStub import com.example.what_the_fantasy.data.model.Question +import com.example.what_the_fantasy.ui.components.NavBar @Composable fun QuizPage() { @@ -37,68 +38,69 @@ fun QuizPage() { ) val questions = QuestionStub.allQuestions - - Box( - modifier = Modifier - .fillMaxSize() - .background(Color(0xFF100C1B)) // Fond global de l'écran - .padding(16.dp) // Marges autour de tout le contenu - ) { - // Numéro de la question en haut - Text( - text = "Question numéro : " + questions.first().id.toString(), - color = Color.White, - fontSize = 18.sp, // Taille réduite pour tenir sur un écran portrait - modifier = Modifier - .align(Alignment.TopCenter) // Position en haut au centre - .padding(top = 16.dp) // Un peu d'espace en haut - ) - - // Contenu centré, mais avec une gestion plus équilibrée du placement - Column( + NavBar { + Box( modifier = Modifier .fillMaxSize() - .padding(top = 48.dp), // Réduit l'espace entre le numéro de la question et la question elle-même - verticalArrangement = Arrangement.Center, // Centre verticalement - horizontalAlignment = Alignment.CenterHorizontally // Centre horizontalement + .background(Color(0xFF100C1B)) // Fond global de l'écran + .padding(16.dp) // Marges autour de tout le contenu ) { - // Question principale + // Numéro de la question en haut Text( - text = questions.first().question, + text = "Question numéro : " + questions.first().id.toString(), color = Color.White, - fontSize = 22.sp, // Taille plus petite pour tenir sur un écran portrait - modifier = Modifier.padding(bottom = 16.dp) // Réduit l'espacement entre la question et les réponses + fontSize = 18.sp, // Taille réduite pour tenir sur un écran portrait + modifier = Modifier + .align(Alignment.TopCenter) // Position en haut au centre + .padding(top = 16.dp) // Un peu d'espace en haut ) - // Liste des réponses - val answers = listOf( - questions.first().ansA, - questions.first().ansB, - questions.first().ansC, - questions.first().ansD - ) + // Contenu centré, mais avec une gestion plus équilibrée du placement + Column( + modifier = Modifier + .fillMaxSize() + .padding(top = 48.dp), // Réduit l'espace entre le numéro de la question et la question elle-même + verticalArrangement = Arrangement.Center, // Centre verticalement + horizontalAlignment = Alignment.CenterHorizontally // Centre horizontalement + ) { + // Question principale + Text( + text = questions.first().question, + color = Color.White, + fontSize = 22.sp, // Taille plus petite pour tenir sur un écran portrait + modifier = Modifier.padding(bottom = 16.dp) // Réduit l'espacement entre la question et les réponses + ) + + // Liste des réponses + val answers = listOf( + questions.first().ansA, + questions.first().ansB, + questions.first().ansC, + questions.first().ansD + ) - // Pour chaque réponse, on applique une Box avec un espacement uniforme - answers.forEach { answer -> - Box( - modifier = Modifier - .width(220.dp) // Largeur plus petite pour que ça tienne mieux - .height(50.dp) // Hauteur ajustée - .background( - brush = gradient, - shape = RoundedCornerShape(16.dp) // Coins arrondis + // Pour chaque réponse, on applique une Box avec un espacement uniforme + answers.forEach { answer -> + Box( + modifier = Modifier + .width(220.dp) // Largeur plus petite pour que ça tienne mieux + .height(50.dp) // Hauteur ajustée + .background( + brush = gradient, + shape = RoundedCornerShape(16.dp) // Coins arrondis + ) + .clickable { /* Action pour la réponse */ } + .padding(horizontal = 8.dp), // Padding interne + contentAlignment = Alignment.Center + ) { + Text( + text = answer, + color = Color.White, + fontSize = 18.sp // Taille du texte ajustée pour un écran portrait ) - .clickable { /* Action pour la réponse */ } - .padding(horizontal = 8.dp), // Padding interne - contentAlignment = Alignment.Center - ) { - Text( - text = answer, - color = Color.White, - fontSize = 18.sp // Taille du texte ajustée pour un écran portrait - ) + } + Spacer(modifier = Modifier.height(16.dp)) // Espacement réduit entre les réponses } - Spacer(modifier = Modifier.height(16.dp)) // Espacement réduit entre les réponses } } } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt index cfb1d2f..a5b82e7 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt @@ -1,6 +1,11 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.runtime.Composable +import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun QuotePage() {} \ No newline at end of file +fun QuotePage() { + NavBar { + + } +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt index 9b8d6ac..be429f8 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt @@ -1,6 +1,11 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.runtime.Composable +import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun SearchPage() {} \ No newline at end of file +fun SearchPage() { + NavBar { + + } +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt index 0b88b35..42913ae 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt @@ -1,6 +1,11 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.runtime.Composable +import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun SubmitQuotePage() {} \ No newline at end of file +fun SubmitQuotePage() { + NavBar { + + } +} \ No newline at end of file From be33806593be3ce9d7f038f58b00d8843e5c7c07 Mon Sep 17 00:00:00 2001 From: brongniart Date: Thu, 20 Feb 2025 12:00:04 +0100 Subject: [PATCH 3/7] =?UTF-8?q?cr=C3=A9ation=20navbar=20a=20finir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../what_the_fantasy/ui/components/NavBar.kt | 30 ++++++++++++++++++- .../what_the_fantasy/ui/screens/LoginPage.kt | 3 ++ .../what_the_fantasy/ui/theme/Color.kt | 4 ++- 3 files changed, 35 insertions(+), 2 deletions(-) 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 dedbd00..14dba5f 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,4 +1,32 @@ package com.example.what_the_fantasy.ui.components -class NavBar { +import android.widget.ImageView +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.FlowRow + +import androidx.compose.foundation.layout.Row +import androidx.compose.material3.BottomAppBar +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import com.example.what_the_fantasy.R +import com.example.what_the_fantasy.ui.theme.colorNavBar + + +@Composable +fun NavBar(actualPage :String) { + FlowRow(modifier = Modifier + .background(colorNavBar), + Arrangement.SpaceAround + ){ + Text("Favorie") + Image( painter = painterResource(R.mipmap.ic_launcher_foreground), contentDescription = "Accueil") + Text("Quiz") + + } + } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt index 47309cc..c84383c 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt @@ -39,6 +39,7 @@ import androidx.navigation.compose.composable import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.UserStub import com.example.what_the_fantasy.data.model.User +import com.example.what_the_fantasy.ui.components.NavBar import com.example.what_the_fantasy.ui.components.SpaceHeightComponent import com.example.what_the_fantasy.ui.components.TitlePageComponent import com.example.what_the_fantasy.ui.theme.colorBackground @@ -57,6 +58,7 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni .background(colorBackground), contentAlignment = Alignment.Center ){ + Column( modifier = Modifier .fillMaxWidth(0.9f) @@ -75,6 +77,7 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni SpaceHeightComponent(16) CreateAccountButton(R.string.ButtonCreateLogin,12, Color.White, navControllerSignUp) } + NavBar("") } } 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 41c8deb..64ce917 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 @@ -16,4 +16,6 @@ val gradienBox = Brush.linearGradient( start = Offset(0f, 1000f), // Départ en bas à gauche end = Offset(1000f, 0f) // Fin en haut à droite ) -val colorBackground = Color(0xFF100C1B) \ No newline at end of file +val colorBackground = Color(0xFF100C1B) + +val colorNavBar = Color(0xFF2F0E62) \ No newline at end of file From a36665b102dc44c772514bc35312b8f90c87f6ff Mon Sep 17 00:00:00 2001 From: brongniart Date: Thu, 20 Feb 2025 15:53:25 +0100 Subject: [PATCH 4/7] =?UTF-8?q?NavBar=20inf=C3=A9rieur=20et=20sup=C3=A9rie?= =?UTF-8?q?ur=20faite=20style=20bouton=20a=20corig=C3=A9=20&=20mettre=20la?= =?UTF-8?q?=20nav=20dans=20les=20onclick?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../what_the_fantasy/ui/components/NavBar.kt | 81 ++++++++++++++++--- .../ui/screens/AccueilPage.kt | 7 +- .../ui/screens/FavoritePage.kt | 7 +- .../what_the_fantasy/ui/screens/LoginPage.kt | 4 +- .../what_the_fantasy/ui/screens/ProfilPage.kt | 1 + .../what_the_fantasy/ui/screens/QuizPage.kt | 2 + .../what_the_fantasy/ui/screens/QuotePage.kt | 7 +- .../what_the_fantasy/ui/screens/SearchPage.kt | 7 +- .../ui/screens/SubmitQuotePage.kt | 7 +- 9 files changed, 107 insertions(+), 16 deletions(-) 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 14dba5f..a922a8e 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 @@ -4,29 +4,92 @@ import android.widget.ImageView import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.FlowRow +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.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.BottomAppBar +import androidx.compose.material3.Button import androidx.compose.material3.Text import androidx.compose.runtime.Composable 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.layout.onGloballyPositioned import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.TextUnit +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.ui.navigations.AppNavigator import com.example.what_the_fantasy.ui.theme.colorNavBar @Composable -fun NavBar(actualPage :String) { - FlowRow(modifier = Modifier - .background(colorNavBar), - Arrangement.SpaceAround - ){ - Text("Favorie") - Image( painter = painterResource(R.mipmap.ic_launcher_foreground), contentDescription = "Accueil") - Text("Quiz") +fun NavBar(content : @Composable ()-> Unit ) { + val nav = AppNavigator() + + Column( + modifier = Modifier + .fillMaxSize() + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .height(55.dp) + .background(colorNavBar) + .padding(10.dp), + Arrangement.SpaceBetween, + verticalAlignment = Alignment.Bottom + ) { + Button(onClick = {}, Modifier.background(Color.Unspecified)) { + Text("Profile", fontSize = 25.sp, color = Color.White) + } + Button(onClick = {}) { + Text("Theme", fontSize = 25.sp, color = Color.White) + } + + } + + Box(modifier = Modifier.background(Color.Black).fillMaxHeight(0.92f)){ + content() + } + + Row(modifier = Modifier + .background(colorNavBar) + .fillMaxSize(), + horizontalArrangement = Arrangement.SpaceAround, + verticalAlignment = Alignment.CenterVertically + ) { + + Button(onClick = {}) { + Text("Favorie", fontSize = 25.sp, color = Color.White) + } + + Button(onClick = {}) { + Image( + painter = painterResource(R.mipmap.ic_launcher_foreground), + contentDescription = "Accueil", + modifier = Modifier + .size(100.dp) + ) + } + + Button(onClick = {}) { + Text("Quiz", fontSize = 25.sp, color = Color.White) + } } + + } } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt index 8fd4c97..4f5b249 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt @@ -1,6 +1,11 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.runtime.Composable +import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun AccueilPage() {} \ No newline at end of file +fun AccueilPage() { + NavBar { + + } +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt index 72c2e72..8945f9e 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt @@ -1,6 +1,11 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.runtime.Composable +import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun FavoritePage() {} \ No newline at end of file +fun FavoritePage() { + NavBar { + + } +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt index c84383c..4dbc28a 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt @@ -51,7 +51,6 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni val users = UserStub.allUsers; - Box( modifier = Modifier .fillMaxSize() @@ -77,8 +76,9 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni SpaceHeightComponent(16) CreateAccountButton(R.string.ButtonCreateLogin,12, Color.White, navControllerSignUp) } - NavBar("") + } + } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt index 98e7838..35fc035 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt @@ -62,6 +62,7 @@ import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.QuestionStub import com.example.what_the_fantasy.data.local.UserStub import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent +import com.example.what_the_fantasy.ui.components.NavBar import com.example.what_the_fantasy.ui.components.SpaceHeightComponent import com.example.what_the_fantasy.ui.components.TitlePageComponent import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme 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 4317669..4897a92 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 @@ -20,6 +20,8 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavController import com.example.what_the_fantasy.data.local.QuestionStub +import com.example.what_the_fantasy.data.model.Question +import com.example.what_the_fantasy.ui.components.NavBar @Composable fun QuizPage(navController: NavController) { diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt index cfb1d2f..a5b82e7 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt @@ -1,6 +1,11 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.runtime.Composable +import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun QuotePage() {} \ No newline at end of file +fun QuotePage() { + NavBar { + + } +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt index 9b8d6ac..be429f8 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt @@ -1,6 +1,11 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.runtime.Composable +import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun SearchPage() {} \ No newline at end of file +fun SearchPage() { + NavBar { + + } +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt index 0b88b35..42913ae 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt @@ -1,6 +1,11 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.runtime.Composable +import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun SubmitQuotePage() {} \ No newline at end of file +fun SubmitQuotePage() { + NavBar { + + } +} \ No newline at end of file From 2c3ea83a4b0dae908e1c82a5ba6f1ec8227a3406 Mon Sep 17 00:00:00 2001 From: Kentin BRONGNIART Date: Tue, 25 Feb 2025 15:38:55 +0100 Subject: [PATCH 5/7] =?UTF-8?q?Navigation=20faite=20sur=20Accueil,Favorite?= =?UTF-8?q?,Quiz=20=20/=20=20A=20finir=20la=20nav=20vers=20Profil=20=20/?= =?UTF-8?q?=20=20Corection=20nav=20dans=20Quiz(supertion=20du=20passage=20?= =?UTF-8?q?en=20param=C3=A9tre=20directement=20du=20nav=20controleur)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../what_the_fantasy/ui/components/NavBar.kt | 121 ++++++++---- .../ui/navigations/AppNavigator.kt | 61 ++++-- .../ui/screens/AccueilPage.kt | 33 +++- .../ui/screens/FavoritePage.kt | 33 +++- .../what_the_fantasy/ui/screens/ProfilPage.kt | 86 +++++---- .../ui/screens/QuizAccueil.kt | 182 +++++++++--------- .../what_the_fantasy/ui/screens/QuizPage.kt | 9 +- .../what_the_fantasy/ui/screens/QuotePage.kt | 3 - .../what_the_fantasy/ui/screens/SearchPage.kt | 3 - .../ui/screens/SubmitQuotePage.kt | 3 - .../what_the_fantasy/ui/theme/Color.kt | 4 +- 11 files changed, 333 insertions(+), 205 deletions(-) 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 a922a8e..fb0ead1 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,7 +1,5 @@ package com.example.what_the_fantasy.ui.components -import android.widget.ImageView -import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -12,31 +10,39 @@ 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.padding import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.BottomAppBar +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.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.IconButtonColors import androidx.compose.material3.Text import androidx.compose.runtime.Composable 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.layout.onGloballyPositioned +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.TextUnit 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.ui.navigations.AppNavigator -import com.example.what_the_fantasy.ui.theme.colorNavBar - +import com.example.what_the_fantasy.ui.theme.* @Composable -fun NavBar(content : @Composable ()-> Unit ) { - val nav = AppNavigator() +fun NavBar(onProfile : Boolean = false , + onFavorite : Boolean = false , + onAccueil : Boolean = false , + onQuiz : Boolean = false , + + navControllerProfil: (Int) -> Unit, + navControllerFavorite: () -> Unit, + navControllerAccueil: () -> Unit, + navControllerQuiz: () -> Unit, + + content : @Composable ()-> Unit ) { Column( modifier = Modifier @@ -45,16 +51,17 @@ fun NavBar(content : @Composable ()-> Unit ) { Row( modifier = Modifier .fillMaxWidth() - .height(55.dp) - .background(colorNavBar) - .padding(10.dp), + .height(70.dp) + .background(colorNavBar), Arrangement.SpaceBetween, verticalAlignment = Alignment.Bottom ) { - Button(onClick = {}, Modifier.background(Color.Unspecified)) { - Text("Profile", fontSize = 25.sp, color = Color.White) - } - Button(onClick = {}) { + ButtonIconVectorInt(Icons.Rounded.AccountCircle,"Profile",{},onProfile) + + + Button(onClick = {}, + colors = ButtonDefaults.buttonColors(containerColor = Color.Transparent) + ) { Text("Theme", fontSize = 25.sp, color = Color.White) } @@ -65,31 +72,67 @@ fun NavBar(content : @Composable ()-> Unit ) { } Row(modifier = Modifier - .background(colorNavBar) - .fillMaxSize(), + .background(colorNavBar) + .fillMaxSize(), horizontalArrangement = Arrangement.SpaceAround, verticalAlignment = Alignment.CenterVertically ) { - Button(onClick = {}) { - Text("Favorie", fontSize = 25.sp, color = Color.White) - } + ButtonIconVector(Icons.Rounded.Favorite,"Favorite",navControllerFavorite,onFavorite) - Button(onClick = {}) { - Image( - painter = painterResource(R.mipmap.ic_launcher_foreground), - contentDescription = "Accueil", - modifier = Modifier - .size(100.dp) - ) - } - - Button(onClick = {}) { - Text("Quiz", fontSize = 25.sp, color = Color.White) - } + ButtonIconPainter(painterResource(R.mipmap.ic_launcher_foreground),"Accueil",navControllerAccueil,onAccueil) + ButtonIconVector(Icons.Rounded.Create,"Quiz",navControllerQuiz,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 ,onPage : Boolean){ + IconButton(onClick = {}, + 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 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) + ) } -} \ No newline at end of file +} 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 d7c38e5..a957940 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 @@ -8,6 +8,8 @@ import com.example.what_the_fantasy.ui.screens.AccueilPage import com.example.what_the_fantasy.ui.screens.FavoritePage import com.example.what_the_fantasy.ui.screens.LoginPage import com.example.what_the_fantasy.ui.screens.ProfilPage +import com.example.what_the_fantasy.ui.screens.QuizAccueil +import com.example.what_the_fantasy.ui.screens.QuizEndPage import com.example.what_the_fantasy.ui.screens.QuizPage import com.example.what_the_fantasy.ui.screens.QuotePage import com.example.what_the_fantasy.ui.screens.SearchPage @@ -23,38 +25,69 @@ sealed class Destination(val route: String) { 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 Quiz : Destination("Quiz") + data object Quote : Destination("Quote") data object Search : Destination("Search") data object SignUp : Destination("SignUp") data object SubmitQuote : Destination("SubmitQuote") + + data object QuizAccueil : Destination("QuizAccueil") + data object QuizPage : Destination("QuizPage") + data object QuizEndPage : Destination("QuizEndPage") } @Composable fun AppNavigator() { val navController = rememberNavController() - NavHost(navController, startDestination = Destination.Login.route) { - composable(Destination.Login.route) { - LoginPage( - navControllerSignUp = { navController.navigate(Destination.SignUp.route) }, - navControllerProfil = { userIndex -> - navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil - } - ) - } - composable(Destination.Accueil.route) { AccueilPage() } - composable(Destination.Favorite.route) { FavoritePage() } + NavHost(navController, startDestination = Destination.Accueil.route) { + composable(Destination.Login.route) { LoginPage( + navControllerSignUp = { navController.navigate(Destination.SignUp.route) }, + navControllerProfil = { userIndex -> + navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil + } + ) } + composable(Destination.Accueil.route) { AccueilPage( + navFavorite = { navController.navigate(Destination.Favorite.route) }, + navQuiz = { navController.navigate(Destination.QuizAccueil.route) } + ) } + composable(Destination.Favorite.route) { FavoritePage( + navAccueil = { navController.navigate(Destination.Accueil.route) }, + navQuiz = { navController.navigate(Destination.QuizAccueil.route) } + ) } composable(Destination.Profil.route) { backStackEntry -> // Récupère l'index passé dans la route val userIndex = backStackEntry.arguments?.getString("userIndex")?.toInt() ?: -1 - ProfilPage(index = userIndex, navController = navController) + ProfilPage(index = userIndex, + navController = navController, + + + ) } - composable(Destination.Quiz.route) { QuizPage(navController) } composable(Destination.Quote.route) { QuotePage() } composable(Destination.Search.route) { SearchPage() } composable(Destination.SignUp.route) { SignUpPage(navController) } composable(Destination.SubmitQuote.route) { SubmitQuotePage() } + + + + composable(Destination.QuizAccueil.route) { QuizAccueil( + navFavorite = { navController.navigate(Destination.Favorite.route) }, + navAccueil = { navController.navigate(Destination.Accueil.route) }, + + navControllerQuizPage = { navController.navigate(Destination.QuizPage.route) }, + navControllerQuizEndPage = { navController.navigate(Destination.QuizEndPage.route) } + ) } + + composable(Destination.QuizPage.route) { QuizPage( + navControllerQuiz = {navController.navigate(Destination.QuizAccueil.route)}, + navControllerQuizEndPage = {navController.navigate(Destination.QuizEndPage.route)} + ) } + composable(Destination.QuizEndPage.route) { QuizEndPage( + points = 5, + idQuiz = 1 + ) } + } } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt index 4f5b249..16fe4f8 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt @@ -1,11 +1,38 @@ package com.example.what_the_fantasy.ui.screens +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.Text 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.unit.sp import com.example.what_the_fantasy.ui.components.NavBar +import com.example.what_the_fantasy.ui.theme.colorBackground @Composable -fun AccueilPage() { - NavBar { - +fun AccueilPage( + navFavorite: () -> Unit, + navQuiz: () -> Unit +) { + NavBar(onAccueil = true, + navControllerFavorite = navFavorite, + navControllerAccueil = { }, + navControllerProfil = {}, + navControllerQuiz = navQuiz + ){ + Box( + modifier = Modifier + .fillMaxSize() + .background(colorBackground), + contentAlignment = Alignment.Center + ){ + Column { + Text("Accueil", color = Color.White, fontSize = 20.sp) + } + } } } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt index 8945f9e..2914701 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt @@ -1,11 +1,38 @@ package com.example.what_the_fantasy.ui.screens +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.Text 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.unit.sp import com.example.what_the_fantasy.ui.components.NavBar +import com.example.what_the_fantasy.ui.theme.colorBackground @Composable -fun FavoritePage() { - NavBar { - +fun FavoritePage( + navAccueil: () -> Unit, + navQuiz: () -> Unit +) { + NavBar(onFavorite = true, + navControllerFavorite = { }, + navControllerAccueil = navAccueil, + navControllerProfil = {}, + navControllerQuiz = navQuiz + ) { + Box( + modifier = Modifier + .fillMaxSize() + .background(colorBackground), + contentAlignment = Alignment.Center + ){ + Column { + Text("Favorite", color = Color.White, fontSize = 20.sp) + } + } } } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt index 35fc035..5937840 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt @@ -70,50 +70,56 @@ import com.example.what_the_fantasy.ui.theme.gradienBox @Composable fun ProfilPage(index: Int, navController: NavController) { - - val userList = UserStub.allUsers - val user = userList[index] - - Box( - modifier = Modifier - .fillMaxSize() - .background(Color(0xFF100C1B)), - contentAlignment = Alignment.Center + NavBar(onProfile = true, + navControllerFavorite = {}, + navControllerAccueil = {}, + navControllerProfil = {}, + navControllerQuiz = {} ) { - Column( + val userList = UserStub.allUsers + val user = userList[index] + + Box( modifier = Modifier - .fillMaxWidth(0.9f) - .padding(20.dp) - .clip(RoundedCornerShape(16.dp)) - .background(gradienBox) - .padding(20.dp), - horizontalAlignment = Alignment.CenterHorizontally + .fillMaxSize() + .background(Color(0xFF100C1B)), + contentAlignment = Alignment.Center ) { + Column( + modifier = Modifier + .fillMaxWidth(0.9f) + .padding(20.dp) + .clip(RoundedCornerShape(16.dp)) + .background(gradienBox) + .padding(20.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + + // Titre + TitlePageComponent(R.string.titleProfile, 20, Color.White) + SpaceHeightComponent(16) + + // Image de profil + ImageProfil(user.imgUrl, 120) + SpaceHeightComponent(16) + + EditUsername(user.username)// Édition du Username + SpaceHeightComponent(16) + + EditEmail(user.email)// Édition du Email + Spacer(modifier = Modifier.height(8.dp)) + + EditPasswd() + SpaceHeightComponent(16) + + // Bouton + ButtonProfile(R.string.ButtonAddQuoteprofile, 18, Color.Black, Color.White) + SpaceHeightComponent(16) + ButtonProfile(R.string.ButtonLanguageprofile, 18, Color.Black, Color.White) + SpaceHeightComponent(16) + ButtonProfile(R.string.ButtonUnlogprofile, 18, Color.Black, Color.White) - // Titre - TitlePageComponent(R.string.titleProfile, 20, Color.White) - SpaceHeightComponent(16) - - // Image de profil - ImageProfil(user.imgUrl, 120) - SpaceHeightComponent(16) - - EditUsername(user.username)// Édition du Username - SpaceHeightComponent(16) - - EditEmail(user.email)// Édition du Email - Spacer(modifier = Modifier.height(8.dp)) - - EditPasswd() - SpaceHeightComponent(16) - - // Bouton - ButtonProfile(R.string.ButtonAddQuoteprofile,18, Color.Black, Color.White) - SpaceHeightComponent(16) - ButtonProfile(R.string.ButtonLanguageprofile,18, Color.Black, Color.White) - SpaceHeightComponent(16) - ButtonProfile(R.string.ButtonUnlogprofile, 18, Color.Black, Color.White) - + } } } } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizAccueil.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizAccueil.kt index b237afd..a5fcaac 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizAccueil.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizAccueil.kt @@ -24,116 +24,112 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import com.example.what_the_fantasy.R +import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun QuizAccueil(navController: NavController) { - Row( - modifier = Modifier - .fillMaxSize() - .background(Color(0xFF100C1B)) - .padding(top = 100.dp) +fun QuizAccueil( + navFavorite: () -> Unit, + navAccueil: () -> Unit, + navControllerQuizPage: () -> Unit, + navControllerQuizEndPage: () -> Unit +) { + NavBar(onQuiz = true, + navControllerFavorite = navFavorite, + navControllerAccueil = navAccueil, + navControllerProfil = {}, + navControllerQuiz = { } ) { - Spacer(modifier = Modifier.weight(0.1f)) - Column( + Row( modifier = Modifier - .weight(0.9f) - .fillMaxHeight(), - horizontalAlignment = Alignment.CenterHorizontally + .fillMaxSize() + .background(Color(0xFF100C1B)) + .padding(top = 100.dp) ) { - Box( - modifier = Modifier - .size(width = 150.dp, height = 100.dp) - .padding(8.dp) - .clickable { - navController.navigate("quizPage") - } - ) { - Image( - painter = painterResource(id = R.drawable.quiz), - contentDescription = "Quiz 1", - modifier = Modifier.fillMaxSize(), - contentScale = ContentScale.Crop - ) - } + Spacer(modifier = Modifier.weight(0.1f)) - Box( + Column( modifier = Modifier - .size(width = 150.dp, height = 100.dp) - .padding(8.dp) - .clickable { - - navController.navigate("quizPage") - } + .weight(0.9f) + .fillMaxHeight(), + horizontalAlignment = Alignment.CenterHorizontally ) { - Image( - painter = painterResource(id = R.drawable.quiz), - contentDescription = "Quiz 2", - modifier = Modifier.fillMaxSize(), - contentScale = ContentScale.Crop - ) + Box( + modifier = Modifier + .size(width = 150.dp, height = 100.dp) + .padding(8.dp) + .clickable { + navControllerQuizPage() + } + ) { + Image( + painter = painterResource(id = R.drawable.quiz), + contentDescription = "Quiz 1", + modifier = Modifier.fillMaxSize(), + contentScale = ContentScale.Crop + ) + } + + Box( + modifier = Modifier + .size(width = 150.dp, height = 100.dp) + .padding(8.dp) + .clickable { + navControllerQuizPage() + } + ) { + Image( + painter = painterResource(id = R.drawable.quiz), + contentDescription = "Quiz 2", + modifier = Modifier.fillMaxSize(), + contentScale = ContentScale.Crop + ) + } } - } - Spacer(modifier = Modifier.width(10.dp)) + Spacer(modifier = Modifier.width(10.dp)) - Column( - modifier = Modifier - .weight(0.9f) - .fillMaxHeight(), - horizontalAlignment = Alignment.CenterHorizontally - ) { - Box( + Column( modifier = Modifier - .size(width = 150.dp, height = 100.dp) - .padding(8.dp) - .clickable { - navController.navigate("quizPage") - } + .weight(0.9f) + .fillMaxHeight(), + horizontalAlignment = Alignment.CenterHorizontally ) { - Image( - painter = painterResource(id = R.drawable.quiz), - contentDescription = "Quiz 3", - modifier = Modifier.fillMaxSize(), - contentScale = ContentScale.Crop - ) - } + Box( + modifier = Modifier + .size(width = 150.dp, height = 100.dp) + .padding(8.dp) + .clickable { + navControllerQuizPage() + } + ) { + Image( + painter = painterResource(id = R.drawable.quiz), + contentDescription = "Quiz 3", + modifier = Modifier.fillMaxSize(), + contentScale = ContentScale.Crop + ) + } - Box( - modifier = Modifier - .size(width = 150.dp, height = 100.dp) - .padding(8.dp) - .clickable { - navController.navigate("quizPage") - } - ) { - Image( - painter = painterResource(id = R.drawable.quiz), - contentDescription = "Quiz 4", - modifier = Modifier.fillMaxSize(), - contentScale = ContentScale.Crop - ) + Box( + modifier = Modifier + .size(width = 150.dp, height = 100.dp) + .padding(8.dp) + .clickable { + navControllerQuizPage() + } + ) { + Image( + painter = painterResource(id = R.drawable.quiz), + contentDescription = "Quiz 4", + modifier = Modifier.fillMaxSize(), + contentScale = ContentScale.Crop + ) + } } - } - - Spacer(modifier = Modifier.weight(0.1f)) - } -} -@Composable -fun QuizApp() { - val navController = rememberNavController() - - NavHost(navController = navController, startDestination = "quizEndPage") { - composable("quizAccueil") { - QuizAccueil(navController = navController) - } - composable("quizPage") { - QuizPage(navController = navController) - } - composable("quizEndPage") { - QuizEndPage(5, 1) + Spacer(modifier = Modifier.weight(0.1f)) } } -} \ 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 4897a92..94bc2ba 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 @@ -24,7 +24,10 @@ import com.example.what_the_fantasy.data.model.Question import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun QuizPage(navController: NavController) { +fun QuizPage( + navControllerQuiz: () -> Unit, + navControllerQuizEndPage: () -> Unit +) { val questions = QuestionStub.allQuestions var idCurrentQuestion by remember { mutableIntStateOf(0) } var pts by remember { mutableIntStateOf(0) } @@ -46,7 +49,7 @@ fun QuizPage(navController: NavController) { if (answer == correctAnswer) pts++ if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++ - else navController.popBackStack() // Retour menu + else navControllerQuiz() // Retour menu } Box( @@ -69,7 +72,7 @@ fun QuizPage(navController: NavController) { modifier = Modifier.fillMaxWidth() ) { IconButton( - onClick = { navController.popBackStack() }, + onClick = { navControllerQuiz() }, modifier = Modifier.align(Alignment.TopStart) ) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Retour", tint = Color.White) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt index a5b82e7..078c936 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt @@ -5,7 +5,4 @@ import com.example.what_the_fantasy.ui.components.NavBar @Composable fun QuotePage() { - NavBar { - - } } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt index be429f8..3d081c1 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt @@ -5,7 +5,4 @@ import com.example.what_the_fantasy.ui.components.NavBar @Composable fun SearchPage() { - NavBar { - - } } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt index 42913ae..dd6dce6 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt @@ -5,7 +5,4 @@ import com.example.what_the_fantasy.ui.components.NavBar @Composable fun SubmitQuotePage() { - NavBar { - - } } \ 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 64ce917..880122c 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 @@ -18,4 +18,6 @@ val gradienBox = Brush.linearGradient( ) val colorBackground = Color(0xFF100C1B) -val colorNavBar = Color(0xFF2F0E62) \ No newline at end of file +val colorNavBar = Color(0xFF2F0E62) + +val colorButtonNav = Color.Cyan \ No newline at end of file From 69859097ac502305b4e307f6306bea465120ad54 Mon Sep 17 00:00:00 2001 From: Kentin BRONGNIART Date: Fri, 28 Feb 2025 11:09:22 +0100 Subject: [PATCH 6/7] e --- .../java/com/example/what_the_fantasy/ui/components/NavBar.kt | 2 ++ 1 file changed, 2 insertions(+) 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 fb0ead1..a13609e 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 @@ -42,6 +42,8 @@ fun NavBar(onProfile : Boolean = false , navControllerAccueil: () -> Unit, navControllerQuiz: () -> Unit, + + content : @Composable ()-> Unit ) { Column( From 4f9e791fd371033c750a4fe1c3bd8c78edbcc7ed Mon Sep 17 00:00:00 2001 From: Kentin BRONGNIART Date: Fri, 28 Feb 2025 12:25:04 +0100 Subject: [PATCH 7/7] finition de la barre de navigation (avec sauvegarde de l'utilisateur) --- .../what_the_fantasy/data/local/UserStub.kt | 121 +++++----------- .../what_the_fantasy/data/model/User.kt | 4 +- .../data/services/IServices.kt | 16 ++- .../data/services/ServicesAPI.kt | 20 ++- .../data/services/ServicesStub.kt | 76 ++++++++-- .../what_the_fantasy/ui/components/NavBar.kt | 41 ++++-- .../ui/components/hasPassword.kt | 14 ++ .../ui/navigations/AppNavigator.kt | 130 ++++++++++++------ .../ui/screens/AccueilPage.kt | 10 +- .../ui/screens/FavoritePage.kt | 10 +- .../what_the_fantasy/ui/screens/LoginPage.kt | 29 ++-- .../what_the_fantasy/ui/screens/ProfilPage.kt | 19 ++- .../ui/screens/QuizEndPage.kt | 85 +----------- .../screens/{QuizAccueil.kt => QuizMenu.kt} | 28 ++-- .../what_the_fantasy/ui/screens/QuizPage.kt | 117 +++++++++------- 15 files changed, 379 insertions(+), 341 deletions(-) create mode 100644 What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/hasPassword.kt rename What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/{QuizAccueil.kt => QuizMenu.kt} (87%) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt index 552ad3e..d5250eb 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt @@ -3,95 +3,38 @@ package com.example.what_the_fantasy.data.local import com.example.what_the_fantasy.data.model.User object UserStub { - val user1 = User( - id = 1, - username = "Aragorn123", - email = "aragorn@example.com", - date = "2022-01-15", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-fantaisie_1045-185.jpg?size=338&ext=jpg", - password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 - - val user2 = User( - id = 2, - username = "Legolas456", - email = "legolas@example.com", - date = "2021-05-23", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-elfe-fantaisie_1045-186.jpg?size=338&ext=jpg", - password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 - - val user3 = User( - id = 3, - username = "Gandalf789", - email = "gandalf@example.com", - date = "2020-09-10", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-magicien-fantaisie_1045-187.jpg?size=338&ext=jpg", - password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 - - val user4 = User( - id = 4, - username = "FrodoBaggins", - email = "frodo@example.com", - date = "2023-03-18", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-hobbit-fantaisie_1045-188.jpg?size=338&ext=jpg", - password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 - - val user5 = User( - id = 5, - username = "Gimli999", - email = "gimli@example.com", - date = "2022-07-04", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-nain-fantaisie_1045-189.jpg?size=338&ext=jpg", - password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 - - val user6 = User( - id = 6, - username = "Galadriel321", - email = "galadriel@example.com", - date = "2021-11-30", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-elfe-femme-fantaisie_1045-190.jpg?size=338&ext=jpg", - password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 - - val user7 = User( - id = 7, - username = "Boromir654", - email = "boromir@example.com", - date = "2023-06-22", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-191.jpg?size=338&ext=jpg", - password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 - - val user8 = User( - id = 8, - username = "Eowyn777", - email = "eowyn@example.com", - date = "2022-04-11", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerriere-femme-fantaisie_1045-192.jpg?size=338&ext=jpg", - password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 - - val user9 = User( - id = 9, - username = "Saruman888", - email = "saruman@example.com", - date = "2021-08-15", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-magicien-malefique-fantaisie_1045-193.jpg?size=338&ext=jpg", - password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 - - val user10 = User( - id = 10, - username = "Faramir222", - email = "faramir@example.com", - date = "2023-02-08", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg", - password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 + //LE MOT DE PASSE POUR TOUS LES UTILISATEURS EST : 1234 + val users: MutableList = mutableListOf( + User(1, "Aragorn123", "aragorn@example.com", "2022-01-15", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-fantaisie_1045-185.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"), //1234 + User(2, "Legolas456", "legolas@example.com", "2021-05-23", "https://img.freepik.com/vecteurs-libre/personnage-elfe-fantaisie_1045-186.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"),//1234 + User(3, "Gandalf789", "gandalf@example.com", "2020-09-10", "https://img.freepik.com/vecteurs-libre/personnage-magicien-fantaisie_1045-187.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"),//1234 + User(4, "FrodoBaggins", "frodo@example.com", "2023-03-18", "https://img.freepik.com/vecteurs-libre/personnage-hobbit-fantaisie_1045-188.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"),//1234 + User(5, "Gimli999", "gimli@example.com", "2022-07-04", "https://img.freepik.com/vecteurs-libre/personnage-nain-fantaisie_1045-189.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"),//1234 + User(6, "Galadriel321", "galadriel@example.com", "2021-11-30", "https://img.freepik.com/vecteurs-libre/personnage-elfe-femme-fantaisie_1045-190.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"),//1234 + User(7, "Boromir654", "boromir@example.com", "2023-06-22", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-191.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"),//1234 + User(8, "Eowyn777", "eowyn@example.com", "2022-04-11", "https://img.freepik.com/vecteurs-libre/personnage-guerriere-femme-fantaisie_1045-192.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"),//1234 + User(9, "Saruman888", "saruman@example.com", "2021-08-15", "https://img.freepik.com/vecteurs-libre/personnage-magicien-malefique-fantaisie_1045-193.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"),//1234 + User(10, "Faramir222", "faramir@example.com", "2023-02-08", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"),//1234 + User(11, "dev", "testeur@example.com", "2023-02-08", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4")//1234 + ) - val user11 = User( - id = 10, - username = "dev", - email = "testeur@example.com", - date = "2023-02-08", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg", - password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 + fun addUser(user: User) { + users.add(user) + } + +// +// // Modifier un utilisateur +// fun updateUser(id: Int, updatedUser: User) { +// val index = users.indexOfFirst { it.id == id } +// if (index != -1) { +// users[index] = updatedUser +// } +// } +// +// // Supprimer un utilisateur +// fun removeUser(id: Int) { +// users.removeAll { it.id == id } +// } +// - val allUsers: List = listOf( - user1, user2, user3, user4, user5, user6, user7, user8, user9, user10, user11 - ) } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/User.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/User.kt index ce4cb2f..811561b 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/User.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/User.kt @@ -6,5 +6,5 @@ class User( var email:String, var date:String, val imgUrl: String, - val password: String -) + var password: String +) \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt index df15ebd..5f8ab42 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt @@ -1,13 +1,19 @@ package com.example.what_the_fantasy.data.services +import com.example.what_the_fantasy.data.local.UserStub.users +import com.example.what_the_fantasy.data.model.User + interface IServices { - fun EditUsername(username : String) - fun EditEmail(email : String) - fun EditPasswd(passwd : String, passwdValid : String) - fun EditImage(imageURL : String) + fun EditUsername(username : String, index : Int) + fun EditEmail(email : String, index : Int) + fun EditPasswd(passwd : String, index : Int) + fun EditImage(imageURL : String, index : Int) - fun CreateUser(username : String, email : String, passwd : String, imageURL: String) + fun CreateUser(username : String, email : String, passwd : String, imageURL: String, services : IServices) : Boolean fun getFavorite(username: String) + fun getAllUsers(): List + + fun getUserById(id: Int): User? fun SearchQuote(quote : String) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt index 9743f68..bf6d27e 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt @@ -1,23 +1,25 @@ package com.example.what_the_fantasy.data.services +import com.example.what_the_fantasy.data.model.User + class ServicesAPI : IServices { - override fun EditUsername(username: String) { + override fun EditUsername(username: String, index : Int) { TODO("Not yet implemented") } - override fun EditEmail(email: String) { + override fun EditEmail(email: String, index : Int) { TODO("Not yet implemented") } - override fun EditPasswd(passwd: String, passwdValid: String) { + override fun EditPasswd(passwd: String, index : Int) { TODO("Not yet implemented") } - override fun EditImage(imageURL: String) { + override fun EditImage(imageURL: String, index : Int) { TODO("Not yet implemented") } - override fun CreateUser(username: String, email: String, passwd: String, imageURL: String) { + override fun CreateUser(username: String, email: String, passwd: String, imageURL: String, services: IServices) : Boolean { TODO("Not yet implemented") } @@ -28,4 +30,12 @@ class ServicesAPI : IServices { override fun getFavorite(username: String) { TODO("Not yet implemented") } + + override fun getAllUsers(): List { + TODO("Not yet implemented") + } + + override fun getUserById(id: Int): User? { + TODO("Not yet implemented") + } } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt index 8c84176..f87ede9 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt @@ -1,24 +1,67 @@ package com.example.what_the_fantasy.data.services +import android.annotation.SuppressLint +import android.util.Log +import com.example.what_the_fantasy.data.local.UserStub +import com.example.what_the_fantasy.data.local.UserStub.users +import com.example.what_the_fantasy.data.model.User +import com.example.what_the_fantasy.ui.components.hashPassword +import java.time.LocalDate + class ServicesStub : IServices { - override fun EditUsername(username: String) { - TODO("Not yet implemented") + override fun EditUsername(username: String, index : Int) { + val user = getUserById(index) + user?.username = username + + //Afficher tous les users + debugDisplayUser(getAllUsers(), "UsernameUpdate") + } - override fun EditEmail(email: String) { - TODO("Not yet implemented") + override fun EditEmail(email: String,index : Int) { + val user = getUserById(index) + user?.email = email + + //Afficher tous les users + debugDisplayUser(getAllUsers(), "EmailUpdate") } - override fun EditPasswd(passwd: String, passwdValid: String) { - TODO("Not yet implemented") + override fun EditPasswd(passwd: String,index : Int) { + val user = getUserById(index) + val passwordhash = hashPassword(passwd) + user?.password = passwordhash + + //Afficher tous les users en log + debugDisplayUser(getAllUsers(), "PasswordUpdate") } - override fun EditImage(imageURL: String) { + override fun EditImage(imageURL: String,index : Int) { TODO("Not yet implemented") } - override fun CreateUser(username: String, email: String, passwd: String, imageURL: String) { - TODO("Not yet implemented") + override fun CreateUser(username: String, email: String, passwd: String, imageURL: String, services : IServices) : Boolean { + val date =dateDuJour() + val passwordhash = hashPassword(passwd) + + val userStub = services.getAllUsers() + val nbUser = userStub.size + for (user in userStub) { + if (user.username == username) { + return false + } + } + val user = User(nbUser+1,username, email, imageURL, date, passwordhash) + users.add(user)//ajout au stub + + //Afficher tous les users + debugDisplayUser(users, "CreateUser") + return true + } + + override fun getAllUsers(): List = users + + override fun getUserById(id: Int): User? { + return (users.find { it.id == id+1 }) } override fun SearchQuote(quote: String) { @@ -28,4 +71,19 @@ class ServicesStub : IServices { override fun getFavorite(username: String) { TODO("Not yet implemented") } + + + //------------------------------------------------------ + @SuppressLint("NewApi") + fun dateDuJour(): String { + val date = LocalDate.now() + return date.toString() + } + + + private fun debugDisplayUser(users : List, titleLog : String){ + for(user in users){ + Log.e(titleLog, "User created: ${user.username} => ${user.email} => ${user.password}") + } + } } \ 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 a13609e..9b64162 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 @@ -29,6 +29,7 @@ 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 @@ -36,12 +37,11 @@ fun NavBar(onProfile : Boolean = false , onFavorite : Boolean = false , onAccueil : Boolean = false , onQuiz : Boolean = false , - + index:Int, navControllerProfil: (Int) -> Unit, - navControllerFavorite: () -> Unit, - navControllerAccueil: () -> Unit, - navControllerQuiz: () -> Unit, - + navControllerFavorite:(Int) -> Unit, + navControllerAccueil: (Int) -> Unit, + navControllerQuiz: (Int) -> Unit, content : @Composable ()-> Unit ) { @@ -58,7 +58,7 @@ fun NavBar(onProfile : Boolean = false , Arrangement.SpaceBetween, verticalAlignment = Alignment.Bottom ) { - ButtonIconVectorInt(Icons.Rounded.AccountCircle,"Profile",{},onProfile) + ButtonIconVectorInt(Icons.Rounded.AccountCircle,"Profile",navControllerProfil,index,onProfile) Button(onClick = {}, @@ -80,11 +80,11 @@ fun NavBar(onProfile : Boolean = false , verticalAlignment = Alignment.CenterVertically ) { - ButtonIconVector(Icons.Rounded.Favorite,"Favorite",navControllerFavorite,onFavorite) + ButtonIconVectorInt(Icons.Rounded.Favorite,"Favorite",navControllerFavorite,index,onFavorite) - ButtonIconPainter(painterResource(R.mipmap.ic_launcher_foreground),"Accueil",navControllerAccueil,onAccueil) + ButtonIconPainterInt(painterResource(R.mipmap.ic_launcher_foreground),"Accueil",navControllerAccueil,index,onAccueil) - ButtonIconVector(Icons.Rounded.Create,"Quiz",navControllerQuiz,onQuiz) + ButtonIconVectorInt(Icons.Rounded.Create,"Quiz",navControllerQuiz,index,onQuiz) } } } @@ -105,8 +105,8 @@ fun ButtonIconVector(img : ImageVector, name : String, nav : ()->Unit ,onPage : } } @Composable -fun ButtonIconVectorInt(img : ImageVector, name : String, nav : (Int)->Unit ,onPage : Boolean){ - IconButton(onClick = {}, +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é @@ -127,7 +127,7 @@ fun ButtonIconPainter(img : Painter, name : String, nav : ()->Unit,onPage : Bool 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é + Color.Transparent, colorButtonNav),//couleur quand il est selectionné modifier = Modifier .size(60.dp) ) { @@ -138,3 +138,20 @@ fun ButtonIconPainter(img : Painter, name : String, nav : ()->Unit,onPage : Bool ) } } +@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é + modifier = Modifier + .size(60.dp) + ) { + Icon(img, + contentDescription = name, + modifier = Modifier + .size(60.dp) + ) + } +} + diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/hasPassword.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/hasPassword.kt new file mode 100644 index 0000000..2f46a9d --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/hasPassword.kt @@ -0,0 +1,14 @@ +package com.example.what_the_fantasy.ui.components + +import java.security.MessageDigest + +fun hashPassword(password: String): String { + // SHA-256 + val digest = MessageDigest.getInstance("SHA-256") + + // Convertir mdp en bytes et appliquer le hash + val hashedBytes = digest.digest(password.toByteArray()) + + // Convertir le tableau de bytes en une chaîne hexadécimale + return hashedBytes.joinToString("") { "%02x".format(it) } +} \ No newline at end of file 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 a957940..cdfdc50 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,12 +4,13 @@ import androidx.compose.runtime.Composable import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController +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 import com.example.what_the_fantasy.ui.screens.LoginPage import com.example.what_the_fantasy.ui.screens.ProfilPage -import com.example.what_the_fantasy.ui.screens.QuizAccueil import com.example.what_the_fantasy.ui.screens.QuizEndPage +import com.example.what_the_fantasy.ui.screens.QuizMenu import com.example.what_the_fantasy.ui.screens.QuizPage import com.example.what_the_fantasy.ui.screens.QuotePage import com.example.what_the_fantasy.ui.screens.SearchPage @@ -17,11 +18,14 @@ import com.example.what_the_fantasy.ui.screens.SignUpPage import com.example.what_the_fantasy.ui.screens.SubmitQuotePage - sealed class Destination(val route: String) { data object Login : Destination("Login") - data object Accueil : Destination("Accueil") - data object Favorite : Destination("Favorite") + 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 } @@ -31,37 +35,71 @@ sealed class Destination(val route: String) { data object SignUp : Destination("SignUp") data object SubmitQuote : Destination("SubmitQuote") - data object QuizAccueil : Destination("QuizAccueil") - data object QuizPage : Destination("QuizPage") - data object QuizEndPage : Destination("QuizEndPage") + 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") + data object QuizEnd : Destination("QuizEnd/{idQuiz}/{pts}") { + // Ajout paramètres idQuiz et pts + fun createIdAndPts(idQuiz : Int, pts : Int) = "QuizEnd/$idQuiz/$pts" + } } @Composable fun AppNavigator() { val navController = rememberNavController() - - NavHost(navController, startDestination = Destination.Accueil.route) { + val services = ServicesStub() + NavHost(navController, startDestination = Destination.Login.route) { composable(Destination.Login.route) { LoginPage( navControllerSignUp = { navController.navigate(Destination.SignUp.route) }, navControllerProfil = { userIndex -> navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil - } + }, + services ) } - composable(Destination.Accueil.route) { AccueilPage( - navFavorite = { navController.navigate(Destination.Favorite.route) }, - navQuiz = { navController.navigate(Destination.QuizAccueil.route) } + composable(Destination.Accueil.route) { + val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 + 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 + } ) } - composable(Destination.Favorite.route) { FavoritePage( - navAccueil = { navController.navigate(Destination.Accueil.route) }, - navQuiz = { navController.navigate(Destination.QuizAccueil.route) } + composable(Destination.Favorite.route) { + val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 + 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 + } ) } - composable(Destination.Profil.route) { backStackEntry -> + composable(Destination.Profil.route) { // Récupère l'index passé dans la route - val userIndex = backStackEntry.arguments?.getString("userIndex")?.toInt() ?: -1 - ProfilPage(index = userIndex, - navController = navController, - - + val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 + 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 + }, + services = services ) } composable(Destination.Quote.route) { QuotePage() } @@ -69,25 +107,35 @@ fun AppNavigator() { composable(Destination.SignUp.route) { SignUpPage(navController) } composable(Destination.SubmitQuote.route) { SubmitQuotePage() } - - - composable(Destination.QuizAccueil.route) { QuizAccueil( - navFavorite = { navController.navigate(Destination.Favorite.route) }, - navAccueil = { navController.navigate(Destination.Accueil.route) }, - - navControllerQuizPage = { navController.navigate(Destination.QuizPage.route) }, - navControllerQuizEndPage = { navController.navigate(Destination.QuizEndPage.route) } - ) } - - composable(Destination.QuizPage.route) { QuizPage( - navControllerQuiz = {navController.navigate(Destination.QuizAccueil.route)}, - navControllerQuizEndPage = {navController.navigate(Destination.QuizEndPage.route)} - ) } - composable(Destination.QuizEndPage.route) { QuizEndPage( - points = 5, - idQuiz = 1 - ) } - + composable(Destination.QuizMenu.route) { + val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 + QuizMenu( + index = userIndex, + navAccueil = { navController.navigate(Destination.Accueil.route) }, + navFavorite = { navController.navigate(Destination.Favorite.route) }, + navControllerQuiz = { navController.navigate(Destination.Quiz.route) }, + navProfil = { userIndex -> + navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil + } + ) + } + composable(Destination.Quiz.route) { + QuizPage( + navControllerQuizEnd = { idQuiz, pts -> + navController.navigate(Destination.QuizEnd.createIdAndPts(idQuiz, pts)) + }, + navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) } + ) + } + composable(Destination.QuizEnd.route) { backStackEntry -> + val idQuiz = backStackEntry.arguments?.getString("idQuiz")?.toInt() ?: 0 + val pts = backStackEntry.arguments?.getString("pts")?.toInt() ?: 0 + QuizEndPage( + idQuiz, + pts, + navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) } + ) + } } } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt index 16fe4f8..f56508f 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt @@ -10,18 +10,22 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.sp +import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.ui.components.NavBar import com.example.what_the_fantasy.ui.theme.colorBackground @Composable fun AccueilPage( - navFavorite: () -> Unit, - navQuiz: () -> Unit + index: Int, + navFavorite:(Int) -> Unit, + navQuiz: (Int) -> Unit, + navProfil:(Int) -> Unit ) { NavBar(onAccueil = true, + index = index, navControllerFavorite = navFavorite, navControllerAccueil = { }, - navControllerProfil = {}, + navControllerProfil = navProfil, navControllerQuiz = navQuiz ){ Box( diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt index 2914701..fc7f309 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt @@ -10,18 +10,22 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.sp +import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.ui.components.NavBar import com.example.what_the_fantasy.ui.theme.colorBackground @Composable fun FavoritePage( - navAccueil: () -> Unit, - navQuiz: () -> Unit + index: Int, + navAccueil: (Int) -> Unit, + navQuiz: (Int) -> Unit, + navProfil:(Int) -> Unit ) { NavBar(onFavorite = true, + index = index, navControllerFavorite = { }, navControllerAccueil = navAccueil, - navControllerProfil = {}, + navControllerProfil = navProfil, navControllerQuiz = navQuiz ) { Box( diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt index 4dbc28a..767b2ad 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt @@ -39,17 +39,19 @@ import androidx.navigation.compose.composable import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.UserStub import com.example.what_the_fantasy.data.model.User -import com.example.what_the_fantasy.ui.components.NavBar +import com.example.what_the_fantasy.data.services.IServices +import com.example.what_the_fantasy.data.services.ServicesStub +import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent import com.example.what_the_fantasy.ui.components.SpaceHeightComponent import com.example.what_the_fantasy.ui.components.TitlePageComponent +import com.example.what_the_fantasy.ui.components.hashPassword import com.example.what_the_fantasy.ui.theme.colorBackground import com.example.what_the_fantasy.ui.theme.gradienBox import java.security.MessageDigest @Composable -fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Unit) { - - val users = UserStub.allUsers; +fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Unit, services : IServices) { + val users = services.getAllUsers() Box( modifier = Modifier @@ -57,7 +59,6 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni .background(colorBackground), contentAlignment = Alignment.Center ){ - Column( modifier = Modifier .fillMaxWidth(0.9f) @@ -76,9 +77,7 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni SpaceHeightComponent(16) CreateAccountButton(R.string.ButtonCreateLogin,12, Color.White, navControllerSignUp) } - } - } @@ -130,6 +129,7 @@ fun PassWdTextField(textpasswdResId : Int) : String{ @Composable fun ConnexionButtonLogin(userStub : List, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: (Int) -> Unit){ val title = stringResource(id = titleResId) + Button( onClick = { validLogin(id, passwd, userStub, navController) }, colors = ButtonDefaults.buttonColors(containerColor = colorButton), @@ -142,6 +142,7 @@ fun ConnexionButtonLogin(userStub : List, id : String, passwd : String, ti fun validLogin(identifiant : String, passwd : String, users : List, navController: (Int) -> Unit){ + users.forEachIndexed { index, user -> val hashPassWd = hashPassword(passwd) if (user.username == identifiant && user.password == hashPassWd) { @@ -151,18 +152,6 @@ fun validLogin(identifiant : String, passwd : String, users : List, navCon } } -fun hashPassword(password: String): String { - // SHA-256 - val digest = MessageDigest.getInstance("SHA-256") - - // Convertir mdp en bytes et appliquer le hash - val hashedBytes = digest.digest(password.toByteArray()) - - // Convertir le tableau de bytes en une chaîne hexadécimale - return hashedBytes.joinToString("") { "%02x".format(it) } -} - - @Composable fun CreateAccountButton(titleResId : Int, size : Int, color : Color, navController: () -> Unit){ val title = stringResource(id = titleResId) @@ -174,4 +163,4 @@ fun CreateAccountButton(titleResId : Int, size : Int, color : Color, navControll navController()// rediriger vers la page de création de compte } ) -} +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt index 5937840..4df4756 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt @@ -61,6 +61,7 @@ import coil.compose.AsyncImage import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.QuestionStub import com.example.what_the_fantasy.data.local.UserStub +import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent import com.example.what_the_fantasy.ui.components.NavBar import com.example.what_the_fantasy.ui.components.SpaceHeightComponent @@ -69,15 +70,21 @@ import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme import com.example.what_the_fantasy.ui.theme.gradienBox @Composable -fun ProfilPage(index: Int, navController: NavController) { +fun ProfilPage(index: Int, + navFavorite: (Int) -> Unit, + navAccueil: (Int) -> Unit, + navQuiz: (Int) -> Unit, + services: IServices +) { + val user = services.getUserById(index) ?: return + NavBar(onProfile = true, - navControllerFavorite = {}, - navControllerAccueil = {}, + index = index, + navControllerFavorite = navFavorite, + navControllerAccueil = navAccueil, navControllerProfil = {}, - navControllerQuiz = {} + navControllerQuiz = navQuiz ) { - val userList = UserStub.allUsers - val user = userList[index] Box( modifier = Modifier 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 359e7f7..3548590 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 @@ -2,6 +2,7 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.foundation.Image import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape @@ -31,37 +32,11 @@ val gradient = Brush.linearGradient( end = Offset(1000f, 0f) ) - - @Composable -fun QuizEndPage(points: Int, idQuiz: Int) { +fun QuizEndPage(idQuiz: Int, points: Int, navControllerQuizMenu: () -> Unit) { 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 - ) { - IconButton(onClick = { }) { - Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Retour", tint = Color.White) - } - Image( - painter = painterResource(id = R.drawable.quiz), - contentDescription = "Profil", - modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape) - ) - Image( - painter = painterResource(id = R.drawable.quiz), - contentDescription = "Profil", - modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape) - ) - } // Contenu principal Column( @@ -102,62 +77,8 @@ fun QuizEndPage(points: Int, idQuiz: Int) { color = Color.White, style = TextStyle(fontSize = 15.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center) ) - Row ( - modifier = Modifier - .fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceAround - ) { - // Bouton Quiz Précédent - Image( - painter = painterResource(id = R.drawable.quiz), - contentDescription = "Profil", - modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape) - ) - // Bouton Retour Menu Quiz - Image( - painter = painterResource(id = R.drawable.quiz), - contentDescription = "Profil", - modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape) - ) - // Bouton Quiz Suivant - Image( - painter = painterResource(id = R.drawable.quiz), - contentDescription = "Profil", - modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape) - ) - } - } } - // 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.quiz), - contentDescription = "Bouton", - modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape) - ) - // Bouton WhatTheFantasy - Image( - painter = painterResource(id = R.drawable.quiz), - contentDescription = "Bouton", - modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape) - ) - // Bouton Quiz - Image( - painter = painterResource(id = R.drawable.quiz), - contentDescription = "Bouton", - modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape) - ) - } } -} +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizAccueil.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt similarity index 87% rename from What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizAccueil.kt rename to What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt index a5fcaac..1a26099 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizAccueil.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt @@ -19,28 +19,26 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp -import androidx.navigation.NavController -import androidx.navigation.compose.NavHost -import androidx.navigation.compose.composable -import androidx.navigation.compose.rememberNavController import com.example.what_the_fantasy.R +import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun QuizAccueil( - navFavorite: () -> Unit, - navAccueil: () -> Unit, - navControllerQuizPage: () -> Unit, - navControllerQuizEndPage: () -> Unit +fun QuizMenu( + index: Int, + navFavorite: (Int) -> Unit, + navAccueil: (Int) -> Unit, + navProfil:(Int) -> Unit, + navControllerQuiz: () -> Unit ) { NavBar(onQuiz = true, + index = index, navControllerFavorite = navFavorite, navControllerAccueil = navAccueil, - navControllerProfil = {}, + navControllerProfil = navProfil, navControllerQuiz = { } ) { - Row( modifier = Modifier .fillMaxSize() @@ -60,7 +58,7 @@ fun QuizAccueil( .size(width = 150.dp, height = 100.dp) .padding(8.dp) .clickable { - navControllerQuizPage() + navControllerQuiz() } ) { Image( @@ -76,7 +74,7 @@ fun QuizAccueil( .size(width = 150.dp, height = 100.dp) .padding(8.dp) .clickable { - navControllerQuizPage() + navControllerQuiz() } ) { Image( @@ -101,7 +99,7 @@ fun QuizAccueil( .size(width = 150.dp, height = 100.dp) .padding(8.dp) .clickable { - navControllerQuizPage() + navControllerQuiz() } ) { Image( @@ -117,7 +115,7 @@ fun QuizAccueil( .size(width = 150.dp, height = 100.dp) .padding(8.dp) .clickable { - navControllerQuizPage() + navControllerQuiz() } ) { Image( 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 0d7e3a3..8647b43 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 @@ -1,14 +1,11 @@ package com.example.what_the_fantasy.ui.screens +import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.automirrored.filled.ArrowBack -import androidx.compose.material.icons.filled.ArrowBack -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment @@ -16,17 +13,19 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import androidx.navigation.NavController +import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.QuestionStub -import com.example.what_the_fantasy.data.model.Question -import com.example.what_the_fantasy.ui.components.NavBar @Composable fun QuizPage( - navControllerQuiz: () -> Unit, - navControllerQuizEndPage: () -> Unit + navControllerQuizEnd: (Int, Int) -> Unit, + navControllerQuizMenu: () -> Unit ) { val questions = QuestionStub.allQuestions var idCurrentQuestion by remember { mutableIntStateOf(0) } @@ -49,61 +48,81 @@ fun QuizPage( if (answer == correctAnswer) pts++ if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++ - else navControllerQuiz() // Retour menu + else navControllerQuizEnd(0, pts) // Retour menu } - Box( - modifier = Modifier - .fillMaxSize() - .background(Color(0xFF100C1B)) - .padding(16.dp) + Column ( + modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B)) ) { + + + // Contenu princiapl Column( modifier = Modifier - .fillMaxSize(), + .weight(0.8f) + .fillMaxWidth() + .padding(horizontal = 50.dp, vertical = 20.dp), horizontalAlignment = Alignment.CenterHorizontally ) { val question = questions[idCurrentQuestion] - Column ( + Column( horizontalAlignment = Alignment.CenterHorizontally, ) { - Box( - modifier = Modifier.fillMaxWidth() + Text( + text = "▶ Quiz ◀", + color = Color.White, + style = TextStyle(fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center) + ) + Column ( + modifier = Modifier + .background(brush = gradient, shape = RoundedCornerShape(20.dp)), + horizontalAlignment = Alignment.CenterHorizontally ) { - IconButton( - onClick = { navControllerQuiz() }, - modifier = Modifier.align(Alignment.TopStart) - ) { - Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Retour", tint = Color.White) - } - } - Text("Question ${question.id}", color = Color.White, fontSize = 18.sp, modifier = Modifier.padding(top = 20.dp)) - Text("Points : $pts", color = Color.White, fontSize = 18.sp, modifier = Modifier.padding(top = 40.dp)) - 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( + Text( + "Question ${question.id}", + 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 - .width(220.dp) - .height(50.dp) - .background(brush = gradient, shape = RoundedCornerShape(16.dp)) - .clickable { onAnswerSelected(answer) } - .padding(horizontal = 8.dp), - contentAlignment = Alignment.Center + .padding(top = 30.dp) ) { - Text(answer, color = Color.White, fontSize = 18.sp) + 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)) } } - } - } -} - + } +} \ No newline at end of file