fusion entre api - stub

API
Shana CASCARRA 3 months ago
parent 90da510a63
commit 47daea74e6

@ -58,11 +58,6 @@ fun VeraxContent() {
var theme = listOf("Economique", "Culture", "Politique", "Faits divers") var theme = listOf("Economique", "Culture", "Politique", "Faits divers")
TopBarVerax(articles = articlesApi, theme = theme, articlesStub= articles)
TopBarVerax(articles = articlesApi, theme = theme)
VeraxNavHost()
} }

@ -26,11 +26,11 @@ class StubArticles() : IArticlesDataManager {
"Thinkerview est une chaîne passionnante chaîne youtube d'interview-débat.", "Thinkerview est une chaîne passionnante chaîne youtube d'interview-débat.",
"3", "3",
"02/09/2024", "02/09/2024",
"Tony", "Siwa",
"Politique", "Politique",
"12", "https://cdn.discordapp.com/attachments/1150826798549049554/1219554341388816437/stub1.webp?ex=660bb97d&is=65f9447d&hm=3e1e8d3372ae897fa4e2aa1ec730d976d74b35fce96cb8d78d6f9239e2836564&",
"https://cdn.discordapp.com/attachments/1150826798549049554/1219554341388816437/stub1.webp?ex=660bb97d&is=65f9447d&hm=3e1e8d3372ae897fa4e2aa1ec730d976d74b35fce96cb8d78d6f9239e2836564&" "12"
) )
article1.remplirArticle(contenuMap["article1"]) article1.remplirArticle(contenuMap["article1"])
lArticles!!.add(article1) lArticles!!.add(article1)
@ -41,10 +41,10 @@ class StubArticles() : IArticlesDataManager {
"Revenons sur les différentes controverses à ce sujet.", "Revenons sur les différentes controverses à ce sujet.",
"7", "7",
"02/09/2024", "02/09/2024",
"Tony", "Siwa",
"Politique", "Politique",
"12", "https://cdn.discordapp.com/attachments/1150826798549049554/1219555874339815454/stub2.webp?ex=660bbaea&is=65f945ea&hm=80aef945e8410b18395c716fdd19265608f7b1263731192d5c69f807fce9e944&",
"https://cdn.discordapp.com/attachments/1150826798549049554/1219555874339815454/stub2.webp?ex=660bbaea&is=65f945ea&hm=80aef945e8410b18395c716fdd19265608f7b1263731192d5c69f807fce9e944&" "12"
) )
article2.remplirArticle(contenuMap["article5"]) article2.remplirArticle(contenuMap["article5"])
lArticles!!.add(article2) lArticles!!.add(article2)
@ -56,11 +56,10 @@ class StubArticles() : IArticlesDataManager {
"Pour réfuter la fausse croyance que la Terre est plate, il est essentiel de s'appuyer sur des preuves scientifiques et des observations historiques. ", "Pour réfuter la fausse croyance que la Terre est plate, il est essentiel de s'appuyer sur des preuves scientifiques et des observations historiques. ",
"5", "5",
"02/09/2024", "02/09/2024",
"Tony", "Siwa",
"Politique", "Politique",
"12", "https://cdn.discordapp.com/attachments/1150826798549049554/1219547864196317225/stub1.webp?ex=660bb374&is=65f93e74&hm=a9e5dd48faa3ae68c358309af8949c46dfd4dea9c4d6e3d845d707784e5341cf&",
"12"
"https://cdn.discordapp.com/attachments/1150826798549049554/1219547864196317225/stub1.webp?ex=660bb374&is=65f93e74&hm=a9e5dd48faa3ae68c358309af8949c46dfd4dea9c4d6e3d845d707784e5341cf&"
) )
article3.remplirArticle(contenuMap["article4"]) article3.remplirArticle(contenuMap["article4"])
lArticles!!.add(article3) lArticles!!.add(article3)
@ -72,10 +71,10 @@ class StubArticles() : IArticlesDataManager {
"Explorons les progrès remarquables dans le domaine de l'IA, les secteurs qu'elle révolutionne, et les implications éthiques majeures qu'elle soulève.", "Explorons les progrès remarquables dans le domaine de l'IA, les secteurs qu'elle révolutionne, et les implications éthiques majeures qu'elle soulève.",
"9", "9",
"02/09/2024", "02/09/2024",
"Tony", "Luthen",
"Politique", "Politique",
"12", "https://cdn.discordapp.com/attachments/1150826798549049554/1219560686254817290/stub1.webp?ex=660bbf65&is=65f94a65&hm=021bd8c90c89347f31373468cc7a03ae15f1d3f9988a5b4325149c6df938d7bb&",
"https://cdn.discordapp.com/attachments/1150826798549049554/1219560686254817290/stub1.webp?ex=660bbf65&is=65f94a65&hm=021bd8c90c89347f31373468cc7a03ae15f1d3f9988a5b4325149c6df938d7bb&" "12"
) )
article4.remplirArticle(contenuMap["article6"]) article4.remplirArticle(contenuMap["article6"])
lArticles!!.add(article4) lArticles!!.add(article4)

