From 04ed49e551f767ea87e6fee97734cab3afd6e69d Mon Sep 17 00:00:00 2001 From: CAPEL Maxime <83071634+fortyup@users.noreply.github.com> Date: Mon, 15 Jan 2024 10:21:10 +0100 Subject: [PATCH] Add menu button on every views --- src/main/kotlin/main/Compare.kt | 34 ++++++++- src/main/kotlin/main/Detail.kt | 29 +++++++- src/main/kotlin/main/Glossary.kt | 24 +++++- src/main/kotlin/main/Home.kt | 73 +++++++++++++++++-- src/main/kotlin/main/Main.kt | 22 ++++-- src/main/kotlin/main/Projects.kt | 25 ++++++- src/main/kotlin/main/Verify.kt | 56 ++++++++++++-- .../kotlin/main/{ => component}/MenuButton.kt | 3 +- src/main/kotlin/main/nb_occurrence.kt | 33 ++++++++- 9 files changed, 269 insertions(+), 30 deletions(-) rename src/main/kotlin/main/{ => component}/MenuButton.kt (97%) diff --git a/src/main/kotlin/main/Compare.kt b/src/main/kotlin/main/Compare.kt index e1b3946..46be770 100644 --- a/src/main/kotlin/main/Compare.kt +++ b/src/main/kotlin/main/Compare.kt @@ -6,28 +6,36 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.Button +import androidx.compose.material.MaterialTheme import androidx.compose.material.Text -import androidx.compose.runtime.Composable +import androidx.compose.runtime.* 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 +import main.component.dropdownButtonComponent +import org.apache.poi.ss.usermodel.HorizontalAlignment @Composable fun compareResults( glossaryWords: List, codeWords: List, - onBackClick: () -> Unit + onBackClick: () -> Unit, + onProjectClick: () -> Unit, + onCodeToVerifyClick: () -> Unit, ) { println(glossaryWords) val commonWords = findCommonWords(glossaryWords, codeWords) + var isCompareClicked by remember { mutableStateOf(false) } + val noFileSnackbarVisibleState = remember { mutableStateOf(false) } Column( modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Top, horizontalAlignment = Alignment.CenterHorizontally ) { + Text(text = "Comparaison glossaire / code", style = MaterialTheme.typography.h3) Spacer(modifier = Modifier.height(16.dp)) @@ -36,9 +44,10 @@ fun compareResults( Spacer(modifier = Modifier.height(16.dp)) // Légende - Column( + Row( modifier = Modifier.fillMaxWidth().padding(16.dp), - verticalArrangement = Arrangement.spacedBy(8.dp), + // Espace entre les éléments + horizontalArrangement = Arrangement.spacedBy(16.dp) ) { LegendItem(color = Color.Green, label = "Mot dans le glossaire et dans le code") LegendItem(color = Color.White, label = "Mot seulement dans le glossaire") @@ -58,6 +67,23 @@ fun compareResults( Text("Retour") } } + dropdownButtonComponent( + items = listOf("Glossaire", "Code à vérifier", "Comparer") + ) { selectedOption -> + // Handle the selected option + when (selectedOption) { + "Glossaire" -> onProjectClick() + "Code à vérifier" -> onCodeToVerifyClick() + "Comparer" -> { + if (mostUsedWordList.isEmpty()) { + noFileSnackbarVisibleState.value = true + return@dropdownButtonComponent + } else { + isCompareClicked = true + } + } + } + } } // Ajouter une légende au tableau diff --git a/src/main/kotlin/main/Detail.kt b/src/main/kotlin/main/Detail.kt index 7419fe3..76f4662 100644 --- a/src/main/kotlin/main/Detail.kt +++ b/src/main/kotlin/main/Detail.kt @@ -9,14 +9,14 @@ import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack -import androidx.compose.runtime.Composable -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.* 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 import main.component.buttonComponent +import main.component.dropdownButtonComponent @OptIn(ExperimentalMaterialApi::class) @Composable @@ -26,8 +26,13 @@ fun glossaryDetailedPage( onBackClick: () -> Unit, onAddWordClick: () -> Unit, onExportClick: () -> Unit, - onImportClick: () -> Unit + onImportClick: () -> Unit, + onProjectClick: () -> Unit, + onCodeToVerifyClick: () -> Unit, ) { + var isCompareClicked by remember { mutableStateOf(false) } + val noFileSnackbarVisibleState = remember { mutableStateOf(false) } + println(glossary) Column( modifier = Modifier.fillMaxSize(), @@ -124,7 +129,23 @@ fun glossaryDetailedPage( } } } - + dropdownButtonComponent( + items = listOf("Glossaire", "Code à vérifier", "Comparer") + ) { selectedOption -> + // Handle the selected option + when (selectedOption) { + "Glossaire" -> onProjectClick() + "Code à vérifier" -> onCodeToVerifyClick() + "Comparer" -> { + if (mostUsedWordList.isEmpty()) { + noFileSnackbarVisibleState.value = true + return@dropdownButtonComponent + } else { + isCompareClicked = true + } + } + } + } } var importedSuccessfully = mutableStateOf(false) diff --git a/src/main/kotlin/main/Glossary.kt b/src/main/kotlin/main/Glossary.kt index 86b6eab..05bf36b 100644 --- a/src/main/kotlin/main/Glossary.kt +++ b/src/main/kotlin/main/Glossary.kt @@ -29,6 +29,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.key.* import androidx.compose.ui.unit.dp +import main.component.dropdownButtonComponent data class Glossary(val name: String, val jsonFilePath: String) @@ -37,10 +38,14 @@ val frame = Frame() @Composable fun glossariesPage( - currentPage: MutableState + currentPage: MutableState, + onProjectClick: () -> Unit, + onCodeToVerifyClick: () -> Unit ) { var glossaries by remember { mutableStateOf(emptyList()) } + var isCompareClicked by remember { mutableStateOf(false) } + val noFileSnackbarVisibleState = remember { mutableStateOf(false) } Column( modifier = Modifier.fillMaxSize(), @@ -148,6 +153,23 @@ fun glossariesPage( Text("Retour") } } + dropdownButtonComponent( + items = listOf("Glossaire", "Code à vérifier", "Comparer") + ) { selectedOption -> + // Handle the selected option + when (selectedOption) { + "Glossaire" -> onProjectClick() + "Code à vérifier" -> onCodeToVerifyClick() + "Comparer" -> { + if (mostUsedWordList.isEmpty()) { + noFileSnackbarVisibleState.value = true + return@dropdownButtonComponent + } else { + isCompareClicked = true + } + } + } + } } @OptIn(ExperimentalStdlibApi::class, ExperimentalComposeUiApi::class) diff --git a/src/main/kotlin/main/Home.kt b/src/main/kotlin/main/Home.kt index 91babdb..05a4fbe 100644 --- a/src/main/kotlin/main/Home.kt +++ b/src/main/kotlin/main/Home.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import main.component.buttonComponent +import main.component.dropdownButtonComponent var mostUsedWordList = mutableMapOf() @@ -143,7 +144,9 @@ fun homePage( isCompareClicked = false selectedGlossary = null selectedProject = null - } + }, + onProjectClick = { currentPage.value = "projects" }, + onCodeToVerifyClick = { currentPage.value = "choixLangage" } ) } @@ -157,7 +160,9 @@ fun homePage( isCompareClicked = false selectedGlossary = null selectedProject = null - } + }, + onProjectClick = { currentPage.value = "projects" }, + onCodeToVerifyClick = { currentPage.value = "choixLangage" } ) } @@ -170,8 +175,11 @@ fun homePage( isCompareClicked = false selectedGlossary = null selectedProject = null - } + }, + onProjectClick = { currentPage.value = "projects" }, + onCodeToVerifyClick = { currentPage.value = "choixLangage" }, ) + } } } @@ -184,7 +192,17 @@ fun homePage( } @Composable -fun glossaryList(glossaries: List, onGlossarySelected: (Glossary) -> Unit, onBackClick: () -> Unit) { +fun glossaryList( + glossaries: List, + onGlossarySelected: (Glossary) -> Unit, + onBackClick: () -> Unit, + onProjectClick: () -> Unit, + onCodeToVerifyClick: () -> Unit +) { + + var isCompareClicked by remember { mutableStateOf(false) } + val noFileSnackbarVisibleState = remember { mutableStateOf(false) } + Column( modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Center, @@ -234,10 +252,38 @@ fun glossaryList(glossaries: List, onGlossarySelected: (Glossary) -> U buttonComponent("Retour", onBackClick) } + + dropdownButtonComponent( + items = listOf("Glossaire", "Code à vérifier", "Comparer") + ) { selectedOption -> + // Handle the selected option + when (selectedOption) { + "Glossaire" -> onProjectClick() + "Code à vérifier" -> onCodeToVerifyClick() + "Comparer" -> { + if (mostUsedWordList.isEmpty()) { + noFileSnackbarVisibleState.value = true + return@dropdownButtonComponent + } else { + isCompareClicked = true + } + } + } + } } @Composable -fun projectList(projects: List, onProjectSelected: (Project) -> Unit, onBackClick: () -> Unit) { +fun projectList( + projects: List, + onProjectSelected: (Project) -> Unit, + onBackClick: () -> Unit, + onProjectClick: () -> Unit, + onCodeToVerifyClick: () -> Unit +) { + + var isCompareClicked by remember { mutableStateOf(false) } + val noFileSnackbarVisibleState = remember { mutableStateOf(false) } + Column( modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Center, @@ -287,4 +333,21 @@ fun projectList(projects: List, onProjectSelected: (Project) -> Unit, o buttonComponent("Retour", onBackClick) } + dropdownButtonComponent( + items = listOf("Glossaire", "Code à vérifier", "Comparer") + ) { selectedOption -> + // Handle the selected option + when (selectedOption) { + "Glossaire" -> onProjectClick() + "Code à vérifier" -> onCodeToVerifyClick() + "Comparer" -> { + if (mostUsedWordList.isEmpty()) { + noFileSnackbarVisibleState.value = true + return@dropdownButtonComponent + } else { + isCompareClicked = true + } + } + } + } } \ No newline at end of file diff --git a/src/main/kotlin/main/Main.kt b/src/main/kotlin/main/Main.kt index 9413f9d..affac50 100644 --- a/src/main/kotlin/main/Main.kt +++ b/src/main/kotlin/main/Main.kt @@ -57,6 +57,8 @@ fun app() { "glossaires" -> { glossariesPage( currentPage = currentPage, + onProjectClick = { currentPage.value = "projets" }, + onCodeToVerifyClick = { currentPage.value = "choixLangage" }, ) } @@ -70,7 +72,9 @@ fun app() { "projects" -> { projectsPage( - currentPage = currentPage + currentPage = currentPage, + onProjectClick = { currentPage.value = "projects" }, + onCodeToVerifyClick = { currentPage.value = "choixLangage" }, ) } @@ -106,7 +110,9 @@ fun app() { println("Importing file: $filePath") appState.selectedGlossary?.let { importFile(it, filePath) } } - } + }, + onProjectClick = { currentPage.value = "projects" }, + onCodeToVerifyClick = { currentPage.value = "choixLangage" }, ) } } @@ -137,11 +143,18 @@ fun app() { mostUsedWordList = parser(filePath) // Change by parser functions isJavaScriptFileSelected = true } - } + }, + onProjectClick = { currentPage.value = "projects" }, + onCodeToVerifyClick = { currentPage.value = "choixLangage" }, ) } "occurrence" -> { - parsedWordsTable(mostUsedWordList, onBackClick = { currentPage.value = "choixLangage" }) + parsedWordsTable( + mostUsedWordList, + onBackClick = { currentPage.value = "choixLangage" }, + onProjectClick = { currentPage.value = "projects" }, + onCodeToVerifyClick = { currentPage.value = "choixLangage" }, + ) } } if (isJavaScriptFileSelected) { @@ -161,7 +174,6 @@ fun app() { onClick = { // Handle the confirm button action isJavaScriptFileSelected = false - currentPage.value = "occurrence" }, colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, diff --git a/src/main/kotlin/main/Projects.kt b/src/main/kotlin/main/Projects.kt index fd00d2e..e46e2ef 100644 --- a/src/main/kotlin/main/Projects.kt +++ b/src/main/kotlin/main/Projects.kt @@ -16,6 +16,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.key.* import androidx.compose.ui.unit.dp +import main.component.dropdownButtonComponent import java.io.File data class Project(val name: String) @@ -28,16 +29,21 @@ fun loadProjects(): List { @Composable fun projectsPage( - currentPage: MutableState + currentPage: MutableState, + onProjectClick: () -> Unit, + onCodeToVerifyClick: () -> Unit ) { val appState = AppState + val noFileSnackbarVisibleState = remember { mutableStateOf(false) } var projects: List by remember { mutableStateOf(loadProjects()) } + var isCompareClicked by remember { mutableStateOf(false) } Column( modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally ) { + Text("Sélectionnez un projet", style = MaterialTheme.typography.h5) Spacer(modifier = Modifier.height(16.dp)) @@ -135,6 +141,23 @@ fun projectsPage( Text("Retour") } } + dropdownButtonComponent( + items = listOf("Glossaire", "Code à vérifier", "Comparer") + ) { selectedOption -> + // Handle the selected option + when (selectedOption) { + "Glossaire" -> onProjectClick() + "Code à vérifier" -> onCodeToVerifyClick() + "Comparer" -> { + if (mostUsedWordList.isEmpty()) { + noFileSnackbarVisibleState.value = true + return@dropdownButtonComponent + } else { + isCompareClicked = true + } + } + } + } } @OptIn(ExperimentalComposeUiApi::class) diff --git a/src/main/kotlin/main/Verify.kt b/src/main/kotlin/main/Verify.kt index 5f8e7fb..9d6db31 100644 --- a/src/main/kotlin/main/Verify.kt +++ b/src/main/kotlin/main/Verify.kt @@ -5,11 +5,12 @@ 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.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp +import main.component.dropdownButtonComponent @Composable fun choixLangagePage( @@ -17,8 +18,12 @@ fun choixLangagePage( onBackClick: () -> Unit, onPythonClick: () -> Unit, onJavaClick: () -> Unit, - onJavaScriptClick: () -> Unit + onJavaScriptClick: () -> Unit, + onProjectClick: () -> Unit, + onCodeToVerifyClick: () -> Unit, ) { + var isCompareClicked by remember { mutableStateOf(false) } + val noFileSnackbarVisibleState = remember { mutableStateOf(false) } Column( modifier = Modifier.fillMaxSize(), @@ -40,7 +45,7 @@ fun choixLangagePage( Button( onClick = onPythonClick, modifier = Modifier - .width(125.dp), + .width(150.dp), colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White @@ -53,7 +58,7 @@ fun choixLangagePage( Button( onClick = onJavaClick, modifier = Modifier - .width(125.dp), + .width(150.dp), colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White @@ -66,7 +71,7 @@ fun choixLangagePage( Button( onClick = onJavaScriptClick, modifier = Modifier - .width(125.dp), + .width(150.dp), colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White @@ -74,6 +79,29 @@ fun choixLangagePage( ) { Text("JavaScript") } + + // Faire un bouton qui affiche la vue "occurence" si on a déjà importer un fichier + // Sinon afficher un snackbar qui dit qu'il faut importer un fichier + Button( + onClick = { + if (mostUsedWordList.isEmpty()) { + noFileSnackbarVisibleState.value = true + return@Button + } else { + isCompareClicked = true + currentPage.value = "occurrence" + } + }, + modifier = Modifier + .width(150.dp), + colors = ButtonDefaults.buttonColors( + backgroundColor = customRedColor, + contentColor = Color.White + ), + enabled = mostUsedWordList.isNotEmpty() + ) { + Text("Mots parsés") + } } Column( @@ -91,5 +119,21 @@ fun choixLangagePage( Text(languageManager.getBackButtonText()) } } - + dropdownButtonComponent( + items = listOf("Glossaire", "Code à vérifier", "Comparer") + ) { selectedOption -> + // Handle the selected option + when (selectedOption) { + "Glossaire" -> onProjectClick() + "Code à vérifier" -> onCodeToVerifyClick() + "Comparer" -> { + if (mostUsedWordList.isEmpty()) { + noFileSnackbarVisibleState.value = true + return@dropdownButtonComponent + } else { + isCompareClicked = true + } + } + } + } } \ No newline at end of file diff --git a/src/main/kotlin/main/MenuButton.kt b/src/main/kotlin/main/component/MenuButton.kt similarity index 97% rename from src/main/kotlin/main/MenuButton.kt rename to src/main/kotlin/main/component/MenuButton.kt index 55f7c01..cc5cb08 100644 --- a/src/main/kotlin/main/MenuButton.kt +++ b/src/main/kotlin/main/component/MenuButton.kt @@ -1,4 +1,4 @@ -package main +package main.component import androidx.compose.foundation.layout.* import androidx.compose.material.* @@ -8,6 +8,7 @@ import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp +import main.customRedColor @Composable fun dropdownButtonComponent( diff --git a/src/main/kotlin/main/nb_occurrence.kt b/src/main/kotlin/main/nb_occurrence.kt index 5a955f9..05022e6 100644 --- a/src/main/kotlin/main/nb_occurrence.kt +++ b/src/main/kotlin/main/nb_occurrence.kt @@ -8,21 +8,31 @@ import androidx.compose.foundation.lazy.items import androidx.compose.material.Button import androidx.compose.material.MaterialTheme import androidx.compose.material.Text -import androidx.compose.runtime.Composable +import androidx.compose.runtime.* 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 +import main.component.dropdownButtonComponent @Composable -fun parsedWordsTable(parsedWords: Map, onBackClick: () -> Unit) { +fun parsedWordsTable( + parsedWords: Map, + onBackClick: () -> Unit, + onProjectClick: () -> Unit, + onCodeToVerifyClick: () -> Unit, +) { + + var isCompareClicked by remember { mutableStateOf(false) } + val noFileSnackbarVisibleState = remember { mutableStateOf(false) } + Column( modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Top, horizontalAlignment = Alignment.CenterHorizontally ) { - Text(text = "Mots Parsés", style = MaterialTheme.typography.h3) + Text(text = "Mots parsés", style = MaterialTheme.typography.h3) Spacer(modifier = Modifier.height(16.dp)) @@ -48,6 +58,23 @@ fun parsedWordsTable(parsedWords: Map, onBackClick: () -> Unit) { Text("Retour") } } + dropdownButtonComponent( + items = listOf("Glossaire", "Code à vérifier", "Comparer") + ) { selectedOption -> + // Handle the selected option + when (selectedOption) { + "Glossaire" -> onProjectClick() + "Code à vérifier" -> onCodeToVerifyClick() + "Comparer" -> { + if (mostUsedWordList.isEmpty()) { + noFileSnackbarVisibleState.value = true + return@dropdownButtonComponent + } else { + isCompareClicked = true + } + } + } + } } @Composable