diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/MainActivity.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/MainActivity.kt index cbed7f2..55db434 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/MainActivity.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/MainActivity.kt @@ -5,6 +5,7 @@ import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import com.example.what_the_fantasy.ui.navigations.AppNavigator +import com.example.what_the_fantasy.ui.screens.QuotePage import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme class MainActivity : ComponentActivity() { 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 1b66358..620ba60 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,6 +1,6 @@ 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.Quote import com.example.what_the_fantasy.data.model.User interface IServices { @@ -17,6 +17,8 @@ interface IServices { fun SearchQuote(quote : String) + fun getQuote( id : Int): Quote? + fun isFavorite(id : Int): Boolean } \ No newline at end of file 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 25cd320..facc895 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,6 +1,8 @@ package com.example.what_the_fantasy.data.services +import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.data.model.User +import com.example.what_the_fantasy.ui.navigations.Destination class ServicesAPI : IServices { override fun EditUsername(username: String, index : Int) { @@ -27,6 +29,14 @@ class ServicesAPI : IServices { TODO("Not yet implemented") } + override fun getQuote(id: Int): Quote? { + TODO("Not yet implemented") + } + + override fun isFavorite(id: Int): Boolean { + TODO("Not yet implemented") + } + override fun getFavorite(username: String) { TODO("Not yet implemented") } 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 70745e7..995918e 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 @@ -2,10 +2,11 @@ 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.Logs.LogsUsers +import com.example.what_the_fantasy.data.local.QuoteStub +import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.data.model.SrcLanguage import com.example.what_the_fantasy.ui.components.hashPassword import java.time.LocalDate @@ -71,6 +72,14 @@ class ServicesStub : IServices { TODO("Not yet implemented") } + override fun getQuote(id: Int): Quote? { + return (QuoteStub.allQuotes.find { it.id == id }) + } + + override fun isFavorite(id: Int): Boolean { + TODO("Not yet implemented") + } + override fun getFavorite(username: String) { TODO("Not yet implemented") } 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 c249a68..7a7936e 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 @@ -34,7 +34,7 @@ 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 +data class Quote(val quoteId: Int, val userIndex : Int) @Serializable data object Search @Serializable @@ -51,7 +51,9 @@ sealed class Destination(val route: String) { 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 Quote : Destination("Quote/{quoteId}"){ + fun createRoute(quoteId : Int) = "Profil/$quoteId" + } data object Search : Destination("Search") data object SignUp : Destination("SignUp") data object SubmitQuote : Destination("SubmitQuote") @@ -89,7 +91,7 @@ fun AppNavigator() { navAccueil ={ navController.navigate( Accueil(favorite.userIndex) ) }, navQuiz = { navController.navigate(QuizMenu(favorite.userIndex)) }, navProfil = { navController.navigate(Profil(favorite.userIndex)) }, - navQuote = {navController.navigate(Quote)} + navQuote = { quoteId -> navController.navigate(Quote(quoteId,favorite.userIndex))} ) } composable{ val profil:Profil = it.toRoute() @@ -107,11 +109,18 @@ fun AppNavigator() { services = services ) } - composable { composable(Destination.Quote.route) { backStackEntry -> - // Récupère l'index passé dans la route - val index = backStackEntry.arguments?.getString("userIndex")?.toInt() ?: -1 - QuotePage(quoteId = index)//, navController = navController) - } } + composable{ + val quote:Quote = it.toRoute() + QuotePage( + quoteId = quote.quoteId, + index = quote.userIndex, + navAccueil ={ navController.navigate( Accueil(quote.userIndex) ) }, + navQuiz = { navController.navigate(QuizMenu(quote.userIndex)) }, + navProfil = { navController.navigate(Profil(quote.userIndex)) }, + navFavorite = { navController.navigate(Favorite(quote.userIndex)) }, + service = services + ) + } composable { SearchPage() } composable { SignUpPage( navControllerLogin = { 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 2d34fb8..6874a50 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 @@ -28,7 +28,7 @@ fun FavoritePage( navAccueil: (Int) -> Unit, navQuiz: (Int) -> Unit, navProfil: (Int) -> Unit, - navQuote:() -> Unit + navQuote: (Int) -> Unit ) { NavBar( onFavorite = true, @@ -57,7 +57,7 @@ fun FavoritePage( horizontalAlignment = Alignment.CenterHorizontally ) { items(QuoteStub.allQuotes) { quote -> - Column (Modifier.clickable { navQuote()}){ + Column (Modifier.clickable { navQuote(quote.id)}){ LittleQuoteComponent(quote) Spacer(modifier = Modifier.height(16.dp)) 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 056d0ce..16dcfac 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 @@ -2,7 +2,6 @@ package com.example.what_the_fantasy.ui.screens import android.content.Context import android.content.Intent -import android.net.Uri import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -32,11 +31,10 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight 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.model.Quote import coil.compose.AsyncImage -import com.example.what_the_fantasy.data.local.QuoteStub +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 import com.example.what_the_fantasy.ui.theme.gradienBox import com.example.what_the_fantasy.ui.theme.iconText @@ -44,65 +42,87 @@ import com.example.what_the_fantasy.ui.theme.likeIcon import com.example.what_the_fantasy.ui.theme.whiteBackcgroundText @Composable -fun QuotePage(quoteId : Int) { - var quote : Quote= QuoteStub.quote1 // service -> GetQuote(id) +fun QuotePage( + quoteId : Int, + service : IServices, + index : Int, + navAccueil: (Int) -> Unit, + navFavorite:(Int) -> Unit, + navQuiz: (Int) -> Unit, + navProfil:(Int) -> Unit) +{ + var quote = service.getQuote(quoteId) ?: return val context = LocalContext.current - Box( - modifier = Modifier - .fillMaxSize() - .background(colorBackground), - contentAlignment = Alignment.Center + NavBar(onProfile = true, + index = index, + navControllerFavorite = navFavorite, + navControllerAccueil = navAccueil, + navControllerProfil = navProfil, + navControllerQuiz = navQuiz ) { - Column(modifier = Modifier - .padding(15.dp) - .drawBehind { - drawRoundRect( - gradienBox, - cornerRadius = CornerRadius(15.dp.toPx()), - ) - } + Box( + modifier = Modifier + .fillMaxSize() + .background(colorBackground), + contentAlignment = Alignment.Center ) { - Row(modifier = Modifier.padding(15.dp)) { - ImageQuote( - imageUrl = quote.imgUrl - ) - Column { - - FunctionalIcon( - // --/!\-- a modifier --/!\-- - // service -> isFavorite(id) - true, - id = quoteId, - context = context + Column(modifier = Modifier + .padding(15.dp) + .drawBehind { + drawRoundRect( + gradienBox, + cornerRadius = CornerRadius(15.dp.toPx()), ) - QuoteText( - text = '"' + quote.content + '"' + } + ) { + Row(modifier = Modifier.padding(15.dp)) { + ImageQuote( + imageUrl = quote.imgUrl ) + Column { + + FunctionalIcon( + // --/!\-- a modifier --/!\-- + // isFavorite = service.isFavorite(id) + // -------------------------- + true, + id = quoteId, + context = context + ) + QuoteText( + text = '"' + quote.content + '"' + ) + } } - } - Column(modifier = Modifier.padding(15.dp)) { - InfoQuoteText( - nameId = R.string.source, - text = quote.source - ) - InfoQuoteText( - nameId = R.string.charac, - text = quote.character - ) - Row( - modifier = Modifier - .padding(top = 10.dp) - .align(alignment = Alignment.End) + Column(modifier = Modifier + .padding(15.dp) + .fillMaxWidth() ) { - LikeInfo( - likes = quote.likes + InfoQuoteText( + nameId = R.string.source, + text = quote.source + ) + InfoQuoteText( + nameId = R.string.charac, + text = quote.character ) + Row( + modifier = Modifier + .padding(top = 10.dp) + .align(alignment = Alignment.End) + ) { + LikeInfo( + likes = quote.likes + ) + } } } } } } +// ------------------ Composants non partager de la page -------------------------------------- + @Composable fun QuoteText(text: String ){ Text(