diff --git a/src/main/kotlin/main/Detail.kt b/src/main/kotlin/main/Detail.kt index 88d9c25..bf6e16a 100644 --- a/src/main/kotlin/main/Detail.kt +++ b/src/main/kotlin/main/Detail.kt @@ -6,11 +6,11 @@ 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.material.MaterialTheme -import androidx.compose.material.Text +import androidx.compose.material.* import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.* +import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -18,11 +18,14 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import main.component.buttonComponent +@OptIn(ExperimentalMaterialApi::class) @Composable fun glossaryDetailedPage( glossary: List, onBackClick: () -> Unit, - onAddWordClick: () -> Unit + onAddWordClick: () -> Unit, + onExportClick: () -> Unit, + onImportClick: () -> Unit ) { Column( modifier = Modifier.fillMaxSize(), @@ -37,11 +40,82 @@ fun glossaryDetailedPage( Spacer(modifier = Modifier.height(16.dp)) - buttonComponent(text = "Retour", onClick = { onBackClick() }, icon = Icons.Filled.ArrowBack, width = 150) - buttonComponent(text = "Ajouter un mot", onClick = { onAddWordClick() }, icon = Icons.Filled.Add, width = 150) + Row { + buttonComponent(text = "Retour", onClick = { onBackClick() }, icon = Icons.Filled.ArrowBack, width = 150, modifier = Modifier.padding(10.dp)) + buttonComponent(text = "Ajouter un mot", onClick = { onAddWordClick() }, width = 150, modifier = Modifier.padding(10.dp)) + buttonComponent(text = "Exporter un fichier", onClick = { onExportClick() }, width = 150, modifier = Modifier.padding(10.dp)) + if (exportedSuccessfully.value) { + AlertDialog( + onDismissRequest = { exportedSuccessfully.value = false }, + title = { Text("Exportation réussie") }, + text = { Text("Le fichier a été exporté avec succès") }, + confirmButton = { + Button( + onClick = { exportedSuccessfully.value = false }, + colors = ButtonDefaults.buttonColors( + backgroundColor = customRedColor, + contentColor = Color.White + ) + ) { + Text("OK") + } + } + ) + } + buttonComponent(text = "Importer un fichier", onClick = { onImportClick() }, width = 150, modifier = Modifier.padding(10.dp)) + if (importedSuccessfully.value) { + AlertDialog( + onDismissRequest = { importedSuccessfully.value = false }, + title = { Text("Importation réussie") }, + text = { Text("Le fichier a été importé avec succès") }, + confirmButton = { + Button( + onClick = { + importedSuccessfully.value = false + frame.dispose() + }, + colors = ButtonDefaults.buttonColors( + backgroundColor = customRedColor, + contentColor = Color.White + ) + ) { + Text("OK") + } + } + ) + + } + + if (errorImportation.value) { + AlertDialog( + onDismissRequest = { errorImportation.value = false }, + title = { Text("Importation Echouée") }, + text = { Text("Le fichier n'a pas pu être importé") }, + confirmButton = { + Button( + onClick = { + errorImportation.value = false + frame.dispose() + }, + colors = ButtonDefaults.buttonColors( + backgroundColor = customRedColor, + contentColor = Color.White + ) + ) { + Text("OK") + } + } + ) + } + } } + } +var importedSuccessfully = mutableStateOf(false) +var errorImportation = mutableStateOf(false) +var exportedSuccessfully = mutableStateOf(false) + // Faire un tableau qui affiche les mots et leur définition @Composable fun glossaryTable(glossary: List) { diff --git a/src/main/kotlin/main/Glossary.kt b/src/main/kotlin/main/Glossary.kt index 1dcab5c..699d478 100644 --- a/src/main/kotlin/main/Glossary.kt +++ b/src/main/kotlin/main/Glossary.kt @@ -1,12 +1,5 @@ package main -import androidx.compose.foundation.layout.* -import androidx.compose.material.* -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 org.apache.poi.ss.usermodel.CellType import org.apache.poi.ss.usermodel.Workbook import org.apache.poi.xssf.usermodel.XSSFWorkbook @@ -21,170 +14,7 @@ import java.io.File data class Glossary(val name: String, val jsonFilePath: String) val frame = Frame() -@OptIn(ExperimentalMaterialApi::class) -@Composable -fun glossaryPage( - languageManager: LanguageManager, - onAddWordClick: () -> Unit, - onImportClick: () -> Unit, - onExportClick: () -> Unit, - onSeeGlossaryClick: () -> Unit, - glossary: Glossary, - onBackClick: () -> Unit, -) { - - Column( - modifier = Modifier.fillMaxSize(), - verticalArrangement = Arrangement.Top, // Align content at the top - horizontalAlignment = Alignment.CenterHorizontally - ) { - Text(text = languageManager.getGlossaryTitle() + ": " + glossary.name, style = MaterialTheme.typography.h3) - } - - Column( - modifier = Modifier - .fillMaxSize() // Fills the maximum available width - .padding(16.dp), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - - ) { - - Button( - onClick = onAddWordClick, - modifier = Modifier - .width(300.dp), - colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ) - ) { - Text(languageManager.getAddWordText()) - } - - Button( - onClick = onImportClick, - modifier = Modifier - .width(300.dp), - colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ) - ) { - Text(languageManager.getImportText()) - } - - if (importedSuccessfully.value) { - AlertDialog( - onDismissRequest = { importedSuccessfully.value = false }, - title = { Text("Importation réussie") }, - text = { Text("Le fichier a été importé avec succès") }, - confirmButton = { - Button( - onClick = { - importedSuccessfully.value = false - frame.dispose() - }, - colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ) - ) { - Text("OK") - } - } - ) - - } - - if (errorImportation.value) { - AlertDialog( - onDismissRequest = { errorImportation.value = false }, - title = { Text("Importation Echouée") }, - text = { Text("Le fichier n'a pas pu être importé") }, - confirmButton = { - Button( - onClick = { - errorImportation.value = false - frame.dispose() - }, - colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ) - ) { - Text("OK") - } - } - ) - } - - - Button( - onClick = onExportClick, - modifier = Modifier - .width(300.dp), - colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ) - ) { - Text(languageManager.getExportText()) - } - - if (exportedSuccessfully.value) { - AlertDialog( - onDismissRequest = { exportedSuccessfully.value = false }, - title = { Text("Exportation réussie") }, - text = { Text("Le fichier a été exporté avec succès") }, - confirmButton = { - Button( - onClick = { exportedSuccessfully.value = false }, - colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ) - ) { - Text("OK") - } - } - ) - } - - Button( - onClick = onSeeGlossaryClick, - modifier = Modifier - .width(300.dp), - colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ) - ) { - Text(languageManager.getSeeGlossaryText()) - } - } - - Column( - modifier = Modifier.fillMaxSize().padding(20.dp), - verticalArrangement = Arrangement.Bottom, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Button( - onClick = onBackClick, - colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ) - ) { - Text(languageManager.getBackButtonText()) - } - } -} - -var importedSuccessfully = mutableStateOf(false) -var errorImportation = mutableStateOf(false) -var exportedSuccessfully = mutableStateOf(false) fun selectFile(extensions: Set, onFileSelected: (String) -> Unit) { val fileDialog = FileDialog(frame, "Select a file", FileDialog.LOAD) diff --git a/src/main/kotlin/main/Main.kt b/src/main/kotlin/main/Main.kt index 1d0ab9f..aacba80 100644 --- a/src/main/kotlin/main/Main.kt +++ b/src/main/kotlin/main/Main.kt @@ -102,7 +102,7 @@ fun app() { Button( onClick = { selectedGlossary = glossary - currentPage.value = "glossaireOptions" + currentPage.value = "glossaireDetail" }, modifier = Modifier .width(150.dp), @@ -295,17 +295,12 @@ fun app() { currentPage = currentPage ) } - - "glossaireOptions" -> { - glossaryPage( - languageManager, + + "glossaireDetail" -> { + glossaryDetailedPage( + glossary = glossaryDetail, + onBackClick = { currentPage.value = "glossaires" }, onAddWordClick = { currentPage.value = "formulaire" }, - onImportClick = { - selectFile(setOf("csv", "xlsx")) { filePath -> - println("Importing file: $filePath") - selectedGlossary?.let { importFile(it, filePath) } - } - }, onExportClick = { val fileDialog = FileDialog(Frame(), "Save as CSV", FileDialog.SAVE) fileDialog.file = selectedGlossary?.name // Initial file name @@ -320,23 +315,17 @@ fun app() { println("Export command cancelled by user.") } }, - onSeeGlossaryClick = { - glossaryDetail = selectedGlossary?.let { loadDatasFromFile(it.jsonFilePath) }!! - currentPage.value = "glossaireDetail" - }, - glossary = selectedGlossary!!, - ) { currentPage.value = "glossaires" } - } - "glossaireDetail" -> { - glossaryDetailedPage( - glossary = glossaryDetail, - onBackClick = { currentPage.value = "glossaireOptions" }, - onAddWordClick = { currentPage.value = "formulaire" }, + onImportClick = { + selectFile(setOf("csv", "xlsx")) { filePath -> + println("Importing file: $filePath") + selectedGlossary?.let { importFile(it, filePath) } + } + } ) } "formulaire" -> { - selectedGlossary?.let { formPage(it, onCancelClick = { currentPage.value = "glossaireOptions" }) } + selectedGlossary?.let { formPage(it, onCancelClick = { currentPage.value = "glossaireDetail" }) } } "choixLangage" -> {