From 38038c793994ecf81ae7d4b903dadcce106b3ab9 Mon Sep 17 00:00:00 2001 From: "maxime.rocher" Date: Mon, 3 Mar 2025 11:54:52 +0100 Subject: [PATCH] =?UTF-8?q?=E2=98=9D=F0=9F=A4=93=E2=80=8Bbon=20debut=20mai?= =?UTF-8?q?n=20manque=20seulement=20la=20DailyQuote?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- What_The_Fantasy/app/build.gradle.kts | 1 + .../ui/components/QuoteLittle.kt | 108 +++++++++++------- .../ui/navigations/AppNavigator.kt | 21 ++-- .../ui/screens/AccueilPage.kt | 56 ++++++--- 4 files changed, 120 insertions(+), 66 deletions(-) diff --git a/What_The_Fantasy/app/build.gradle.kts b/What_The_Fantasy/app/build.gradle.kts index a38d9d3..cda6e9d 100644 --- a/What_The_Fantasy/app/build.gradle.kts +++ b/What_The_Fantasy/app/build.gradle.kts @@ -50,6 +50,7 @@ android { } dependencies { + implementation("io.coil-kt:coil-compose:1.4.0") implementation(libs.bcrypt) // pour hacher les mdp implementation(libs.androidx.core.ktx) implementation(libs.androidx.lifecycle.runtime.ktx) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/QuoteLittle.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/QuoteLittle.kt index 96aca58..ffc331e 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/QuoteLittle.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/QuoteLittle.kt @@ -1,59 +1,87 @@ package com.example.what_the_fantasy.ui.components +import androidx.compose.foundation.Image +import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +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.shape.RoundedCornerShape import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.drawBehind -import androidx.compose.ui.geometry.CornerRadius +import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import coil.compose.rememberAsyncImagePainter +import coil.compose.rememberImagePainter import com.example.what_the_fantasy.data.model.Quote +import com.example.what_the_fantasy.ui.theme.colorBackground +import com.example.what_the_fantasy.ui.theme.gradienBox @Composable -fun QuoteLittle(quote: Quote, modifier: Modifier) { - Column(modifier = modifier.padding(10.dp).drawBehind { - drawRoundRect( - Color(70,190,115), - cornerRadius = CornerRadius(10.dp.toPx()) - ) - }.size(500.dp, 600.dp)) - { - Text( - text = '"'+quote.content+'"' - - ) - InfoQuoteText( - name = "@string/source", - text = quote.source - ) - InfoQuoteText( - name = "@string/charac", - text = quote.character - ) - } -} - -@Composable -fun InfoQuoteText(name : String, text : String){ - Column{ - Text( - text = name +fun QuoteLittle(quote: Quote, modifier: Modifier = Modifier) { + Row( + modifier = modifier + .fillMaxWidth() + .padding(8.dp) + .clip(RoundedCornerShape(16.dp)) + .background(colorBackground) + ) { + Image( + painter = rememberAsyncImagePainter(quote.imgUrl), + contentDescription = "Character Image", + contentScale = ContentScale.Crop, + modifier = Modifier + .size(width = 135.dp, height = 135.dp) + .clip( + RoundedCornerShape( + topStart = 12.dp, + bottomStart = 12.dp, + topEnd = 0.dp, + bottomEnd = 0.dp + ) + ) ) - Text( - text = text, + Column( modifier = Modifier - .drawBehind { - drawRoundRect( - Color(255,255,255), - cornerRadius = CornerRadius(15.dp.toPx()) + .weight(1f) + .height(135.dp) + .clip( + RoundedCornerShape( + topEnd = 12.dp, + bottomEnd = 12.dp ) - } - .padding(5.dp) - ) + ) + .background(gradienBox) + .padding(12.dp) + ) { + Text( + text = quote.content, + color = Color.White, + fontSize = 16.sp, + maxLines = 2, + overflow = TextOverflow.Ellipsis + ) + Spacer(modifier = Modifier.height(8.dp)) + + Text( + text = "Film : ${quote.source}", + color = Color.White, + fontSize = 12.sp + ) + Text( + text = "Personnage : ${quote.character}", + color = Color.White, + fontSize = 12.sp + ) + } } } - 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 5ab890c..9b98a52 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 @@ -64,20 +64,27 @@ fun AppNavigator() { services ) } - composable(Destination.Accueil.route) { - val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 + composable(Destination.Accueil.route) { backStackEntry -> + val userIndex = backStackEntry.arguments?.getString("userIndex")?.toInt() ?: -1 AccueilPage( index = userIndex, navFavorite = { userIndex -> - navController.navigate(Destination.Favorite.createRoute(userIndex)) // Passe l'index à Profil + navController.navigate(Destination.Favorite.createRoute(userIndex)) { + popUpTo(Destination.Accueil.createRoute(userIndex)) { inclusive = false } + } }, - navQuiz = { userIndex -> - navController.navigate(Destination.QuizMenu.createRoute(userIndex)) // Passe l'index à Profil + navQuiz = { userIndex -> + 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 + navController.navigate(Destination.Profil.createRoute(userIndex)) { + popUpTo(Destination.Accueil.createRoute(userIndex)) { inclusive = false } + } } - ) } + ) + } composable(Destination.Favorite.route) { val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 FavoritePage( 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 f56508f..4f28696 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,42 +1,60 @@ 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.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material3.Button import androidx.compose.material3.Text -import androidx.compose.runtime.Composable +import androidx.compose.runtime.* 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 androidx.compose.ui.unit.dp +import com.example.what_the_fantasy.data.local.QuoteStub 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 @Composable fun AccueilPage( index: Int, - navFavorite:(Int) -> Unit, + navFavorite: (Int) -> Unit, navQuiz: (Int) -> Unit, - navProfil:(Int) -> Unit + navProfil: (Int) -> Unit ) { - NavBar(onAccueil = true, + var itemCount by remember { mutableStateOf(15) } // On affiche 15 quotes au début + + val quotes = QuoteStub.allQuotes.take(itemCount) + + NavBar( + onAccueil = true, index = index, navControllerFavorite = navFavorite, - navControllerAccueil = { }, + navControllerAccueil = { }, navControllerProfil = navProfil, navControllerQuiz = navQuiz - ){ - Box( + ) { + Column( modifier = Modifier .fillMaxSize() - .background(colorBackground), - contentAlignment = Alignment.Center - ){ - Column { - Text("Accueil", color = Color.White, fontSize = 20.sp) + .background(colorBackground) + ) { + LazyColumn(modifier = Modifier.weight(1f)) { + items(quotes) { quote -> + QuoteLittle(quote) + } + + // Si on a encore des éléments à charger, on affiche le bouton + if (itemCount < QuoteStub.allQuotes.size) { + item { + Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { + Button(onClick = { itemCount += 15 }) { + Text("Charger plus") + } + } + } + } } } } -} \ No newline at end of file +}