Update sort method
parent
1fa9c904bd
commit
684bacd863
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
|
@ -64,34 +65,21 @@ fun parsedWordsTable(
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
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
|
// Tableau des mots parsés
|
||||||
LazyColumn(modifier = Modifier.padding(16.dp)) {
|
LazyColumn(modifier = Modifier.padding(16.dp)) {
|
||||||
item {
|
item {
|
||||||
parsedWordsHeaderRow()
|
parsedWordsHeaderRow(
|
||||||
|
onWordHeaderClick = {
|
||||||
|
sortByAlphabet(!isAscendingOrderByWord)
|
||||||
|
isAscendingOrderByWord = !isAscendingOrderByWord
|
||||||
|
},
|
||||||
|
onOccurrencesHeaderClick = {
|
||||||
|
sortByOccurrences(!isAscendingOrderByOccurrences)
|
||||||
|
isAscendingOrderByOccurrences = !isAscendingOrderByOccurrences
|
||||||
|
},
|
||||||
|
isAscendingOrderByWord = isAscendingOrderByWord,
|
||||||
|
isAscendingOrderByOccurrences = isAscendingOrderByOccurrences
|
||||||
|
)
|
||||||
}
|
}
|
||||||
items(sortedWords) { word ->
|
items(sortedWords) { word ->
|
||||||
val backgroundColor = if (sortedWords.indexOf(word) % 2 == 0) {
|
val backgroundColor = if (sortedWords.indexOf(word) % 2 == 0) {
|
||||||
|
@ -136,7 +124,12 @@ fun parsedWordsTable(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun parsedWordsHeaderRow() {
|
fun parsedWordsHeaderRow(
|
||||||
|
onWordHeaderClick: () -> Unit,
|
||||||
|
onOccurrencesHeaderClick: () -> Unit,
|
||||||
|
isAscendingOrderByWord: Boolean,
|
||||||
|
isAscendingOrderByOccurrences: Boolean
|
||||||
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
@ -144,14 +137,27 @@ fun parsedWordsHeaderRow() {
|
||||||
.border(1.dp, Color.Black),
|
.border(1.dp, Color.Black),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
listOf("Mot", "Occurrences").forEach { header ->
|
// En-tête pour le mot
|
||||||
Text(
|
Text(
|
||||||
text = header,
|
text = "Mot ${if (isAscendingOrderByWord) "▲" else "▼"}",
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
modifier = Modifier.weight(1f).padding(8.dp),
|
modifier = Modifier
|
||||||
color = Color.White
|
.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
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue