Add compare in table

main
CAPEL Maxime 2023-12-19 11:26:29 +01:00
parent 5e26cc7fd6
commit c65c90b0a1
6 changed files with 100 additions and 77 deletions

View File

@ -1,17 +1,18 @@
package main
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
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.ButtonDefaults
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
@ -19,38 +20,28 @@ fun compareResults(
glossaryWords: List<Word>,
codeWords: List<String>,
onBackClick: () -> Unit
) {
val commonWords = findCommonWords(glossaryWords, codeWords)
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Top, // Align content at the top
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Le code contient ${compareWords(glossaryWords, codeWords)}% des mots du glossaire",
text = "Le code contient ${commonWords.size}% des mots du glossaire",
style = MaterialTheme.typography.h3
)
}
Column(
modifier = Modifier
.fillMaxSize() // Fills the maximum available width
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
Spacer(modifier = Modifier.height(16.dp))
) {
Text(text = "Le code contient ${compareWords(glossaryWords, codeWords)}% des mots du glossaire")
}
commonWordsTable(glossaryWords, codeWords)
Spacer(modifier = Modifier.height(16.dp))
Column(
modifier = Modifier.fillMaxSize().padding(20.dp),
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(
onClick = onBackClick,
colors = ButtonDefaults.buttonColors(
colors = androidx.compose.material.ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
@ -58,18 +49,79 @@ fun compareResults(
Text("Retour")
}
}
}
fun compareWords(glossaryWord: List<Word>, wordsCode: List<String>): Int {
var foundWords = 0
wordsCode.forEach { wordCode ->
glossaryWord.forEach { word ->
if (wordCode.equals(word.name, ignoreCase = true)) {
foundWords++
@Composable
fun commonWordsTable(
glossaryWords: List<Word>,
codeWords: List<String>
) {
val glossaryWordsSet = glossaryWords.map { it.name }.toSet()
LazyColumn(
modifier = Modifier.fillMaxSize(),
content = {
item {
commonWordsHeaderRow()
}
items(glossaryWords) { word ->
commonWordsDataRow(word, codeWords, glossaryWordsSet)
}
}
)
}
@Composable
fun commonWordsHeaderRow() {
Row(
modifier = Modifier
.fillMaxWidth()
.background(Color.Gray)
.border(1.dp, Color.Black),
verticalAlignment = Alignment.CenterVertically
) {
listOf("Mot du glossaire", "Mot du code", "Présence commune").forEach { header ->
Text(
text = header,
fontWeight = FontWeight.Bold,
modifier = Modifier.weight(1f).padding(8.dp),
color = Color.White
)
}
}
}
println(foundWords * 100 / wordsCode.size)
return foundWords * 100 / wordsCode.size
@Composable
fun commonWordsDataRow(
word: Word,
codeWords: List<String>,
glossaryWordsSet: Set<String>
) {
val modifier = Modifier
.fillMaxWidth()
.border(1.dp, Color.Black)
.padding(8.dp)
val isCommon = word.name in codeWords && word.name in glossaryWordsSet
val backgroundColor = when {
isCommon -> Color.Yellow
word.name in codeWords -> Color.Blue // Couleur pour les mots du code
word.name in glossaryWordsSet -> Color.Green // Couleur pour les mots du glossaire
else -> Color.White
}
Row(
modifier = modifier.background(backgroundColor),
verticalAlignment = Alignment.CenterVertically
) {
cellContent(word.name, modifier)
cellContent(if (word.name in codeWords) "Oui" else "Non", modifier)
cellContent(if (isCommon) "Oui" else "Non", modifier)
}
}
fun findCommonWords(glossaryWords: List<Word>, codeWords: List<String>): List<String> {
val glossaryWordsSet = glossaryWords.map { it.name }.toSet()
return codeWords.filter { it in glossaryWordsSet }
}

View File

@ -93,7 +93,7 @@ fun headerRow() {
}
@Composable
fun CellContent(text: String, modifier: Modifier = Modifier) {
fun cellContent(text: String, modifier: Modifier = Modifier) {
Text(
text = text,
modifier = modifier
@ -111,12 +111,12 @@ fun glossaryDataRow(word: Word) {
) {
val modifier = Modifier.weight(1f).padding(8.dp)
// Contenu de chaque cellule
CellContent(word.name, modifier)
CellContent(word.description, modifier)
CellContent(word.mainContext, modifier)
CellContent(word.secondaryContext, modifier)
CellContent(word.relatedTo, modifier)
CellContent(word.synonymous, modifier)
CellContent(word.antonym, modifier)
cellContent(word.name, modifier)
cellContent(word.description, modifier)
cellContent(word.mainContext, modifier)
cellContent(word.secondaryContext, modifier)
cellContent(word.relatedTo, modifier)
cellContent(word.synonymous, modifier)
cellContent(word.antonym, modifier)
}
}

View File

@ -28,8 +28,7 @@ fun glossaryPage(
onImportClick: () -> Unit,
onExportClick: () -> Unit,
onSeeGlossaryClick: () -> Unit,
onBackClick: () -> Unit,
selectedGlossary: Glossary
onBackClick: () -> Unit
) {

View File

@ -1,8 +1,8 @@
package main
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
@ -10,7 +10,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import java.util.*
var mostUsedWordList = mutableMapOf<String, Int>()
@ -129,28 +128,3 @@ fun homePage(
}
}
}
@Composable
fun getGlossaryButtonText(language: Language): String {
return when (language) {
Language.FRENCH -> "Glossaire"
Language.ENGLISH -> "Glossary"
}
}
@Composable
fun getCodeToVerifyButtonText(language: Language): String {
return when (language) {
Language.FRENCH -> "Code à Vérifier"
Language.ENGLISH -> "Code to Verify"
}
}
@Composable
fun getCompareButtonText(language: Language): String {
return when (language) {
Language.FRENCH -> "Comparer"
Language.ENGLISH -> "Compare"
}
}

View File

@ -246,10 +246,8 @@ fun app() {
onSeeGlossaryClick = {
glossaryDetail = selectedGlossary?.let { loadDatasFromFile(it.jsonFilePath) }!!
currentPage.value = "glossaireDetail"
},
onBackClick = { currentPage.value = "glossaires" },
selectedGlossary = selectedGlossary!!
)
}
) { currentPage.value = "glossaires" }
}
"glossaireDetail" -> {
glossaryDetailedPage(

View File

@ -80,7 +80,7 @@ fun parsedWordsDataRow(word: String, count: Int) {
verticalAlignment = Alignment.CenterVertically
) {
val modifier = Modifier.weight(1f).padding(8.dp)
CellContent(word, modifier)
CellContent(count.toString(), modifier)
cellContent(word, modifier)
cellContent(count.toString(), modifier)
}
}