From 08e8577a5c2162ace024ad442edd5b787db32db5 Mon Sep 17 00:00:00 2001 From: CAPEL Maxime <83071634+fortyup@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:33:09 +0100 Subject: [PATCH] Split compare view in different files --- src/main/kotlin/main/CompareGlossary.kt | 99 ++++++++++++++ src/main/kotlin/main/CompareProject.kt | 98 ++++++++++++++ src/main/kotlin/main/Home.kt | 165 ------------------------ 3 files changed, 197 insertions(+), 165 deletions(-) create mode 100644 src/main/kotlin/main/CompareGlossary.kt create mode 100644 src/main/kotlin/main/CompareProject.kt diff --git a/src/main/kotlin/main/CompareGlossary.kt b/src/main/kotlin/main/CompareGlossary.kt new file mode 100644 index 0000000..bebcf18 --- /dev/null +++ b/src/main/kotlin/main/CompareGlossary.kt @@ -0,0 +1,99 @@ +package main + +import androidx.compose.foundation.VerticalScrollbar +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.rememberScrollbarAdapter +import androidx.compose.material.MaterialTheme +import androidx.compose.material.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import main.component.buttonComponent +import main.component.dropdownButtonComponent + +@Composable +fun glossaryList( + languageManager: LanguageManager, + 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, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text("Sélectionnez un glossaire", style = MaterialTheme.typography.h5) + + Spacer(modifier = Modifier.height(16.dp)) + + Box( + modifier = Modifier + .height(500.dp) + .width(250.dp) + .padding(10.dp) + ) { + val scrollState = rememberLazyListState() + LazyColumn( + state = scrollState, + modifier = Modifier + .padding(10.dp) + .width(200.dp), + verticalArrangement = Arrangement.spacedBy(10.dp) + ) { + if (glossaries.isEmpty()) { + item { + Text("Aucun glossaire disponible") + } + } else { + items(glossaries) { glossary -> + Row( + modifier = Modifier.width(200.dp).fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + buttonComponent(glossary.name, { onGlossarySelected(glossary) }, width = 200) + } + } + } + } + VerticalScrollbar( + modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(), + adapter = rememberScrollbarAdapter(scrollState) + ) + Spacer(modifier = Modifier.height(6.dp)) + } + Spacer(modifier = Modifier.height(16.dp)) + + buttonComponent("Retour", onBackClick) + } + + dropdownButtonComponent( + languageManager, + 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/CompareProject.kt b/src/main/kotlin/main/CompareProject.kt new file mode 100644 index 0000000..1c285e1 --- /dev/null +++ b/src/main/kotlin/main/CompareProject.kt @@ -0,0 +1,98 @@ +package main + +import androidx.compose.foundation.VerticalScrollbar +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.rememberScrollbarAdapter +import androidx.compose.material.MaterialTheme +import androidx.compose.material.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import main.component.buttonComponent +import main.component.dropdownButtonComponent + +@Composable +fun projectList( + languageManager: LanguageManager, + 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, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text("Sélectionnez un projet", style = MaterialTheme.typography.h5) + + Spacer(modifier = Modifier.height(16.dp)) + + Box( + modifier = Modifier + .height(500.dp) + .width(250.dp) + .padding(10.dp) + ) { + val scrollState = rememberLazyListState() + LazyColumn( + state = scrollState, + modifier = Modifier + .padding(10.dp) + .width(200.dp), + verticalArrangement = Arrangement.spacedBy(10.dp) + ) { + if (projects.isEmpty()) { + item { + Text("Aucun glossaire disponible") + } + } else { + items(projects) { project -> + Row( + modifier = Modifier.width(200.dp).fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + buttonComponent(project.name, { onProjectSelected(project) }, width = 200) + } + } + } + } + VerticalScrollbar( + modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(), + adapter = rememberScrollbarAdapter(scrollState) + ) + Spacer(modifier = Modifier.height(6.dp)) + } + Spacer(modifier = Modifier.height(16.dp)) + + buttonComponent("Retour", onBackClick) + } + dropdownButtonComponent( + languageManager, + 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/Home.kt b/src/main/kotlin/main/Home.kt index 31d4599..a64699e 100644 --- a/src/main/kotlin/main/Home.kt +++ b/src/main/kotlin/main/Home.kt @@ -193,169 +193,4 @@ fun homePage( } } -} - -@Composable -fun glossaryList( - languageManager: LanguageManager, - 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, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Text("Sélectionnez un glossaire", style = MaterialTheme.typography.h5) - - Spacer(modifier = Modifier.height(16.dp)) - - Box( - modifier = Modifier - .height(500.dp) - .width(250.dp) - .padding(10.dp) - ) { - val scrollState = rememberLazyListState() - LazyColumn( - state = scrollState, - modifier = Modifier - .padding(10.dp) - .width(200.dp), - verticalArrangement = Arrangement.spacedBy(10.dp) - ) { - if (glossaries.isEmpty()) { - item { - Text("Aucun glossaire disponible") - } - } else { - items(glossaries) { glossary -> - Row( - modifier = Modifier.width(200.dp).fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - buttonComponent(glossary.name, { onGlossarySelected(glossary) }, width = 200) - } - } - } - } - VerticalScrollbar( - modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(), - adapter = rememberScrollbarAdapter(scrollState) - ) - Spacer(modifier = Modifier.height(6.dp)) - } - Spacer(modifier = Modifier.height(16.dp)) - - buttonComponent("Retour", onBackClick) - } - - dropdownButtonComponent( - languageManager, - 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( - languageManager: LanguageManager, - 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, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Text("Sélectionnez un projet", style = MaterialTheme.typography.h5) - - Spacer(modifier = Modifier.height(16.dp)) - - Box( - modifier = Modifier - .height(500.dp) - .width(250.dp) - .padding(10.dp) - ) { - val scrollState = rememberLazyListState() - LazyColumn( - state = scrollState, - modifier = Modifier - .padding(10.dp) - .width(200.dp), - verticalArrangement = Arrangement.spacedBy(10.dp) - ) { - if (projects.isEmpty()) { - item { - Text("Aucun glossaire disponible") - } - } else { - items(projects) { project -> - Row( - modifier = Modifier.width(200.dp).fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - buttonComponent(project.name, { onProjectSelected(project) }, width = 200) - } - } - } - } - VerticalScrollbar( - modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(), - adapter = rememberScrollbarAdapter(scrollState) - ) - Spacer(modifier = Modifier.height(6.dp)) - } - Spacer(modifier = Modifier.height(16.dp)) - - buttonComponent("Retour", onBackClick) - } - dropdownButtonComponent( - languageManager, - 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