Page favoris

pull/45/head
Maxime ROCHER 1 month ago
parent 8fea813004
commit d384dc7f9e

@ -1,6 +1,7 @@
package com.example.what_the_fantasy.data.local package com.example.what_the_fantasy.data.local
import com.example.what_the_fantasy.data.model.Favorite import com.example.what_the_fantasy.data.model.Favorite
import com.example.what_the_fantasy.data.model.Quote
object FavoriteStub { object FavoriteStub {
val favorites: MutableList<Favorite> = mutableListOf( val favorites: MutableList<Favorite> = mutableListOf(
@ -16,4 +17,11 @@ object FavoriteStub {
Favorite(UserStub.users[9], QuoteStub.quote20), Favorite(UserStub.users[9], QuoteStub.quote20),
Favorite(UserStub.users[10], QuoteStub.quote11) Favorite(UserStub.users[10], QuoteStub.quote11)
) )
fun getFavoritesByUser(userId: Int): List<Quote> {
return favorites
.filter { it.user.id == userId }
.map { it.quote }
}
} }

@ -1,6 +1,12 @@
package com.example.what_the_fantasy.ui.navigations package com.example.what_the_fantasy.ui.navigations
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
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
@ -16,6 +22,7 @@ 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 com.example.what_the_fantasy.ui.theme.colorNavBar
sealed class Destination(val route: String) { sealed class Destination(val route: String) {
@ -40,7 +47,6 @@ sealed class Destination(val route: String) {
} }
data object Quiz : Destination("Quiz") data object Quiz : Destination("Quiz")
data object QuizEnd : Destination("QuizEnd/{idQuiz}/{pts}") { data object QuizEnd : Destination("QuizEnd/{idQuiz}/{pts}") {
// Ajout paramètres idQuiz et pts
fun createIdAndPts(idQuiz : Int, pts : Int) = "QuizEnd/$idQuiz/$pts" fun createIdAndPts(idQuiz : Int, pts : Int) = "QuizEnd/$idQuiz/$pts"
} }
} }
@ -49,122 +55,131 @@ sealed class Destination(val route: String) {
fun AppNavigator() { fun AppNavigator() {
val navController = rememberNavController() val navController = rememberNavController()
val services = ServicesStub() val services = ServicesStub()
NavHost(navController, startDestination = Destination.Login.route) {
composable(Destination.Login.route) { Scaffold(
LoginPage( modifier = Modifier.fillMaxSize(),
navControllerSignUp = { containerColor = colorNavBar
navController.navigate(Destination.SignUp.route) ) { paddingValues ->
}, Box(modifier = Modifier.padding(paddingValues)) {
navControllerProfil = { userIndex -> NavHost(navController, startDestination = Destination.Login.route) {
navController.navigate(Destination.Profil.createRoute(userIndex)) { composable(Destination.Login.route) {
// Vider pile de navigation pour empêcher le retour à la page Login LoginPage(
popUpTo(Destination.Login.route) { inclusive = true } navControllerSignUp = {
} navController.navigate(Destination.SignUp.route)
}, },
services navControllerProfil = { userIndex ->
) navController.navigate(Destination.Profil.createRoute(userIndex)) {
} popUpTo(Destination.Login.route) { inclusive = true }
composable(Destination.Accueil.route) { backStackEntry -> }
val userIndex = backStackEntry.arguments?.getString("userIndex")?.toInt() ?: -1 },
AccueilPage( services
index = userIndex, )
navFavorite = { userIndex ->
navController.navigate(Destination.Favorite.createRoute(userIndex)) {
popUpTo(Destination.Accueil.createRoute(userIndex)) { inclusive = false }
}
},
navQuiz = { userIndex ->
navController.navigate(Destination.QuizMenu.createRoute(userIndex)) {
popUpTo(Destination.Accueil.createRoute(userIndex)) { inclusive = false }
}
},
navProfil = { userIndex ->
navController.navigate(Destination.Profil.createRoute(userIndex)) {
popUpTo(Destination.Accueil.createRoute(userIndex)) { inclusive = false }
}
} }
) composable(Destination.Accueil.route) { backStackEntry ->
} val userIndex = backStackEntry.arguments?.getString("userIndex")?.toInt() ?: -1
composable(Destination.Favorite.route) { AccueilPage(
val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 index = userIndex,
FavoritePage( navFavorite = { userIndex ->
index = userIndex, navController.navigate(Destination.Favorite.createRoute(userIndex)) {
navAccueil ={ userIndex -> popUpTo(Destination.Accueil.createRoute(userIndex)) { inclusive = false }
navController.navigate(Destination.Accueil.createRoute(userIndex)) // Passe l'index à Profil }
}, },
navQuiz = { userIndex -> navQuiz = { userIndex ->
navController.navigate(Destination.QuizMenu.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.QuizMenu.createRoute(userIndex)) {
}, popUpTo(Destination.Accueil.createRoute(userIndex)) { inclusive = false }
navProfil = { userIndex -> }
navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil },
navProfil = { userIndex ->
navController.navigate(Destination.Profil.createRoute(userIndex)) {
popUpTo(Destination.Accueil.createRoute(userIndex)) { inclusive = false }
}
}
)
} }
) } composable(Destination.Favorite.route) {
composable(Destination.Profil.route) { val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1
// Récupère l'index passé dans la route FavoritePage(
val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 index = userIndex,
ProfilPage( navAccueil = { userIndex ->
index = userIndex, navController.navigate(Destination.Accueil.createRoute(userIndex))
navFavorite = { userIndex -> },
navController.navigate(Destination.Favorite.createRoute(userIndex)) // Passe l'index à Profil navQuiz = { userIndex ->
}, navController.navigate(Destination.QuizMenu.createRoute(userIndex))
navAccueil ={ userIndex -> },
navController.navigate(Destination.Accueil.createRoute(userIndex)) // Passe l'index à Profil navProfil = { userIndex ->
}, navController.navigate(Destination.Profil.createRoute(userIndex))
navQuiz = { userIndex -> },
navController.navigate(Destination.QuizMenu.createRoute(userIndex)) // Passe l'index à Profil services
}, )
navUnLog = {
navController.navigate(Destination.Login.route) {
// Vider pile de navigation pour empêcher le retour à la page profil
popUpTo(Destination.Profil.route) { inclusive = true }
}
},
services = services
)
}
composable(Destination.Quote.route) { QuotePage() }
composable(Destination.Search.route) { SearchPage() }
composable(Destination.SignUp.route) { SignUpPage(
navControllerLogin = {
navController.navigate(Destination.Login.route){
// Vider pile de navigation pour empêcher le retour à la page Sign up
popUpTo(Destination.Login.route) { inclusive = true }
} }
},services) } composable(Destination.Profil.route) {
composable(Destination.SubmitQuote.route) { SubmitQuotePage() } val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1
ProfilPage(
composable(Destination.QuizMenu.route) { index = userIndex,
val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 navFavorite = { userIndex ->
QuizMenu( navController.navigate(Destination.Favorite.createRoute(userIndex))
index = userIndex, },
navAccueil = { userIndex -> navAccueil = { userIndex ->
navController.navigate(Destination.Accueil.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.Accueil.createRoute(userIndex))
}, },
navFavorite = { userIndex -> navQuiz = { userIndex ->
navController.navigate(Destination.Favorite.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.QuizMenu.createRoute(userIndex))
}, },
navControllerQuiz = { navController.navigate(Destination.Quiz.route) }, navUnLog = {
navProfil = { userIndex -> navController.navigate(Destination.Login.route) {
navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil popUpTo(Destination.Profil.route) { inclusive = true }
}
},
services = services
)
} }
) composable(Destination.Quote.route) { QuotePage() }
} composable(Destination.Search.route) { SearchPage() }
composable(Destination.Quiz.route) { composable(Destination.SignUp.route) {
QuizPage( SignUpPage(
navControllerQuizEnd = { idQuiz, pts -> navControllerLogin = {
navController.navigate(Destination.QuizEnd.createIdAndPts(idQuiz, pts)) navController.navigate(Destination.Login.route) {
}, popUpTo(Destination.Login.route) { inclusive = true }
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) } }
) },
} services
composable(Destination.QuizEnd.route) { backStackEntry -> )
val idQuiz = backStackEntry.arguments?.getString("idQuiz")?.toInt() ?: 0 }
val pts = backStackEntry.arguments?.getString("pts")?.toInt() ?: 0 composable(Destination.SubmitQuote.route) { SubmitQuotePage() }
QuizEndPage( composable(Destination.QuizMenu.route) {
idQuiz, val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1
pts, QuizMenu(
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) } index = userIndex,
) navAccueil = { userIndex ->
navController.navigate(Destination.Accueil.createRoute(userIndex))
},
navFavorite = { userIndex ->
navController.navigate(Destination.Favorite.createRoute(userIndex))
},
navControllerQuiz = { navController.navigate(Destination.Quiz.route) },
navProfil = { userIndex ->
navController.navigate(Destination.Profil.createRoute(userIndex))
}
)
}
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) }
)
}
}
} }
} }
} }

