Change view detail

main
CAPEL Maxime 2024-01-12 10:31:38 +01:00
parent f611891c09
commit b54f734bd7
3 changed files with 93 additions and 200 deletions

View File

@ -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<Word>,
onBackClick: () -> Unit,
onAddWordClick: () -> Unit
onAddWordClick: () -> Unit,
onExportClick: () -> Unit,
onImportClick: () -> Unit
) {
Column(
modifier = Modifier.fillMaxSize(),
@ -37,10 +40,81 @@ 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

View File

@ -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<String>, onFileSelected: (String) -> Unit) {
val fileDialog = FileDialog(frame, "Select a file", FileDialog.LOAD)

View File

@ -102,7 +102,7 @@ fun app() {
Button(
onClick = {
selectedGlossary = glossary
currentPage.value = "glossaireOptions"
currentPage.value = "glossaireDetail"
},
modifier = Modifier
.width(150.dp),
@ -296,16 +296,11 @@ fun app() {
)
}
"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" }
onImportClick = {
selectFile(setOf("csv", "xlsx")) { filePath ->
println("Importing file: $filePath")
selectedGlossary?.let { importFile(it, filePath) }
}
}
"glossaireDetail" -> {
glossaryDetailedPage(
glossary = glossaryDetail,
onBackClick = { currentPage.value = "glossaireOptions" },
onAddWordClick = { currentPage.value = "formulaire" },
)
}
"formulaire" -> {
selectedGlossary?.let { formPage(it, onCancelClick = { currentPage.value = "glossaireOptions" }) }
selectedGlossary?.let { formPage(it, onCancelClick = { currentPage.value = "glossaireDetail" }) }
}
"choixLangage" -> {