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 b092123..b977a10 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,7 +6,7 @@ import com.example.what_the_fantasy.data.model.Favorite object FavoriteStub { val favorites: MutableList = mutableListOf( - Favorite(users[0], mutableListOf(quotes[0], quotes[0], quotes[0])), // Aragorn123 aime ces citations + Favorite(users[0], mutableListOf(quotes[0], quotes[1], quotes[12])), // 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 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 142b022..0ff0c06 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 @@ -25,7 +25,7 @@ interface IServices { fun getQuote( id : Int): Quote? - fun isFavorite(id : Int): Boolean + fun isFavorite(id : Int, user: User): Boolean fun getAllFavorite(): List fun getAllQuote(): List } \ 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 e8d6676..0155073 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 @@ -55,7 +55,7 @@ class ServicesAPI : IServices { TODO("Not yet implemented") } - override fun isFavorite(id: Int): Boolean { + override fun isFavorite(id: Int, user: User): Boolean { 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 60607bb..8206708 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 @@ -76,6 +76,7 @@ class ServicesStub : IServices { } override fun AddComment(content: String) { + return TODO("Not yet implemented") //comments.add(Comment(content = content,)) } @@ -100,7 +101,7 @@ class ServicesStub : IServices { override fun getFavorite(user: User): List { val favorite = favorites - return favorite[0].quote + return favorite[user.id-1].quote //return emptyList() } @@ -119,11 +120,12 @@ class ServicesStub : IServices { } override fun getQuote(id: Int): Quote? { - return (quotes.find { it.id == id+1 }) + return (quotes.find { it.id == id }) } - override fun isFavorite(id: Int): Boolean { - TODO("Not yet implemented") + override fun isFavorite(id: Int, user: User): Boolean { + var quote = getFavorite(user) + return quote.find{ it.id == id } != null } 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 094431b..db092f5 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 @@ -32,6 +32,7 @@ import androidx.compose.material.icons.filled.MailOutline import androidx.compose.material.icons.filled.Share import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TextField import androidx.compose.runtime.Composable @@ -76,7 +77,10 @@ fun QuotePage( // utiliser ViewModel val quote = service.getQuote(quoteId) ?: return val context = LocalContext.current - NavBar(onProfile = true, + val user = service.getUserById(index) ?: return + val favorite by remember { mutableStateOf(service.isFavorite(id = quoteId, user = user)) } + + NavBar( index = index, navControllerFavorite = navFavorite, navControllerAccueil = navAccueil, @@ -86,17 +90,15 @@ fun QuotePage( Box( modifier = Modifier .fillMaxSize() - .background(colorBackground), + .background(MaterialTheme.colorScheme.background), contentAlignment = Alignment.Center ) { Column(modifier = Modifier .padding(15.dp) - .drawBehind { - drawRoundRect( - gradienBox, - cornerRadius = CornerRadius(15.dp.toPx()), - ) - } + .background( + color = MaterialTheme.colorScheme.primary, + shape = RoundedCornerShape(15.dp) + ) ) { Row(modifier = Modifier.padding(15.dp)) { ImageQuote( @@ -105,10 +107,7 @@ fun QuotePage( Column { FunctionalIcon( - // --/!\-- a modifier --/!\-- - // isFavorite = service.isFavorite(id) - // -------------------------- - false, + isFavorite = favorite, userId = index, id = quoteId, context = context, @@ -154,7 +153,7 @@ fun QuotePage( ), exit = slideOutVertically() + shrinkVertically() + fadeOut() ) { - Box(modifier = Modifier.fillMaxWidth().background(gradienBox).fillMaxSize()){ + Box(modifier = Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.primary).fillMaxSize()){ Column { AddComment(index, service) LstComment(service.getComment(quoteId)) @@ -173,7 +172,7 @@ fun QuoteText(text: String ){ modifier = Modifier.padding(start = 10.dp, top = 15.dp), fontWeight = FontWeight(1000), fontSize = 20.sp, - color = iconText + color = MaterialTheme.colorScheme.onPrimary ) } @@ -214,7 +213,7 @@ fun FunctionalIcon(isFavorite: Boolean, userId : Int, id : Int, context : Contex Icon( Icons.Default.Share, contentDescription = stringResource(R.string.share), - tint = iconText, + tint = MaterialTheme.colorScheme.onPrimary, ) } IconButton( @@ -226,7 +225,7 @@ fun FunctionalIcon(isFavorite: Boolean, userId : Int, id : Int, context : Contex Icon( Icons.Default.MailOutline, contentDescription = stringResource(R.string.comment), - tint = iconText, + tint = MaterialTheme.colorScheme.onPrimary, ) } @@ -238,7 +237,7 @@ fun FunctionalIcon(isFavorite: Boolean, userId : Int, id : Int, context : Contex Icon( Icons.Default.Favorite, contentDescription = stringResource(R.string.favorite), - tint = likeIcon, + tint = MaterialTheme.colorScheme.onPrimary, ) } @@ -251,7 +250,7 @@ fun FunctionalIcon(isFavorite: Boolean, userId : Int, id : Int, context : Contex Icon( Icons.Default.FavoriteBorder, contentDescription = stringResource(R.string.favorite), - tint = iconText + tint = MaterialTheme.colorScheme.onPrimary ) } } @@ -265,22 +264,20 @@ fun InfoQuoteText(nameId : Int, text : String){ text = stringResource(id = nameId), fontSize = 18.sp, fontWeight = FontWeight(500), - color = iconText + color = MaterialTheme.colorScheme.onPrimary ) Text( text = text, - color = whiteBackcgroundText, + color = MaterialTheme.colorScheme.onBackground, fontSize = 16.sp, fontWeight = FontWeight(400), modifier = Modifier - .drawBehind { - drawRoundRect( - Color(255,255,255), - cornerRadius = CornerRadius(15.dp.toPx()) - ) - } - .padding(5.dp), + .background( + color = MaterialTheme.colorScheme.background, + shape = RoundedCornerShape(15.dp) + ) + .padding(5.dp) ) } } @@ -289,12 +286,12 @@ fun InfoQuoteText(nameId : Int, text : String){ fun LikeInfo(likes : Int){ Text( text = likes.toString(), - color = iconText + color = MaterialTheme.colorScheme.onPrimary ) Icon( Icons.Default.Favorite, contentDescription = stringResource(R.string.favorite), - tint = iconText, + tint = MaterialTheme.colorScheme.onPrimary, ) } @@ -308,19 +305,14 @@ fun AddComment(userId : Int, service: IServices){ Icon( Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(R.string.send), - tint = iconText + tint = MaterialTheme.colorScheme.onPrimary ) } TextField( value = text, onValueChange = { text = it }, label = { Text(stringResource(R.string.comment)) }, - modifier = Modifier.drawBehind { - drawRoundRect( - Color.White, - cornerRadius = CornerRadius(15.dp.toPx()) - ) - } + modifier = Modifier .width(300.dp) ) IconButton( @@ -329,7 +321,7 @@ fun AddComment(userId : Int, service: IServices){ Icon( Icons.AutoMirrored.Filled.Send, contentDescription = stringResource(R.string.send), - tint = iconText + tint = MaterialTheme.colorScheme.onPrimary ) } } @@ -346,12 +338,10 @@ fun LstComment(lst : List){ Column( modifier = Modifier.padding(5.dp) .fillMaxSize() - .drawBehind { - drawRoundRect( - Color.White, - cornerRadius = CornerRadius(15.dp.toPx()) - ) - } + .background( + color = MaterialTheme.colorScheme.onPrimary, + shape = RoundedCornerShape(15.dp) + ) ) { Row { AsyncImage(