@ -1,17 +1,25 @@
package com.example.what_the_fantasy.ui.screens package com.example.what_the_fantasy.ui.screens
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import com.example.what_the_fantasy.data.local.DailyQuoteStub
import com.example.what_the_fantasy.data.local.FavoriteStub
import com.example.what_the_fantasy.data.local.QuoteStub
import com.example.what_the_fantasy.data.services.IServices 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.components.NavBar
import com.example.what_the_fantasy.ui.components.QuoteLittle
import com.example.what_the_fantasy.ui.theme.colorBackground import com.example.what_the_fantasy.ui.theme.colorBackground
@Composable @Composable
@ -19,8 +27,12 @@ fun FavoritePage(
index: Int, index: Int,
navAccueil: (Int) -> Unit, navAccueil: (Int) -> Unit,
navQuiz: (Int) -> Unit, navQuiz: (Int) -> Unit,
navProfil:(Int) -> Unit navProfil:(Int) -> Unit,
services: IServices
) { ) {
val user = services.getUserById(index) ?: return
val quotes = FavoriteStub.getFavoritesByUser(user.id)
NavBar(onFavorite = true, NavBar(onFavorite = true,
index = index, index = index,
navControllerFavorite = { }, navControllerFavorite = { },
@ -32,9 +44,24 @@ fun FavoritePage(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.background(colorBackground), .background(colorBackground),
contentAlignment = Alignment.Center contentAlignment = Alignment.TopCenter
){ ){
LazyColumn {
item{
Text(
text = "▶ Favoris ◀",
color = Color.White,
fontSize = 24.sp,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
textAlign = TextAlign.Center
)
}
items(quotes) { quote ->
QuoteLittle(quote)
}
}
} }
} }
} }
Loading…
Cancel
Save