@ -1,22 +1,44 @@
package com.example.veraxapplication.navigation package com.example.veraxapplication.navigation
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import com.example.veraxapplication.MainActivity import androidx.navigation.navArgument
import com.example.veraxapplication.modele.articles.Article
import com.example.veraxapplication.ui.article.AffichageLesArticles
import com.example.veraxapplication.ui.article.AfficherArticle
@Composable @Composable
fun VeraxNavHost() { fun VeraxNavHost(articles : List<Article>, navController: NavHostController, articlesStub: List<Article>) {
val navController = rememberNavController()
NavHost( NavHost(
navController = navController, navController = navController,
startDestination = "accueil" startDestination = "accueil"
){ ){
composable(route="accueil"){ composable(route="accueil"){
AffichageLesArticles(
articles = articles,
goToArticle = {
navController.navigate("article/${it.id}")
}
)
}
composable(
route="article/{articleid}",
arguments= listOf(navArgument("articleid"){ type= NavType.IntType})
){
it.arguments?.getInt("articleid")?.let { articleid ->
articlesStub.find { it.id == articleid }?.let {
AfficherArticle(
e = it
)
}
}
} }
} }

@ -37,40 +37,40 @@ import com.example.veraxapplication.modele.articles.contenus.ContenuParagraphe
import com.example.veraxapplication.ui.theme.Salmon import com.example.veraxapplication.ui.theme.Salmon
@Composable @Composable
fun AffichageLesArticles(articles : List<Article>){ fun AffichageLesArticles(articles : List<Article>, goToArticle: (Article) -> Unit){
Column(modifier = Modifier.verticalScroll(rememberScrollState())){ Column(modifier = Modifier.verticalScroll(rememberScrollState())){
for(article in articles){ for(article in articles){
Box (Modifier.clickable { /*faut je regarde la doc*/ }){ Box {
AffichageUnArticleInfo(e = article) AffichageUnArticleInfo(e = article, goToArticle)
} }
} }
} }
} }
@Composable @Composable
fun AffichageUnArticleInfo(e : Article){ fun AffichageUnArticleInfo(e : Article, goToArticle: (Article) -> Unit){
Column(modifier = Modifier Column(modifier = Modifier
.padding(7.dp) .padding(7.dp)
.border(width = 1.dp, color = Color.Black, shape = RoundedCornerShape(10.dp)) .border(width = 1.dp, color = Color.Black, shape = RoundedCornerShape(10.dp))
.padding(5.dp)) { .padding(5.dp)) {
/*DisplayTitle(title = e.Title)
DisplayHeader(author = e.Author, description = e.Description, lectureTime = e.LectureTime)
DisplayImage(image = e.Image)
DisplayContentArticle(content = e.Content)*/
Text(text = e.titre, fontFamily = FontFamily.Serif, fontSize = 30.sp) Text(text = e.titre, fontFamily = FontFamily.Serif, fontSize = 30.sp)
DisplayHeader(author = e.auteur, description = e.description , lectureTime = e.temps) Box(modifier = Modifier
.padding(15.dp)
var imageURl = e.imagePrincipale .border(width = 1.dp, color = Color.Black, shape = RoundedCornerShape(10.dp))
Log.d("ImageLoad", "URL de l'image reçue de l'API : $imageURl") .clip(RoundedCornerShape(10.dp))
.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 = imageURl data = e.imagePrincipale
), ),
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
contentDescription = null, contentDescription = null,
@ -79,15 +79,16 @@ fun AffichageUnArticleInfo(e : Article){
.align(Alignment.CenterHorizontally) .align(Alignment.CenterHorizontally)
.padding(5.dp, 35.dp) .padding(5.dp, 35.dp)
) )
Button(onClick = { /*TODO*/ },
Button(onClick = { goToArticle(e)},
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
containerColor = Salmon, containerColor = Salmon,
contentColor = Color.Black contentColor = Color.Black
), ),
border = BorderStroke(1.dp, Color.Black), border = BorderStroke(1.dp, Color.Black),
modifier = Modifier modifier = Modifier
.align(Alignment.CenterHorizontally) .align(Alignment.CenterHorizontally)
) { ) {
Text(text = "Voir plus") Text(text = "Voir plus")
} }
@ -107,25 +108,23 @@ fun AfficherArticle(e : Article){
// Affichage des informations de l'article // Affichage des informations de l'article
DisplayHeader(author = e.auteur, description = e.description, lectureTime = e.temps) DisplayHeader(author = e.auteur, description = e.description, lectureTime = e.temps)
Text(text = "coucou")
/*
Image( Image(
painter = rememberImagePainter(data = e.imagePrincipale), painter = rememberImagePainter(
contentScale = ContentScale.FillHeight, data = e.imagePrincipale
),
contentScale = ContentScale.Crop,
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)
)*/
// Affichage contenus // Affichage contenus
//DisplayContenu(e.lContenus) DisplayContenu(e.lContenus)
} }
} }

