Update sort method

main
CAPEL Maxime 2024-01-17 14:53:12 +01:00
parent 1fa9c904bd
commit 684bacd863
1 changed files with 40 additions and 34 deletions

View File

@ -2,6 +2,7 @@ package main
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
@ -64,34 +65,21 @@ fun parsedWordsTable(
Spacer(modifier = Modifier.height(16.dp))
// Ajoutez des boutons de tri
Row(
modifier = Modifier
.padding(16.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
buttonComponent(
text = "Trier par mot ${if (isAscendingOrderByWord) "▲" else "▼"}",
onClick = {
sortByAlphabet(!isAscendingOrderByWord)
isAscendingOrderByWord = !isAscendingOrderByWord
},
width = 250,
)
buttonComponent(
text = "Trier par occurrences ${if (isAscendingOrderByOccurrences) "▲" else "▼"}",
onClick = {
sortByOccurrences(!isAscendingOrderByOccurrences)
isAscendingOrderByOccurrences = !isAscendingOrderByOccurrences
},
width = 250,
)
}
// Tableau des mots parsés
LazyColumn(modifier = Modifier.padding(16.dp)) {
item {
parsedWordsHeaderRow()
parsedWordsHeaderRow(
onWordHeaderClick = {
sortByAlphabet(!isAscendingOrderByWord)
isAscendingOrderByWord = !isAscendingOrderByWord
},
onOccurrencesHeaderClick = {
sortByOccurrences(!isAscendingOrderByOccurrences)
isAscendingOrderByOccurrences = !isAscendingOrderByOccurrences
},
isAscendingOrderByWord = isAscendingOrderByWord,
isAscendingOrderByOccurrences = isAscendingOrderByOccurrences
)
}
items(sortedWords) { word ->
val backgroundColor = if (sortedWords.indexOf(word) % 2 == 0) {
@ -136,7 +124,12 @@ fun parsedWordsTable(
}
@Composable
fun parsedWordsHeaderRow() {
fun parsedWordsHeaderRow(
onWordHeaderClick: () -> Unit,
onOccurrencesHeaderClick: () -> Unit,
isAscendingOrderByWord: Boolean,
isAscendingOrderByOccurrences: Boolean
) {
Row(
modifier = Modifier
.fillMaxWidth()
@ -144,14 +137,27 @@ fun parsedWordsHeaderRow() {
.border(1.dp, Color.Black),
verticalAlignment = Alignment.CenterVertically
) {
listOf("Mot", "Occurrences").forEach { header ->
// En-tête pour le mot
Text(
text = header,
text = "Mot ${if (isAscendingOrderByWord) "▲" else "▼"}",
fontWeight = FontWeight.Bold,
modifier = Modifier.weight(1f).padding(8.dp),
modifier = Modifier
.weight(1f)
.padding(8.dp)
.clickable { onWordHeaderClick() },
color = Color.White
)
// En-tête pour les occurrences
Text(
text = "Occurrences ${if (isAscendingOrderByOccurrences) "▲" else "▼"}",
fontWeight = FontWeight.Bold,
modifier = Modifier
.weight(1f)
.padding(8.dp)
.clickable { onOccurrencesHeaderClick() },
color = Color.White
)
}
}
}