Favoris remarche avec une liste

pull/47/head
Leni BEAULATON 1 month ago
parent 723dd0d6bd
commit bd33430739

@ -6,16 +6,16 @@ import com.example.what_the_fantasy.data.model.Favorite
object FavoriteStub { object FavoriteStub {
val favorites: MutableList<Favorite> = mutableListOf( val favorites: MutableList<Favorite> = mutableListOf(
Favorite(users[0], listOf(quotes[0], quotes[3], quotes[4])), // Aragorn123 aime ces citations Favorite(users[0], mutableListOf(quotes[0], quotes[0], quotes[0])), // Aragorn123 aime ces citations
Favorite(users[1], listOf(quotes[5], quotes[6], quotes[7])), // Legolas456 aime ces citations Favorite(users[1], mutableListOf(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[2], mutableListOf(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[3], mutableListOf(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[4], mutableListOf(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[5], mutableListOf(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[6], mutableListOf(quotes[17], quotes[2], quotes[7])), // Boromir654 aime ces citations
Favorite(users[7], listOf(quotes[3], quotes[4], quotes[10])), // Eowyn777 aime ces citations Favorite(users[7], mutableListOf(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[8], mutableListOf(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[9], mutableListOf(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[10], mutableListOf(quotes[12], quotes[17], quotes[16])) // dev aime ces citations
) )
} }

@ -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.Quote
import com.example.what_the_fantasy.data.model.SrcLanguage 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.SrcType
import com.example.what_the_fantasy.data.model.User
object QuoteStub { 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(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(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(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)
) )
} }

@ -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.Quote
import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.model.User
class ServicesAPI : IServices { //class ServicesAPI : IServices {
override fun EditUsername(username: String, index : Int) : Boolean { // override fun EditUsername(username: String, index : Int) : Boolean {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
override fun EditEmail(email: String, index : Int) : Boolean { // override fun EditEmail(email: String, index : Int) : Boolean {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
override fun EditPasswd(passwd: String, index : Int) { // override fun EditPasswd(passwd: String, index : Int) {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
override fun EditImage(imageURL: String, index : Int) { // override fun EditImage(imageURL: String, index : Int) {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
override fun ChangeLangage(user: User) { // override fun ChangeLangage(user: User) {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
override fun CreateUser(username: String, email: String, passwd: String, services: IServices) : Boolean { // override fun CreateUser(username: String, email: String, passwd: String, services: IServices) : Boolean {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
override fun SearchQuote(quote: String) { // override fun SearchQuote(quote: String) {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
override fun getQuote(id: Int): Quote? { // override fun getQuote(id: Int): Quote? {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
override fun isFavorite(id: Int): Boolean { // override fun isFavorite(id: Int): Boolean {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
override fun getAllFavorite(): List<Favorite> { // override fun getAllFavorite(): List<Favorite> {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
override fun getAllQuote(): List<Quote> { // override fun getAllQuote(): List<Quote> {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
override fun getFavorite(user: User): List<Quote> { // override fun getFavorite(user: User): Favorite {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
override fun getAllUsers(): List<User> { // override fun getAllUsers(): List<User> {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
override fun getUserById(id: Int): User? { // override fun getUserById(id: Int): User? {
TODO("Not yet implemented") // TODO("Not yet implemented")
} // }
//
} //}

@ -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.local.UserStub.users
import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.model.User
import com.example.what_the_fantasy.Logs.LogsUsers 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.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.local.QuoteStub.quotes
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 import com.example.what_the_fantasy.data.model.Quote
@ -84,11 +82,11 @@ class ServicesStub : IServices {
} }
override fun getFavorite(user: User): List<Quote> { override fun getFavorite(user: User): List<Quote> {
val favoriteStub = getAllFavorite() val favorite = favorites
return favoriteStub return favorite[0].quote
.filter { it.user.username == user.username } //return emptyList()
.flatMap { it.quote }
} }
override fun getAllFavorite(): List<Favorite> = favorites override fun getAllFavorite(): List<Favorite> = favorites
override fun getAllQuote(): List<Quote> = quotes override fun getAllQuote(): List<Quote> = quotes
override fun getAllUsers(): List<User> = users override fun getAllUsers(): List<User> = users

@ -17,7 +17,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import com.example.what_the_fantasy.R import com.example.what_the_fantasy.R
import com.example.what_the_fantasy.data.local.DailyQuoteStub 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.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.components.QuoteLittle

@ -1,5 +1,6 @@
package com.example.what_the_fantasy.ui.screens package com.example.what_the_fantasy.ui.screens
import android.util.Log
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
@ -31,7 +32,9 @@ fun FavoritePage(
services: IServices services: IServices
) { ) {
val user = services.getUserById(index) ?: return val user = services.getUserById(index) ?: return
val quotes = services.getFavorite(user) val quotes = services.getFavorite(user)
val TitlePage = stringResource(R.string.TitleFavorite) val TitlePage = stringResource(R.string.TitleFavorite)
NavBar(onFavorite = true, NavBar(onFavorite = true,
index = index, index = index,
@ -45,9 +48,9 @@ fun FavoritePage(
.fillMaxSize() .fillMaxSize()
.background(colorBackground), .background(colorBackground),
contentAlignment = Alignment.TopCenter contentAlignment = Alignment.TopCenter
){ ) {
LazyColumn { LazyColumn {
item{ item {
Text( Text(
text = TitlePage, text = TitlePage,
color = Color.White, color = Color.White,
@ -59,9 +62,8 @@ fun FavoritePage(
) )
} }
items(quotes) { quote -> items(quotes) { quote ->
Column (Modifier.clickable { navQuote( quote.id )} ){ Column(Modifier.clickable { navQuote(quote.id) }) {
QuoteLittle(quote) QuoteLittle(quote)
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
} }
} }

Loading…
Cancel
Save