From 7ecf4cd68d01a5cd4177e11518cd953f49789ee6 Mon Sep 17 00:00:00 2001 From: cemal Date: Tue, 19 Dec 2023 15:30:07 +0100 Subject: [PATCH] Added glossary choose before comparing and bugfix --- src/main/kotlin/main/Home.kt | 218 ++++++++++++++++++++++------------- src/main/kotlin/main/Main.kt | 5 +- 2 files changed, 138 insertions(+), 85 deletions(-) diff --git a/src/main/kotlin/main/Home.kt b/src/main/kotlin/main/Home.kt index cbadc6c..7a30a8b 100644 --- a/src/main/kotlin/main/Home.kt +++ b/src/main/kotlin/main/Home.kt @@ -3,6 +3,8 @@ package main import androidx.compose.foundation.Image import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment @@ -26,105 +28,155 @@ fun homePage( val noFileSnackbarVisibleState = remember { mutableStateOf(false) } var isCompareClicked by remember { mutableStateOf(false) } - // Utilisez un Box pour placer le drapeau en haut à droite - Box( - modifier = Modifier - .fillMaxSize() - .padding(16.dp), - contentAlignment = Alignment.TopEnd - ) { - // Utilisez les images des drapeaux - Image( - painter = painterResource(if (languageManager.currentLanguage == Language.FRENCH) "FR.png" else "EN.png"), - contentDescription = "Language Flag", - modifier = Modifier.size(48.dp) - .clickable { languageManager.changeLanguage() } - ) - } + var selectedGlossary by remember { mutableStateOf(null) } - Column( - modifier = Modifier.fillMaxSize(), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Text("Quali'Nomme", style = MaterialTheme.typography.h3) - - Spacer(modifier = Modifier.height(16.dp)) - - Column { - Row( - horizontalArrangement = Arrangement.spacedBy(16.dp) - ) { - Button( - onClick = onGlossaryClick, - modifier = Modifier.width(200.dp), - colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ) - ) { - Text(languageManager.getGlossaryText()) - } - - Button( - onClick = onCodeToVerifyClick, - modifier = Modifier.width(200.dp), - colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ) - ) { - Text(languageManager.getCodeToVerifyText()) - } - - Button( - onClick = { - if (mostUsedWordList.isEmpty()) { - noFileSnackbarVisibleState.value = true - println("Veuillez d'abord importer un fichier") - return@Button - } else { - isCompareClicked = true - } - }, - modifier = Modifier.width(200.dp), - colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ), - enabled = mostUsedWordList.isNotEmpty() - ) { - Text(languageManager.getCompareText()) - } - } + if (!isCompareClicked && selectedGlossary == null) { + // Utilisez un Box pour placer le drapeau en haut à droite + Box( + modifier = Modifier + .fillMaxSize() + .padding(16.dp), + contentAlignment = Alignment.TopEnd + ) { + // Utilisez les images des drapeaux + Image( + painter = painterResource(if (languageManager.currentLanguage == Language.FRENCH) "FR.png" else "EN.png"), + contentDescription = "Language Flag", + modifier = Modifier.size(48.dp) + .clickable { languageManager.changeLanguage() } + ) } - if (noFileSnackbarVisibleState.value) { - Snackbar( - modifier = Modifier.padding(16.dp), - action = { + Column( + modifier = Modifier.fillMaxSize(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text("Quali'Nomme", style = MaterialTheme.typography.h3) + + Spacer(modifier = Modifier.height(16.dp)) + + Column { + Row( + horizontalArrangement = Arrangement.spacedBy(16.dp) + ) { Button( - onClick = { noFileSnackbarVisibleState.value = false }, + onClick = onGlossaryClick, + modifier = Modifier.width(200.dp), colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White ) ) { - Text("OK") + Text(languageManager.getGlossaryText()) + } + + Button( + onClick = onCodeToVerifyClick, + modifier = Modifier.width(200.dp), + colors = ButtonDefaults.buttonColors( + backgroundColor = customRedColor, + contentColor = Color.White + ) + ) { + Text(languageManager.getCodeToVerifyText()) + } + + Button( + onClick = { + if (mostUsedWordList.isEmpty()) { + noFileSnackbarVisibleState.value = true + println("Veuillez d'abord importer un fichier") + return@Button + } else { + isCompareClicked = true + } + }, + modifier = Modifier.width(200.dp), + colors = ButtonDefaults.buttonColors( + backgroundColor = customRedColor, + contentColor = Color.White + ), + enabled = mostUsedWordList.isNotEmpty() + ) { + Text(languageManager.getCompareText()) } } - ) { - Text("Veuillez d'abord importer un fichier") + } + + if (noFileSnackbarVisibleState.value) { + Snackbar( + modifier = Modifier.padding(16.dp), + action = { + Button( + onClick = { noFileSnackbarVisibleState.value = false }, + colors = ButtonDefaults.buttonColors( + backgroundColor = customRedColor, + contentColor = Color.White + ) + ) { + Text("OK") + } + } + ) { + Text("Veuillez d'abord importer un fichier") + } } } + } - if (isCompareClicked) { - println(mostUsedWordList.keys.toList()) + if (isCompareClicked && selectedGlossary == null) { + GlossaryList(glossaries = loadGlossaries()) { glossary -> + selectedGlossary = glossary + } + } else if (isCompareClicked) { + selectedGlossary?.let { compareResults( - glossaryWords = loadDatasFromFile("glossaire.json"), + glossaryWords = loadDatasFromFile(it.jsonFilePath), codeWords = mostUsedWordList.keys.toList(), - onBackClick = { isCompareClicked = false } + onBackClick = { isCompareClicked = false; selectedGlossary = null } ) } } -} \ No newline at end of file +} + +@Composable +fun GlossaryList(glossaries: List, onGlossarySelected: (Glossary) -> Unit) { + Column( + modifier = Modifier.fillMaxSize(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text("Sélectionnez un glossaire", style = MaterialTheme.typography.h5) + + Spacer(modifier = Modifier.height(16.dp)) + + LazyColumn( + modifier = Modifier.padding(10.dp), + verticalArrangement = Arrangement.spacedBy(10.dp) + ) { + items(glossaries) { glossary -> + Row( + modifier = Modifier.width(200.dp).fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween + ) { + Button( + onClick = { + onGlossarySelected(glossary) + }, + colors = ButtonDefaults.buttonColors( + backgroundColor = customRedColor, + contentColor = Color.White + ) + ) { + Text(glossary.name) + } + } + } + } + Spacer(modifier = Modifier.height(6.dp)) + + } +} + + diff --git a/src/main/kotlin/main/Main.kt b/src/main/kotlin/main/Main.kt index f19661a..2ff56d9 100644 --- a/src/main/kotlin/main/Main.kt +++ b/src/main/kotlin/main/Main.kt @@ -21,6 +21,7 @@ import java.util.* val customRedColor = Color(0xFFB70D1B) +val currentPage = mutableStateOf("accueil") @OptIn(ExperimentalMaterialApi::class) @Composable @@ -28,7 +29,6 @@ val customRedColor = Color(0xFFB70D1B) fun app() { val languageManager = remember { LanguageManager() } MaterialTheme { - val currentPage = remember { mutableStateOf("accueil") } var glossaryDetail: List by remember { mutableStateOf(emptyList()) } var isJavaScriptFileSelected by remember { mutableStateOf(false) } @@ -52,7 +52,7 @@ fun app() { homePage( languageManager, onGlossaryClick = { currentPage.value = "glossaires" }, - onCodeToVerifyClick = { currentPage.value = "choixLangage" } + onCodeToVerifyClick = { currentPage.value = "choixLangage" }, ) } @@ -372,6 +372,7 @@ fun app() { Text("Ce glossaire existe déjà.") } } + } }