Set sort for parsed words
parent
04f263dbb3
commit
1fa9c904bd
|
@ -14,6 +14,7 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import main.component.buttonComponent
|
||||
import main.component.dropdownButtonComponent
|
||||
|
||||
@Composable
|
||||
|
@ -24,10 +25,36 @@ fun parsedWordsTable(
|
|||
onProjectClick: () -> Unit,
|
||||
onCodeToVerifyClick: () -> Unit,
|
||||
) {
|
||||
|
||||
var isCompareClicked by remember { mutableStateOf(false) }
|
||||
val noFileSnackbarVisibleState = remember { mutableStateOf(false) }
|
||||
|
||||
// State pour stocker la liste triée des mots
|
||||
var sortedWords by remember { mutableStateOf(parsedWords.toList()) }
|
||||
|
||||
// State pour stocker le sens du tri pour chaque bouton
|
||||
var isAscendingOrderByWord by remember { mutableStateOf(true) }
|
||||
var isAscendingOrderByOccurrences by remember { mutableStateOf(true) }
|
||||
|
||||
// Fonction pour trier par ordre alphabétique ou nombre d'occurrences
|
||||
fun sortList(comparator: Comparator<Pair<String, Int>>, isAscendingOrder: Boolean) {
|
||||
sortedWords = if (isAscendingOrder) {
|
||||
parsedWords.toList().sortedWith(comparator)
|
||||
} else {
|
||||
parsedWords.toList().sortedWith(comparator.reversed())
|
||||
}
|
||||
}
|
||||
|
||||
// Fonction pour trier par ordre alphabétique
|
||||
fun sortByAlphabet(isAscendingOrder: Boolean) {
|
||||
sortList(compareBy { it.first }, isAscendingOrder)
|
||||
}
|
||||
|
||||
// Fonction pour trier par nombre d'occurrences
|
||||
fun sortByOccurrences(isAscendingOrder: Boolean) {
|
||||
sortList(compareByDescending { it.second }, isAscendingOrder)
|
||||
}
|
||||
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Top,
|
||||
|
@ -37,13 +64,37 @@ 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()
|
||||
}
|
||||
items(parsedWords.toList()) { word ->
|
||||
val backgroundColor = if (parsedWords.toList().indexOf(word) % 2 == 0) {
|
||||
items(sortedWords) { word ->
|
||||
val backgroundColor = if (sortedWords.indexOf(word) % 2 == 0) {
|
||||
Color.White
|
||||
} else {
|
||||
Color.LightGray
|
||||
|
|
Loading…
Reference in New Issue