|
|
@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
|
|
|
|
import androidx.navigation.compose.NavHost
|
|
|
|
import androidx.navigation.compose.NavHost
|
|
|
|
import androidx.navigation.compose.composable
|
|
|
|
import androidx.navigation.compose.composable
|
|
|
|
import androidx.navigation.compose.rememberNavController
|
|
|
|
import androidx.navigation.compose.rememberNavController
|
|
|
|
|
|
|
|
import androidx.navigation.toRoute
|
|
|
|
import com.example.what_the_fantasy.data.services.ServicesStub
|
|
|
|
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.AccueilPage
|
|
|
|
import com.example.what_the_fantasy.ui.screens.FavoritePage
|
|
|
|
import com.example.what_the_fantasy.ui.screens.FavoritePage
|
|
|
@ -16,155 +17,128 @@ import com.example.what_the_fantasy.ui.screens.QuotePage
|
|
|
|
import com.example.what_the_fantasy.ui.screens.SearchPage
|
|
|
|
import com.example.what_the_fantasy.ui.screens.SearchPage
|
|
|
|
import com.example.what_the_fantasy.ui.screens.SignUpPage
|
|
|
|
import com.example.what_the_fantasy.ui.screens.SignUpPage
|
|
|
|
import com.example.what_the_fantasy.ui.screens.SubmitQuotePage
|
|
|
|
import com.example.what_the_fantasy.ui.screens.SubmitQuotePage
|
|
|
|
|
|
|
|
import kotlinx.serialization.Serializable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
|
|
|
|
data class Accueil(val userIndex: Int)
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
|
|
|
|
data object Login
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
|
|
|
|
data class Favorite(val userIndex: Int)
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
|
|
|
|
data class Profil(val userIndex: Int)
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
|
|
|
|
data class QuizMenu(val userIndex: Int)
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
|
|
|
|
data class Quiz(val userIndex : Int, val idQuiz : Int)
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
|
|
|
|
data class QuizEnd(val userIndex : Int, val idQuiz : Int,val pts : Int)
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
|
|
|
|
data object Quote
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
|
|
|
|
data object Search
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
|
|
|
|
data object SignUp
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
|
|
|
|
data object SubmitQuote
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sealed class Destination(val route: String) {
|
|
|
|
|
|
|
|
data object Login : Destination("Login")
|
|
|
|
|
|
|
|
data object Accueil : Destination("Accueil/{userIndex}") { // Ajout du paramètre userIndex
|
|
|
|
|
|
|
|
fun createRoute(userIndex: Int) = "Accueil/$userIndex" // Fonction pour créer la route avec l'index
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
data object Favorite : Destination("Favorite/{userIndex}") { // Ajout du paramètre userIndex
|
|
|
|
|
|
|
|
fun createRoute(userIndex: Int) = "Favorite/$userIndex" // Fonction pour créer la route avec l'index
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
data object Profil : Destination("Profil/{userIndex}") { // Ajout du paramètre userIndex
|
|
|
|
|
|
|
|
fun createRoute(userIndex: Int) = "Profil/$userIndex" // Fonction pour créer la route avec l'index
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
data object QuizMenu : Destination("QuizMenu/{userIndex}") { // Ajout du paramètre userIndex
|
|
|
|
|
|
|
|
fun createRoute(userIndex: Int) = "QuizMenu/$userIndex" // Fonction pour créer la route avec l'index
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
data object Quiz : Destination("Quiz/{idQuiz}") {
|
|
|
|
|
|
|
|
// Ajout paramètre idQuiz
|
|
|
|
|
|
|
|
fun createId(idQuiz : Int) = "Quiz/$idQuiz"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
data object QuizEnd : Destination("QuizEnd/{idQuiz}/{pts}") {
|
|
|
|
|
|
|
|
// Ajout paramètres idQuiz et pts
|
|
|
|
|
|
|
|
fun createIdAndPts(idQuiz : Int, pts : Int) = "QuizEnd/$idQuiz/$pts"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
data object Quote : Destination("Quote")
|
|
|
|
|
|
|
|
data object Search : Destination("Search")
|
|
|
|
|
|
|
|
data object SignUp : Destination("SignUp")
|
|
|
|
|
|
|
|
data object SubmitQuote : Destination("SubmitQuote")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun AppNavigator() {
|
|
|
|
fun AppNavigator() {
|
|
|
|
val navController = rememberNavController()
|
|
|
|
val navController = rememberNavController()
|
|
|
|
val services = ServicesStub()
|
|
|
|
val services = ServicesStub()
|
|
|
|
NavHost(navController, startDestination = Destination.Login.route) {
|
|
|
|
NavHost(navController, startDestination = Login) {
|
|
|
|
composable(Destination.Login.route) {
|
|
|
|
composable<Login> {
|
|
|
|
LoginPage(
|
|
|
|
LoginPage(
|
|
|
|
navControllerSignUp = {
|
|
|
|
navControllerSignUp = { navController.navigate(SignUp) },
|
|
|
|
navController.navigate(Destination.SignUp.route)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
navControllerProfil = { userIndex ->
|
|
|
|
navControllerProfil = { userIndex ->
|
|
|
|
navController.navigate(Destination.Profil.createRoute(userIndex)) {
|
|
|
|
navController.navigate(Profil(userIndex)) {
|
|
|
|
// Vider pile de navigation pour empêcher le retour à la page Login
|
|
|
|
// Vider pile de navigation pour empêcher le retour à la page Login
|
|
|
|
popUpTo(Destination.Login.route) { inclusive = true }
|
|
|
|
popUpTo(Login) { inclusive = true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
services
|
|
|
|
services = services
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
composable(Destination.Accueil.route) {
|
|
|
|
composable<Accueil> {
|
|
|
|
val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1
|
|
|
|
val accueil: Accueil = it.toRoute()
|
|
|
|
AccueilPage(
|
|
|
|
AccueilPage(
|
|
|
|
index = userIndex,
|
|
|
|
index = accueil.userIndex,
|
|
|
|
navFavorite = { userIndex ->
|
|
|
|
navFavorite = { navController.navigate(Favorite(accueil.userIndex)) },
|
|
|
|
navController.navigate(Destination.Favorite.createRoute(userIndex)) // Passe l'index à Profil
|
|
|
|
navQuiz = { navController.navigate(QuizMenu(accueil.userIndex)) },
|
|
|
|
},
|
|
|
|
navProfil = { navController.navigate(Profil(accueil.userIndex)) }
|
|
|
|
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) {
|
|
|
|
composable<Favorite> {
|
|
|
|
val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1
|
|
|
|
val favorite: Favorite = it.toRoute()
|
|
|
|
FavoritePage(
|
|
|
|
FavoritePage(
|
|
|
|
index = userIndex,
|
|
|
|
index = favorite.userIndex,
|
|
|
|
navAccueil ={ userIndex ->
|
|
|
|
navAccueil ={ navController.navigate( Accueil(favorite.userIndex) ) },
|
|
|
|
navController.navigate(Destination.Accueil.createRoute(userIndex)) // Passe l'index à Profil
|
|
|
|
navQuiz = { navController.navigate(QuizMenu(favorite.userIndex)) },
|
|
|
|
},
|
|
|
|
navProfil = { navController.navigate(Profil(favorite.userIndex)) }
|
|
|
|
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) {
|
|
|
|
composable<Profil>{
|
|
|
|
// Récupère l'index passé dans la route
|
|
|
|
val profil:Profil = it.toRoute()
|
|
|
|
val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1
|
|
|
|
|
|
|
|
ProfilPage(
|
|
|
|
ProfilPage(
|
|
|
|
index = userIndex,
|
|
|
|
index = profil.userIndex,
|
|
|
|
navFavorite = { userIndex ->
|
|
|
|
navFavorite = { navController.navigate(Favorite(profil.userIndex)) },
|
|
|
|
navController.navigate(Destination.Favorite.createRoute(userIndex)) // Passe l'index à Profil
|
|
|
|
navAccueil ={ navController.navigate( Accueil(profil.userIndex) ) },
|
|
|
|
},
|
|
|
|
navQuiz = { navController.navigate( QuizMenu(profil.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
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
navUnLog = {
|
|
|
|
navUnLog = {
|
|
|
|
navController.navigate(Destination.Login.route) {
|
|
|
|
navController.navigate(Login) {
|
|
|
|
// Vider pile de navigation pour empêcher le retour à la page profil
|
|
|
|
// Vider pile de navigation pour empêcher le retour à la page profil
|
|
|
|
popUpTo(Destination.Profil.route) { inclusive = true }
|
|
|
|
popUpTo(profil) { inclusive = true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
services = services
|
|
|
|
services = services
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
composable(Destination.Quote.route) { QuotePage() }
|
|
|
|
composable<Quote> { QuotePage() }
|
|
|
|
composable(Destination.Search.route) { SearchPage() }
|
|
|
|
composable<Search> { SearchPage() }
|
|
|
|
composable(Destination.SignUp.route) { SignUpPage(
|
|
|
|
composable<SignUp> { SignUpPage(
|
|
|
|
navControllerLogin = {
|
|
|
|
navControllerLogin = {
|
|
|
|
navController.navigate(Destination.Login.route){
|
|
|
|
navController.navigate(Login){
|
|
|
|
// Vider pile de navigation pour empêcher le retour à la page Sign up
|
|
|
|
// Vider pile de navigation pour empêcher le retour à la page Sign up
|
|
|
|
popUpTo(Destination.Login.route) { inclusive = true }
|
|
|
|
popUpTo(Login) { inclusive = true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},services) }
|
|
|
|
},services) }
|
|
|
|
composable(Destination.SubmitQuote.route) { SubmitQuotePage() }
|
|
|
|
composable<SubmitQuote> { SubmitQuotePage() }
|
|
|
|
|
|
|
|
|
|
|
|
composable(Destination.QuizMenu.route) {
|
|
|
|
composable<QuizMenu> {
|
|
|
|
//val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1
|
|
|
|
val quizMenu:QuizMenu=it.toRoute()
|
|
|
|
QuizMenu(
|
|
|
|
QuizMenu(
|
|
|
|
//index = userIndex,
|
|
|
|
index = quizMenu.userIndex,
|
|
|
|
// navAccueil = { userIndex ->
|
|
|
|
navAccueil = { navController.navigate( Accueil(quizMenu.userIndex) ) },
|
|
|
|
// navController.navigate(Destination.Accueil.createRoute(userIndex)) // Passe l'index à Profil
|
|
|
|
navFavorite = { navController.navigate(Favorite(quizMenu.userIndex)) },
|
|
|
|
// },
|
|
|
|
navProfil = { navController.navigate(Profil(quizMenu.userIndex)) },
|
|
|
|
// navFavorite = { userIndex ->
|
|
|
|
navControllerQuiz = { idQuiz ->
|
|
|
|
// navController.navigate(Destination.Favorite.createRoute(userIndex)) // Passe l'index à Profil
|
|
|
|
navController.navigate(Quiz(quizMenu.userIndex,idQuiz))
|
|
|
|
// },
|
|
|
|
|
|
|
|
// navProfil = { userIndex ->
|
|
|
|
|
|
|
|
// navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
navControllerQuiz = { id ->
|
|
|
|
|
|
|
|
navController.navigate(Destination.Quiz.createId(id))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
composable(Destination.Quiz.route) { backStackEntry ->
|
|
|
|
composable<Quiz> {
|
|
|
|
val idQuiz = backStackEntry.arguments?.getString("idQuiz")?.toInt() ?: 0
|
|
|
|
val quiz:Quiz=it.toRoute()
|
|
|
|
QuizPage(
|
|
|
|
QuizPage(
|
|
|
|
|
|
|
|
index = quiz.userIndex,
|
|
|
|
|
|
|
|
navAccueil = { navController.navigate( Accueil(quiz.userIndex) ) },
|
|
|
|
|
|
|
|
navFavorite = { navController.navigate(Favorite(quiz.userIndex)) },
|
|
|
|
|
|
|
|
navProfil = { navController.navigate(Profil(quiz.userIndex)) },
|
|
|
|
|
|
|
|
navQuiz = { navController.navigate(QuizMenu(quiz.userIndex)) },
|
|
|
|
navControllerQuizEnd = { idQuiz, pts ->
|
|
|
|
navControllerQuizEnd = { idQuiz, pts ->
|
|
|
|
navController.navigate(Destination.QuizEnd.createIdAndPts(idQuiz, pts))
|
|
|
|
navController.navigate(QuizEnd(quiz.userIndex,idQuiz, pts))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) },
|
|
|
|
idQuiz = quiz.idQuiz
|
|
|
|
navControllerMenu = { navController.navigate(Destination.Accueil.route) },
|
|
|
|
|
|
|
|
idQuiz
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
composable(Destination.QuizEnd.route) { backStackEntry ->
|
|
|
|
composable<QuizEnd> {
|
|
|
|
val idQuiz = backStackEntry.arguments?.getString("idQuiz")?.toInt() ?: 0
|
|
|
|
val quizEnd: QuizEnd = it.toRoute()
|
|
|
|
val pts = backStackEntry.arguments?.getString("pts")?.toInt() ?: 0
|
|
|
|
|
|
|
|
QuizEndPage(
|
|
|
|
QuizEndPage(
|
|
|
|
idQuiz,
|
|
|
|
idQuiz = quizEnd.idQuiz,
|
|
|
|
pts,
|
|
|
|
points = quizEnd.pts,
|
|
|
|
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) },
|
|
|
|
index = quizEnd.userIndex,
|
|
|
|
navControllerMenu = { navController.navigate(Destination.Accueil.route) }
|
|
|
|
navAccueil = { navController.navigate( Accueil(quizEnd.userIndex) ) },
|
|
|
|
|
|
|
|
navFavorite = { navController.navigate(Favorite(quizEnd.userIndex)) },
|
|
|
|
|
|
|
|
navProfil = { navController.navigate(Profil(quizEnd.userIndex)) },
|
|
|
|
|
|
|
|
navQuiz = { navController.navigate(QuizMenu(quizEnd.userIndex)) }
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|