From 3e88d7b888a0615b74d3ba1699b3f92244f142f4 Mon Sep 17 00:00:00 2001 From: CAPEL Maxime <83071634+fortyup@users.noreply.github.com> Date: Tue, 19 Dec 2023 10:59:02 +0100 Subject: [PATCH] Add table for parsed word --- src/main/kotlin/main/Main.kt | 5 +- src/main/kotlin/main/nb_occurrence.kt | 86 +++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/main/nb_occurrence.kt diff --git a/src/main/kotlin/main/Main.kt b/src/main/kotlin/main/Main.kt index f916a9d..e57996f 100644 --- a/src/main/kotlin/main/Main.kt +++ b/src/main/kotlin/main/Main.kt @@ -267,6 +267,9 @@ fun app() { } ) } + "occurrence" -> { + parsedWordsTable(mostUsedWordList, onBackClick = { currentPage.value = "choixLangage" }) + } } if (isJavaScriptFileSelected) { AlertDialog( @@ -285,7 +288,7 @@ fun app() { onClick = { // Handle the confirm button action isJavaScriptFileSelected = false - currentPage.value = "accueil" + currentPage.value = "occurrence" }, colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, diff --git a/src/main/kotlin/main/nb_occurrence.kt b/src/main/kotlin/main/nb_occurrence.kt new file mode 100644 index 0000000..116dbb4 --- /dev/null +++ b/src/main/kotlin/main/nb_occurrence.kt @@ -0,0 +1,86 @@ +package main + +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.Button +import androidx.compose.material.MaterialTheme +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp + +@Composable +fun parsedWordsTable(parsedWords: Map, onBackClick: () -> Unit) { + Column( + modifier = Modifier.fillMaxSize(), + verticalArrangement = Arrangement.Top, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text(text = "Mots Parsés", style = MaterialTheme.typography.h3) + + Spacer(modifier = Modifier.height(16.dp)) + + // Tableau des mots parsés + LazyColumn(modifier = Modifier.padding(16.dp)) { + item { + parsedWordsHeaderRow() + } + items(parsedWords.toList()) { (word, count) -> + parsedWordsDataRow(word, count) + } + } + + Spacer(modifier = Modifier.height(16.dp)) + + Button( + onClick = { onBackClick() }, + colors = androidx.compose.material.ButtonDefaults.buttonColors( + backgroundColor = customRedColor, + contentColor = Color.White + ) + ) { + Text("Retour") + } + } +} + +@Composable +fun parsedWordsHeaderRow() { + Row( + modifier = Modifier + .fillMaxWidth() + .background(customRedColor) + .border(1.dp, Color.Black), + verticalAlignment = Alignment.CenterVertically + ) { + listOf("Mot", "Occurrences").forEach { header -> + Text( + text = header, + fontWeight = FontWeight.Bold, + modifier = Modifier.weight(1f).padding(8.dp), + color = Color.White + ) + } + } +} + +@Composable +fun parsedWordsDataRow(word: String, count: Int) { + Row( + modifier = Modifier + .fillMaxWidth() + .background(Color.White) + .border(1.dp, Color.Black), + verticalAlignment = Alignment.CenterVertically + ) { + val modifier = Modifier.weight(1f).padding(8.dp) + CellContent(word, modifier) + CellContent(count.toString(), modifier) + } +} \ No newline at end of file