From 829d85e9b22d0597824fe86b84cf84446397d116 Mon Sep 17 00:00:00 2001 From: beaulaton Date: Thu, 20 Feb 2025 15:20:45 +0100 Subject: [PATCH] Lien entre Login et Profil --- .../ui/navigations/AppNavigator.kt | 15 ++++++++++++--- .../what_the_fantasy/ui/screens/LoginPage.kt | 15 ++++++++------- .../what_the_fantasy/ui/screens/ProfilPage.kt | 8 ++------ 3 files changed, 22 insertions(+), 16 deletions(-) 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 fc05703..d155f2a 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 @@ -20,7 +20,9 @@ sealed class Destination(val route: String) { data object Login : Destination("Login") data object Accueil : Destination("Accueil") data object Favorite : Destination("Favorite") - data object Profil : Destination("Profil") + 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") @@ -36,12 +38,18 @@ fun AppNavigator() { composable(Destination.Login.route) { LoginPage( navControllerSignUp = { navController.navigate(Destination.SignUp.route) }, - navControllerProfil = { navController.navigate(Destination.Profil.route) } + navControllerProfil = { userIndex -> + navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil + } ) } composable(Destination.Accueil.route) { AccueilPage() } composable(Destination.Favorite.route) { FavoritePage() } - composable(Destination.Profil.route) { ProfilPage(navController) } + 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) + } composable(Destination.Quiz.route) { QuizPage() } composable(Destination.Quote.route) { QuotePage() } composable(Destination.Search.route) { SearchPage() } @@ -49,3 +57,4 @@ fun AppNavigator() { composable(Destination.SubmitQuote.route) { SubmitQuotePage() } } } + 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..d5d3fd7 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 @@ -1,5 +1,6 @@ package com.example.what_the_fantasy.ui.screens +import android.util.Log import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box @@ -45,7 +46,7 @@ import com.example.what_the_fantasy.ui.theme.gradienBox import java.security.MessageDigest @Composable -fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: () -> Unit) { +fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Unit) { val users = UserStub.allUsers; @@ -126,7 +127,7 @@ fun PassWdTextField(textpasswdResId : Int) : String{ @Composable -fun ConnexionButtonLogin(userStub : List, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: () -> Unit){ +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) }, @@ -139,12 +140,12 @@ fun ConnexionButtonLogin(userStub : List, id : String, passwd : String, ti } -fun validLogin(identifiant : String, passwd : String, users : List, navController: () -> Unit){ - users.forEach { user -> +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) run { - navController() + if (user.username == identifiant && user.password == hashPassWd) { + // Utilise l'index pour naviguer à la position correspondante + navController(index) // Passer l'index à la fonction navController } } } 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..c2c0702 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 @@ -67,14 +67,14 @@ import com.example.what_the_fantasy.ui.components.TitlePageComponent import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme @Composable -fun ProfilPage(navController: NavController) { +fun ProfilPage(index: Int, navController: NavController) { val gradient = Brush.linearGradient( colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)), // Violet clair → Violet foncé start = Offset(0f, 1000f), // Départ en bas à gauche end = Offset(1000f, 0f) // Fin en haut à droite ) val user = UserStub.allUsers - val index = 2 // Pour changer l'utilisateur pour le moment + //val index = 2 // Pour changer l'utilisateur pour le moment Box( modifier = Modifier @@ -121,9 +121,6 @@ fun ProfilPage(navController: NavController) { } - - - @Composable fun ImageProfil(imgProfil : String, size :Int, sizeBorber : Int, colorBorder : Color){ @@ -136,7 +133,6 @@ fun ImageProfil(imgProfil : String, size :Int, sizeBorber : Int, colorBorder : C ) } - @Composable fun EditEmail(userEmail: String) { var email by remember { mutableStateOf(userEmail) }