From d554b87ab8b04b2c20720ddf09b08a464d472704 Mon Sep 17 00:00:00 2001 From: "kevin.modejar" Date: Mon, 17 Mar 2025 11:41:29 +0100 Subject: [PATCH] commentaire entity + stub / ajout get comment service / affichage ajout commentaire + liste commentaire / animation apparition commentaire --- .../data/local/CommentStub.kt | 39 +++++ .../what_the_fantasy/data/model/Comment.kt | 8 ++ .../data/services/IServices.kt | 3 +- .../data/services/ServicesAPI.kt | 5 + .../data/services/ServicesStub.kt | 4 + .../what_the_fantasy/ui/screens/QuotePage.kt | 135 +++++++++++++++--- .../app/src/main/res/values-fr/strings.xml | 1 + .../app/src/main/res/values/strings.xml | 1 + 8 files changed, 179 insertions(+), 17 deletions(-) create mode 100644 What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/CommentStub.kt create mode 100644 What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/Comment.kt diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/CommentStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/CommentStub.kt new file mode 100644 index 0000000..0009b0c --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/CommentStub.kt @@ -0,0 +1,39 @@ +package com.example.what_the_fantasy.data.local + +import com.example.what_the_fantasy.data.model.Comment +import com.example.what_the_fantasy.data.model.User + +object CommentStub { + val comments: MutableList = mutableListOf( + Comment("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Trop bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("encore un Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Je suis la ","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("J'en ai rien a foutre de la citation","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Android c'est bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("je sais plus quoi mettre donc ca va être le bordel","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Et un test de plus","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("La bombe à été activer","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("J'aime pas les *****","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Trop bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("encore un Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Je suis la ","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("J'en ai rien a foutre de la citation","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Android c'est bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("je sais plus quoi mettre donc ca va être le bordel","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Et un test de plus","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("La bombe à été activer","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("J'aime pas les *****","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Trop bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("encore un Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Je suis la ","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("J'en ai rien a foutre de la citation","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Android c'est bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("je sais plus quoi mettre donc ca va être le bordel","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Et un test de plus","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("La bombe à été activer","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("J'aime pas les *****","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + ) +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/Comment.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/Comment.kt new file mode 100644 index 0000000..2289d09 --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/Comment.kt @@ -0,0 +1,8 @@ +package com.example.what_the_fantasy.data.model + +data class Comment( + val content : String, + val user : String, + val date : String, + val img : String +) \ No newline at end of file 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 620ba60..8598128 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,5 +1,6 @@ package com.example.what_the_fantasy.data.services +import com.example.what_the_fantasy.data.model.Comment import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.data.model.User @@ -12,7 +13,7 @@ interface IServices { fun CreateUser(username : String, email : String, passwd : String, services : IServices) : Boolean fun getFavorite(username: String) fun getAllUsers(): List - + fun getComment(quoteId : Int) : List fun getUserById(id: Int): User? fun SearchQuote(quote : String) 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 facc895..5f85555 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,5 +1,6 @@ package com.example.what_the_fantasy.data.services +import com.example.what_the_fantasy.data.model.Comment 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 @@ -45,6 +46,10 @@ class ServicesAPI : IServices { TODO("Not yet implemented") } + override fun getComment(quoteId: Int): List { + TODO("Not yet implemented") + } + override fun getUserById(id: Int): User? { 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 995918e..354b228 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 @@ -5,7 +5,9 @@ import android.util.Log 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.CommentStub.comments import com.example.what_the_fantasy.data.local.QuoteStub +import com.example.what_the_fantasy.data.model.Comment 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 @@ -64,6 +66,8 @@ class ServicesStub : IServices { override fun getAllUsers(): List = users + override fun getComment(quoteId: Int): List = comments + override fun getUserById(id: Int): User? { return (users.find { it.id == id+1 }) } 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 2a6aa15..91448c4 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,16 +2,30 @@ package com.example.what_the_fantasy.ui.screens import android.content.Context import android.content.Intent +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.expandVertically +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.shrinkVertically +import androidx.compose.animation.slideInVertically +import androidx.compose.animation.slideOutVertically import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize 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.layout.width +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material.icons.automirrored.filled.Send import androidx.compose.material.icons.filled.Favorite import androidx.compose.material.icons.filled.FavoriteBorder import androidx.compose.material.icons.filled.MailOutline @@ -19,6 +33,7 @@ import androidx.compose.material.icons.filled.Share import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.Text +import androidx.compose.material3.TextField import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -37,6 +52,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.what_the_fantasy.R import coil.compose.AsyncImage +import com.example.what_the_fantasy.data.model.Comment 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 @@ -58,7 +74,7 @@ fun QuotePage( navProfil:(Int) -> Unit) { // utiliser ViewModel - var quote = service.getQuote(quoteId) ?: return + val quote = service.getQuote(quoteId) ?: return val context = LocalContext.current NavBar(onProfile = true, index = index, @@ -125,13 +141,27 @@ fun QuotePage( } } } - if(isCommentVisible){ - Box(modifier = Modifier.fillMaxWidth().background(Color.White)){ + AnimatedVisibility( + visible = isCommentVisible, + enter = expandVertically( + expandFrom = Alignment.CenterVertically + ) + fadeIn( + initialAlpha = 0.3f + ) + slideInVertically( + initialOffsetY = { -40 } + ), + exit = slideOutVertically() + shrinkVertically() + fadeOut() + ) { + Box(modifier = Modifier.fillMaxWidth().background(gradienBox).fillMaxSize()){ Column { - + AddComment(index) + LstComment(service.getComment(quoteId)) } } } + if(isCommentVisible){ + + } } } @@ -170,13 +200,13 @@ fun FunctionalIcon(isFavorite: Boolean, id : Int, context : Context){ val sendIntent = Intent().apply { action = Intent.ACTION_SEND // lien a changer quand le site sra deployer - putExtra(Intent.EXTRA_TEXT, "http://wfWebsite/quote/" + id.toString() ) + putExtra(Intent.EXTRA_TEXT, "http://wfWebsite/quote/$id") type = "text/plain" - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) // Ajout pour compatibilité + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } val shareIntent = Intent.createChooser(sendIntent, null) - shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) // Ajout aussi ici + shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) context.startActivity(shareIntent) }, @@ -190,13 +220,8 @@ fun FunctionalIcon(isFavorite: Boolean, id : Int, context : Context){ } IconButton( onClick = { - if(isCommentVisible){ - isCommentVisible = false - } - else{ - isCommentVisible = true - } - }, //Go to comment + isCommentVisible = !isCommentVisible + }, modifier = Modifier.padding(start = 20.dp) ){ Icon( @@ -208,7 +233,7 @@ fun FunctionalIcon(isFavorite: Boolean, id : Int, context : Context){ if(isFavorite){ IconButton( - onClick = { }, //Go to comment + onClick = { }, //sup fav modifier = Modifier.padding(start = 20.dp) ){ Icon( @@ -221,7 +246,7 @@ fun FunctionalIcon(isFavorite: Boolean, id : Int, context : Context){ } else{ IconButton( - onClick = { }, //Go to comment + onClick = { }, //add fav modifier = Modifier.padding(start = 50.dp) ){ Icon( @@ -274,4 +299,82 @@ fun LikeInfo(likes : Int){ ) } +@Composable +fun AddComment(userId : Int){ + var text by remember { mutableStateOf("") } + Row{ + IconButton( + onClick = { isCommentVisible = !isCommentVisible}, + ){ + Icon( + Icons.AutoMirrored.Filled.ArrowBack, + contentDescription = stringResource(R.string.send), + tint = iconText + ) + } + TextField( + value = text, + onValueChange = { text = it }, + label = { Text(stringResource(R.string.comment)) }, + modifier = Modifier.drawBehind { + drawRoundRect( + Color.White, + cornerRadius = CornerRadius(15.dp.toPx()) + ) + } + .width(300.dp) + ) + IconButton( + onClick = { }, //send comment + ){ + Icon( + Icons.AutoMirrored.Filled.Send, + contentDescription = stringResource(R.string.send), + tint = iconText + ) + } + } +} + +@Composable +fun LstComment(lst : List){ + LazyColumn( + verticalArrangement = Arrangement.spacedBy(4.dp), + ) { + items( + items = lst, + ) { + Column( + modifier = Modifier.padding(5.dp) + .fillMaxSize() + .drawBehind { + drawRoundRect( + Color.White, + cornerRadius = CornerRadius(15.dp.toPx()) + ) + } + ) { + Row { + AsyncImage( + model = it.img, + contentDescription = stringResource(R.string.profilePict), + modifier = Modifier + .size(50.dp) + .clip(RoundedCornerShape(50)) + ) + Text( + text = it.user + " " + it.date, + modifier = Modifier.padding(start = 15.dp) + ) + } + Row { + Text( + text = it.content, + modifier = Modifier.padding(15.dp), + ) + } + } + } + } +} diff --git a/What_The_Fantasy/app/src/main/res/values-fr/strings.xml b/What_The_Fantasy/app/src/main/res/values-fr/strings.xml index 47d0063..680c90d 100644 --- a/What_The_Fantasy/app/src/main/res/values-fr/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values-fr/strings.xml @@ -13,6 +13,7 @@ Favoris Likes Image de profil + Envoyer //Page Login Connexion au compte diff --git a/What_The_Fantasy/app/src/main/res/values/strings.xml b/What_The_Fantasy/app/src/main/res/values/strings.xml index 0771fb9..dd450d6 100644 --- a/What_The_Fantasy/app/src/main/res/values/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values/strings.xml @@ -12,6 +12,7 @@ favorite likes Profile picture + Send //Page Login Account login