Add menu button on every views

main
CAPEL Maxime 2024-01-15 10:21:10 +01:00
parent 60d7cf84c6
commit 04ed49e551
9 changed files with 269 additions and 30 deletions

View File

@ -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<Word>,
codeWords: List<String>,
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

View File

@ -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)

View File

@ -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<String>
currentPage: MutableState<String>,
onProjectClick: () -> Unit,
onCodeToVerifyClick: () -> Unit
) {
var glossaries by remember { mutableStateOf(emptyList<Glossary>()) }
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)

View File

@ -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<String, Int>()
@ -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<Glossary>, onGlossarySelected: (Glossary) -> Unit, onBackClick: () -> Unit) {
fun glossaryList(
glossaries: List<Glossary>,
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<Glossary>, 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<Project>, onProjectSelected: (Project) -> Unit, onBackClick: () -> Unit) {
fun projectList(
projects: List<Project>,
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<Project>, 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
}
}
}
}
}

View File

@ -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,

View File

@ -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<Project> {
@Composable
fun projectsPage(
currentPage: MutableState<String>
currentPage: MutableState<String>,
onProjectClick: () -> Unit,
onCodeToVerifyClick: () -> Unit
) {
val appState = AppState
val noFileSnackbarVisibleState = remember { mutableStateOf(false) }
var projects: List<Project> 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)

View File

@ -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
}
}
}
}
}

View File

@ -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(

View File

@ -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<String, Int>, onBackClick: () -> Unit) {
fun parsedWordsTable(
parsedWords: Map<String, Int>,
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<String, Int>, 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