@ -1,5 +1,6 @@
package com.example.veraxapplication.ui.article
package com.example.veraxapplication.ui.article
import android.util.Log
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.background
@ -7,8 +8,10 @@ import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.verticalScroll
@ -28,6 +31,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.unit.sp
import coil.compose.rememberImagePainter
import coil.compose.rememberImagePainter
import com.example.veraxapplication.modele.articles.Article
import com.example.veraxapplication.modele.articles.Article
import com.example.veraxapplication.modele.articles.contenus.Contenu
import com.example.veraxapplication.modele.articles.contenus.ContenuMedia
import com.example.veraxapplication.modele.articles.contenus.ContenuMedia
import com.example.veraxapplication.modele.articles.contenus.ContenuParagraphe
import com.example.veraxapplication.modele.articles.contenus.ContenuParagraphe
import com.example.veraxapplication.ui.theme.Salmon
import com.example.veraxapplication.ui.theme.Salmon
@ -59,21 +63,14 @@ fun AffichageUnArticleInfo(e : Article){
Text ( text = e . titre , fontFamily = FontFamily . Serif , fontSize = 30. sp )
Text ( text = e . titre , fontFamily = FontFamily . Serif , fontSize = 30. sp )
Box ( modifier = Modifier
DisplayHeader ( author = e . auteur , description = e . description , lectureTime = e . temps )
. padding ( 15. dp )
. border ( width = 1. dp , color = Color . Black , shape = RoundedCornerShape ( 10. dp ) )
var imageURl = e . note
. clip ( RoundedCornerShape ( 10. dp ) )
Log . d ( " ImageLoad " , " URL de l'image reçue de l'API : $imageURl " )
. background ( Salmon )
) {
Column ( modifier = Modifier . padding ( 15. dp ) ) {
Text ( text = " Auteur : " + e . auteur , fontSize = 17. sp )
Text ( text = " Description : " + e . description , fontSize = 17. sp )
Text ( text = " Temps de lecture : " + e . temps + " minutes " , fontSize = 17. sp )
}
}
Image (
Image (
painter = rememberImagePainter (
painter = rememberImagePainter (
data = e. imagePrincipale
data = imageURl
) ,
) ,
contentScale = ContentScale . Crop ,
contentScale = ContentScale . Crop ,
contentDescription = null ,
contentDescription = null ,
@ -107,6 +104,34 @@ fun AfficherArticle(e : Article){
Text ( text = e . titre , fontFamily = FontFamily . Serif , fontSize = 30. sp )
Text ( text = e . titre , fontFamily = FontFamily . Serif , fontSize = 30. sp )
// Affichage des informations de l'article
DisplayHeader ( author = e . auteur , description = e . description , lectureTime = e . temps )
Text ( text = " coucou " )
/ *
Image (
painter = rememberImagePainter ( data = e . imagePrincipale ) ,
contentScale = ContentScale . FillHeight ,
contentDescription = null ,
modifier = Modifier
. size ( 350. dp )
. padding ( 5. dp , 35. dp )
. fillMaxWidth ( )
. wrapContentWidth ( Alignment . CenterHorizontally )
) * /
// Affichage contenus
//DisplayContenu(e.lContenus)
}
}
@Composable
fun DisplayHeader ( author : String , description : String , lectureTime : String ) {
Box (
Box (
modifier = Modifier
modifier = Modifier
. padding ( 15. dp )
. padding ( 15. dp )
@ -115,83 +140,79 @@ fun AfficherArticle(e : Article){
. background ( Salmon )
. background ( Salmon )
) {
) {
Column ( modifier = Modifier . padding ( 15. dp ) ) {
Column ( modifier = Modifier . padding ( 15. dp ) ) {
Text ( text = " Auteur : " + e . auteu r, fontSize = 17. sp )
Text ( text = " Auteur : " + autho r, fontSize = 17. sp )
Text ( text = " Description : " + e . description , fontSize = 17. sp )
Text ( text = " Description : " + description , fontSize = 17. sp )
Text ( text = " Temps de lecture : " + e. temps + " minutes " , fontSize = 17. sp )
Text ( text = " Temps de lecture : " + lectureTime + " minutes " , fontSize = 17. sp )
}
}
}
}
Image (
}
painter = rememberImagePainter (
@Composable
data = e . imagePrincipale
fun DisplayContenu ( contenus : List < Contenu > ) {
) ,
Column ( horizontalAlignment = Alignment . CenterHorizontally ) {
contentScale = ContentScale . Crop ,
for ( contenu in contenus ) {
contentDescription = null ,
when ( contenu ) {
modifier = Modifier
. size ( 350. dp )
. align ( Alignment . CenterHorizontally )
. padding ( 5. dp , 35. dp )
)
Column ( modifier = Modifier . align ( Alignment . Start ) ) {
for ( text in e . contenus ) {
when ( text ) {
is ContenuMedia -> {
is ContenuMedia -> {
Text ( text = text . titre , fontSize = 20. sp , fontWeight = FontWeight . Bold )
Text ( text = contenu . titre , fontSize = 20. sp , fontWeight = FontWeight . Bold )
when ( text . typeContenu ) {
when ( contenu . typeContenu ) {
" image " -> {
" image " -> {
Image (
Image (
painter = rememberImagePainter (
painter = rememberImagePainter ( data = contenu . lien ) ,
data = text . lien
contentScale = ContentScale . FillHeight ,
) ,
contentScale = ContentScale . FillHeight ,
contentDescription = null ,
contentDescription = null ,
modifier = Modifier
modifier = Modifier
. size ( 350. dp )
. size ( 350. dp )
. align ( Alignment . CenterHorizontally )
. padding ( 5. dp , 35. dp )
. padding ( 5. dp , 35. dp )
. fillMaxWidth ( )
. wrapContentWidth ( Alignment . CenterHorizontally ) // Centrer l'image
)
)
}
}
" video " -> {
" video " -> {
Text ( text = " Ici une video ... " + text . toString ( ) , fontSize = 15. sp , textAlign = TextAlign . Start )
// Pour l'instant, un simple texte pour les vidéos
//faut je vois comment on fait pour inclure une video ...
Text ( text = " Ici une vidéo ... ${contenu.lien} " , fontSize = 15. sp , textAlign = TextAlign . Start )
// Implémentation pour vidéo à venir...
}
}
}
}
}
is ContenuParagraphe -> {
Text ( text = text . titre , fontSize = 20. sp , fontWeight = FontWeight . Bold )
Text ( text = text . toString ( ) , fontSize = 16. sp , textAlign = TextAlign . Start )
}
}
is ContenuParagraphe -> {
Text ( text = contenu . titre , fontSize = 20. sp , fontWeight = FontWeight . Bold )
Text ( text = contenu . texte , fontSize = 16. sp , textAlign = TextAlign . Start )
}
}
}
}
}
}
}
}
}
}
/ *
/ *
@Composable
@Composable
fun DisplayImage ( image : String ) {
fun DisplayImage ( image : String ) {
Log . d ( " DisplayImage " , " Chargement de l'image à partir de l'URL : $image " )
Image (
painter = rememberImagePainter (
data = image
) ,
contentScale = ContentScale . Crop ,
contentDescription = null ,
modifier = Modifier
. size ( 350. dp )
. align ( Alignment . CenterHorizontally )
. padding ( 5. dp , 35. dp )
)
}
Log . d ( " DisplayImage " , " Painter créé avec succès " )
Box (
@Composable
modifier = Modifier . fillMaxSize ( ) ,
fun DisplayImage ( image : String ) {
contentAlignment = Alignment . Center
) {
Image (
Image (
painter = rememberImagePainter (
painter = rememberImagePainter (
data = image ,
data = e . imagePrincipale
builder = {
scale ( Scale . FILL )
}
) ,
) ,
contentScale = ContentScale . Crop ,
contentDescription = null ,
contentDescription = null ,
modifier = Modifier . fillMaxSize ( ) ,
modifier = Modifier
. size ( 350. dp )
. align ( Alignment . CenterHorizontally )
. padding ( 5. dp , 35. dp )
)
)
}
}
}