Compare commits

...

5 Commits

@ -12,6 +12,7 @@ import com.example.veraxapplication.navigation.VeraxNavHost
import com.example.veraxapplication.ui.article.AfficherArticle
import com.example.veraxapplication.ui.topBar.TopBarVerax
// doc navBar: https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary#TopAppBar(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Function0,kotlin.Function1,androidx.compose.foundation.layout.WindowInsets,androidx.compose.material3.TopAppBarColors,androidx.compose.material3.TopAppBarScrollBehavior)
// doc compose, pleins de trucs: https://developer.android.com/jetpack/compose/text?hl=fr
//doc couleur background pas finie: https://developer.android.com/jetpack/compose/components/scaffold
@ -37,10 +38,10 @@ class MainActivity : ComponentActivity() {
setContent {
//TopBarVerax(theme = theme, articles = articlesApi)
// TopBarVerax(theme = theme, articles = articles)
// TopBarVerax(theme = theme, articles = articlesApi)
TopBarVerax(theme = theme, articles = articles)
VeraxNavHost()
// VeraxNavHost()
}
}

@ -1,11 +0,0 @@
package com.example.veraxapplication.data
/*
data class Article(
var Title : String,
var Description : String,
var Image : String,
var Author : String,
var Content : List<Paragraph>,
var LectureTime : String
)
*/

@ -1,6 +0,0 @@
package com.example.veraxapplication.data
/*
data class Paragraph(
var Content : String,
)
*/

@ -0,0 +1,44 @@
package com.example.veraxapplication.navigation
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.example.veraxapplication.articles.IArticlesDataManager
import com.example.veraxapplication.articles.StubArticles
//import com.example.veraxapplication.HomeScreen
//https://codefirst.iut.uca.fr/git/Kotlin_Android/Android_TP_2/src/branch/master/app/src/main/java/fr/iut/tp2/navigation/TP2NavHost.kt
@Composable
fun NavHost(){
val navController = rememberNavController()
val dataManager : IArticlesDataManager = StubArticles()
var articles = dataManager.getDerniersArticles(4)
NavHost(
modifier = Modifier.fillMaxSize(),
navController = navController,
startDestination = "home"
) {
composable(route = "home") {
/* HomeScreen(
//article = , //recup l article cliqué
goToArticle = {
navController.navigate("articleALaUne/${it.id}")
}
)
}
composable(
route = "articleALaUne/{articleId}",
arguments = navArgument("articleALaUne") { type = NavType.LongType })
*/
}
}
}

@ -1,22 +1,46 @@
package com.example.veraxapplication.navigation
import androidx.compose.runtime.Composable
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.example.veraxapplication.MainActivity
import com.example.veraxapplication.modele.articles.Article
import com.example.veraxapplication.ui.article.AffichageLesArticles
import com.example.veraxapplication.ui.article.AfficherArticle
@Composable
fun VeraxNavHost() {
fun VeraxNavHost(articles : List<Article>, navController: NavHostController) {
val navController = rememberNavController()
NavHost(
navController = navController,
startDestination = "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 ->
articles.find { it.id == articleid }?.let {
AfficherArticle(
e = it
)
}
}
}
}

@ -5,6 +5,7 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.clipScrollableContainer
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
@ -33,11 +34,13 @@ import com.example.veraxapplication.modele.articles.contenus.ContenuParagraphe
import com.example.veraxapplication.ui.theme.Salmon
@Composable
fun AffichageLesArticles(articles : List<Article>){
fun AffichageLesArticles(articles : List<Article>, goToArticle: (Article) -> Unit
){
Column(modifier = Modifier.verticalScroll(rememberScrollState())){
for(article in articles){
Box (Modifier.clickable { /*faut je regarde la doc*/ }){
AffichageUnArticleInfo(e = article)
Box (Modifier.clickable { /*faut je regarde la doc*/ }
.background(color = Color(android.graphics.Color.parseColor("#e7dfd8")))){
AffichageUnArticleInfo(e = article, goToArticle)
}
}
@ -45,10 +48,12 @@ fun AffichageLesArticles(articles : List<Article>){
}
@Composable
fun AffichageUnArticleInfo(e : Article){
fun AffichageUnArticleInfo(e : Article, goToArticle: (Article) -> Unit){
Column(modifier = Modifier
.padding(7.dp)
.border(width = 1.dp, color = Color.Black, shape = RoundedCornerShape(10.dp))
.padding(12.dp,12.dp,12.dp,20.dp)
.background(Color.White)
//.border(width = 1.dp, color = Color.Black, shape = RoundedCornerShape(10.dp))
//.clip(RoundedCornerShape(50.dp)) //ca marche mais il y a comme un rectange blanc derriere
.padding(5.dp)) {
/*DisplayTitle(title = e.Title)
DisplayHeader(author = e.Author, description = e.Description, lectureTime = e.LectureTime)
@ -83,7 +88,7 @@ fun AffichageUnArticleInfo(e : Article){
.padding(5.dp, 35.dp)
)
Button(onClick = { /*TODO*/ },
Button(onClick = { goToArticle(e) },
colors = ButtonDefaults.buttonColors(
containerColor = Salmon,
contentColor = Color.Black
@ -105,6 +110,8 @@ fun AfficherArticle(e : Article){
.padding(7.dp)
.padding(5.dp)) {
Text(text = e.titre, fontFamily = FontFamily.Serif, fontSize = 30.sp)
Box(

@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
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.filled.ArrowBack
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.CenterAlignedTopAppBar
@ -32,8 +33,11 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
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.modele.articles.Article
import com.example.veraxapplication.navigation.VeraxNavHost
import com.example.veraxapplication.ui.article.AffichageLesArticles
import com.example.veraxapplication.ui.article.AfficherArticle
import com.example.veraxapplication.ui.theme.Orange
@ -44,6 +48,11 @@ fun TopBarVerax(theme: List<String>, articles: List<Article>) {
var leMenu by remember {
mutableStateOf(false)
}
val navController = rememberNavController()
val navBackStackEntry by navController.currentBackStackEntryAsState()
Row() {
Scaffold(
topBar = {
@ -59,14 +68,16 @@ fun TopBarVerax(theme: List<String>, articles: List<Article>) {
modifier = Modifier.fillMaxWidth()
)
},
navigationIcon = {
IconButton(onClick = { /* action() */ }) {
navigationIcon = { if (navBackStackEntry?.destination?.route != "accueil"){
IconButton(onClick = { navController.popBackStack() }) {
Icon(
imageVector = Icons.Filled.ArrowBack,
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Retour",
Modifier.size(30.dp)
)
}
}
},
actions = {
IconButton(onClick = { leMenu = !leMenu }) {
@ -79,7 +90,11 @@ fun TopBarVerax(theme: List<String>, articles: List<Article>) {
DropdownMenu(
expanded = leMenu, onDismissRequest = { leMenu = false },
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)
) {
theme.sorted().forEach {
@ -126,8 +141,10 @@ fun TopBarVerax(theme: List<String>, articles: List<Article>) {
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
AffichageLesArticles(articles = articles)
// AfficherArticle(articles.get(0));
// AffichageLesArticles(articles = articles)
// AfficherArticle(articles.get(0))
VeraxNavHost(articles = articles, navController)
}

Loading…
Cancel
Save