@ -5,12 +5,13 @@ import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth 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.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Menu import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.CenterAlignedTopAppBar import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenu
@ -32,18 +33,25 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.example.veraxapplication.R import com.example.veraxapplication.R
import com.example.veraxapplication.modele.articles.Article import com.example.veraxapplication.modele.articles.Article
import com.example.veraxapplication.ui.article.AffichageLesArticles import com.example.veraxapplication.navigation.VeraxNavHost
import com.example.veraxapplication.ui.theme.Orange import com.example.veraxapplication.ui.theme.Orange
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun TopBarVerax(theme: List<String>, articles: List<Article>) { fun TopBarVerax(theme: List<String>, articles: List<Article>, articlesStub : List<Article>) {
var leMenu by remember { var leMenu by remember {
mutableStateOf(false) mutableStateOf(false)
} }
Row() {
val navController = rememberNavController()
val navBackStackEntry by navController.currentBackStackEntryAsState()
Row( modifier = Modifier.background(Color.Blue).fillMaxSize()) {
Scaffold( Scaffold(
topBar = { topBar = {
CenterAlignedTopAppBar( CenterAlignedTopAppBar(
@ -58,14 +66,16 @@ fun TopBarVerax(theme: List<String>, articles: List<Article>) {
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) )
}, },
navigationIcon = { navigationIcon = { if (navBackStackEntry?.destination?.route != "accueil"){
IconButton(onClick = { /* action() */ }) { IconButton(onClick = { navController.popBackStack() }) {
Icon( Icon(
imageVector = Icons.Filled.ArrowBack, imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Retour", contentDescription = "Retour",
Modifier.size(30.dp) Modifier.size(30.dp)
) )
} }
}
}, },
actions = { actions = {
IconButton(onClick = { leMenu = !leMenu }) { IconButton(onClick = { leMenu = !leMenu }) {
@ -78,7 +88,11 @@ fun TopBarVerax(theme: List<String>, articles: List<Article>) {
DropdownMenu( DropdownMenu(
expanded = leMenu, onDismissRequest = { leMenu = false }, expanded = leMenu, onDismissRequest = { leMenu = false },
modifier = Modifier modifier = Modifier
.border(width = 1.dp, color = Color.Black, shape = RoundedCornerShape(10.dp)) .border(
width = 1.dp,
color = Color.Black,
shape = RoundedCornerShape(10.dp)
)
.background(Orange) .background(Orange)
) { ) {
theme.sorted().forEach { theme.sorted().forEach {
@ -125,8 +139,10 @@ fun TopBarVerax(theme: List<String>, articles: List<Article>) {
verticalArrangement = Arrangement.spacedBy(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp),
) { ) {
AffichageLesArticles(articles = articles) // AffichageLesArticles(articles = articles)
// AfficherArticle(articles.get(0)); // AfficherArticle(articles.get(0))
VeraxNavHost(articles = articles, navController, articlesStub= articlesStub)
} }

Loading…
Cancel
Save