From bd33430739e80d9c71932c31381071f6d0ef2b94 Mon Sep 17 00:00:00 2001 From: "leni.beaulaton" Date: Fri, 14 Mar 2025 19:27:35 +0100 Subject: [PATCH] Favoris remarche avec une liste --- .../data/local/FavoriteStub.kt | 22 ++-- .../what_the_fantasy/data/local/QuoteStub.kt | 3 +- .../data/services/ServicesAPI.kt | 116 +++++++++--------- .../data/services/ServicesStub.kt | 10 +- .../ui/screens/AccueilPage.kt | 1 - .../ui/screens/FavoritePage.kt | 10 +- 6 files changed, 80 insertions(+), 82 deletions(-) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/FavoriteStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/FavoriteStub.kt index 8471a05..b092123 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/FavoriteStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/FavoriteStub.kt @@ -6,16 +6,16 @@ import com.example.what_the_fantasy.data.model.Favorite object FavoriteStub { val favorites: MutableList = mutableListOf( - Favorite(users[0], listOf(quotes[0], quotes[3], quotes[4])), // Aragorn123 aime ces citations - Favorite(users[1], listOf(quotes[5], quotes[6], quotes[7])), // Legolas456 aime ces citations - Favorite(users[2], listOf(quotes[8], quotes[9], quotes[10])), // Gandalf789 aime ces citations - Favorite(users[3], listOf(quotes[11], quotes[12], quotes[13])), // FrodoBaggins aime ces citations - Favorite(users[4], listOf(quotes[14], quotes[15], quotes[16])), // Gimli999 aime ces citations - Favorite(users[5], listOf(quotes[17], quotes[18], quotes[19])), // Galadriel321 aime ces citations - Favorite(users[6], listOf(quotes[20], quotes[2], quotes[7])), // Boromir654 aime ces citations - Favorite(users[7], listOf(quotes[3], quotes[4], quotes[10])), // Eowyn777 aime ces citations - Favorite(users[8], listOf(quotes[6], quotes[8], quotes[9])), // Saruman888 aime ces citations - Favorite(users[9], listOf(quotes[5], quotes[13], quotes[15])), // Faramir222 aime ces citations - Favorite(users[10], listOf(quotes[12], quotes[17], quotes[16])) // dev aime ces citations + Favorite(users[0], mutableListOf(quotes[0], quotes[0], quotes[0])), // Aragorn123 aime ces citations + Favorite(users[1], mutableListOf(quotes[5], quotes[6], quotes[7])), // Legolas456 aime ces citations + Favorite(users[2], mutableListOf(quotes[8], quotes[9], quotes[10])), // Gandalf789 aime ces citations + Favorite(users[3], mutableListOf(quotes[11], quotes[12], quotes[13])), // FrodoBaggins aime ces citations + Favorite(users[4], mutableListOf(quotes[14], quotes[15], quotes[16])), // Gimli999 aime ces citations + Favorite(users[5], mutableListOf(quotes[17], quotes[18], quotes[19])), // Galadriel321 aime ces citations + Favorite(users[6], mutableListOf(quotes[17], quotes[2], quotes[7])), // Boromir654 aime ces citations + Favorite(users[7], mutableListOf(quotes[3], quotes[4], quotes[10])), // Eowyn777 aime ces citations + Favorite(users[8], mutableListOf(quotes[6], quotes[8], quotes[9])), // Saruman888 aime ces citations + Favorite(users[9], mutableListOf(quotes[5], quotes[13], quotes[15])), // Faramir222 aime ces citations + Favorite(users[10], mutableListOf(quotes[12], quotes[17], quotes[16])) // dev aime ces citations ) } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuoteStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuoteStub.kt index 102cd90..36e2909 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuoteStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuoteStub.kt @@ -3,7 +3,6 @@ package com.example.what_the_fantasy.data.local import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.data.model.SrcLanguage import com.example.what_the_fantasy.data.model.SrcType -import com.example.what_the_fantasy.data.model.User object QuoteStub { @@ -27,6 +26,6 @@ object QuoteStub { Quote(17, "Le courage n'est pas l'absence de peur, mais la capacité de vaincre ce qui fait peur.", 300, SrcLanguage.vf, CharacterStub.boromir.name, "Nelson Mandela", CharacterStub.boromir.imgUrl, SrcType.Movie, 2000), Quote(18, "La folie, c'est de faire toujours la même chose et de s'attendre à un résultat différent.", 400, SrcLanguage.vf, CharacterStub.eowyn.name, "Albert Einstein", CharacterStub.eowyn.imgUrl, SrcType.Movie, 2000), Quote(19, "Le bonheur n'est pas quelque chose de tout fait. Il vient de vos propres actions.", 500, SrcLanguage.vo, CharacterStub.saruman.name, "Dalaï Lama", CharacterStub.saruman.imgUrl, SrcType.Movie, 2000), - Quote(20, "La vie est un mystère qu'il faut vivre, et non un problème à résoudre.", 600, SrcLanguage.vf, CharacterStub.samwiseGamgee.name, "Gandhi", CharacterStub.samwiseGamgee.imgUrl, SrcType.Movie, 2000) + Quote(20, "La vie est un mystère qu'il faut vivre, et non un problème à résoudre.", 600, SrcLanguage.vo, CharacterStub.samwiseGamgee.name, "Gandhi", CharacterStub.samwiseGamgee.imgUrl, SrcType.Movie, 2000) ) } \ 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 875710f..e7595df 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 @@ -4,61 +4,61 @@ import com.example.what_the_fantasy.data.model.Favorite import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.data.model.User -class ServicesAPI : IServices { - override fun EditUsername(username: String, index : Int) : Boolean { - TODO("Not yet implemented") - } - - override fun EditEmail(email: String, index : Int) : Boolean { - TODO("Not yet implemented") - } - - override fun EditPasswd(passwd: String, index : Int) { - TODO("Not yet implemented") - } - - override fun EditImage(imageURL: String, index : Int) { - TODO("Not yet implemented") - } - - override fun ChangeLangage(user: User) { - TODO("Not yet implemented") - } - - override fun CreateUser(username: String, email: String, passwd: String, services: IServices) : Boolean { - TODO("Not yet implemented") - } - - override fun SearchQuote(quote: String) { - 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 getAllFavorite(): List { - TODO("Not yet implemented") - } - - override fun getAllQuote(): List { - TODO("Not yet implemented") - } - - override fun getFavorite(user: User): List { - TODO("Not yet implemented") - } - - override fun getAllUsers(): List { - TODO("Not yet implemented") - } - - override fun getUserById(id: Int): User? { - TODO("Not yet implemented") - } - -} \ No newline at end of file +//class ServicesAPI : IServices { +// override fun EditUsername(username: String, index : Int) : Boolean { +// TODO("Not yet implemented") +// } +// +// override fun EditEmail(email: String, index : Int) : Boolean { +// TODO("Not yet implemented") +// } +// +// override fun EditPasswd(passwd: String, index : Int) { +// TODO("Not yet implemented") +// } +// +// override fun EditImage(imageURL: String, index : Int) { +// TODO("Not yet implemented") +// } +// +// override fun ChangeLangage(user: User) { +// TODO("Not yet implemented") +// } +// +// override fun CreateUser(username: String, email: String, passwd: String, services: IServices) : Boolean { +// TODO("Not yet implemented") +// } +// +// override fun SearchQuote(quote: String) { +// 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 getAllFavorite(): List { +// TODO("Not yet implemented") +// } + +// override fun getAllQuote(): List { +// TODO("Not yet implemented") +// } +// +// override fun getFavorite(user: User): Favorite { +// TODO("Not yet implemented") +// } +// +// override fun getAllUsers(): List { +// TODO("Not yet implemented") +// } +// +// override fun getUserById(id: Int): User? { +// TODO("Not yet implemented") +// } +// +//} \ No newline at end of file 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 3f27112..7e8eab0 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 @@ -4,9 +4,7 @@ import android.annotation.SuppressLint 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.FavoriteStub import com.example.what_the_fantasy.data.local.FavoriteStub.favorites -import com.example.what_the_fantasy.data.local.QuoteStub import com.example.what_the_fantasy.data.local.QuoteStub.quotes import com.example.what_the_fantasy.data.model.Favorite import com.example.what_the_fantasy.data.model.Quote @@ -84,11 +82,11 @@ class ServicesStub : IServices { } override fun getFavorite(user: User): List { - val favoriteStub = getAllFavorite() - return favoriteStub - .filter { it.user.username == user.username } - .flatMap { it.quote } + val favorite = favorites + return favorite[0].quote + //return emptyList() } + override fun getAllFavorite(): List = favorites override fun getAllQuote(): List = quotes override fun getAllUsers(): List = users 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 86c9691..1047e48 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 @@ -17,7 +17,6 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.DailyQuoteStub -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.components.QuoteLittle 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 dde6bce..cfcf08b 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 @@ -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.* @@ -31,7 +32,9 @@ fun FavoritePage( services: IServices ) { val user = services.getUserById(index) ?: return + val quotes = services.getFavorite(user) + val TitlePage = stringResource(R.string.TitleFavorite) NavBar(onFavorite = true, index = index, @@ -45,9 +48,9 @@ fun FavoritePage( .fillMaxSize() .background(colorBackground), contentAlignment = Alignment.TopCenter - ){ + ) { LazyColumn { - item{ + item { Text( text = TitlePage, color = Color.White, @@ -59,9 +62,8 @@ fun FavoritePage( ) } items(quotes) { quote -> - Column (Modifier.clickable { navQuote( quote.id )} ){ + Column(Modifier.clickable { navQuote(quote.id) }) { QuoteLittle(quote) - Spacer(modifier = Modifier.height(16.dp)) } }