Split code in many files
parent
ef3ba67abe
commit
21fc7ce28d
|
@ -0,0 +1,75 @@
|
|||
package main
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
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.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun compareResults(
|
||||
glossaryWords: List<Word>,
|
||||
codeWords: List<String>,
|
||||
onBackClick: () -> Unit
|
||||
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Top, // Align content at the top
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
text = "Le code contient ${compareWords(glossaryWords, codeWords)}% des mots du glossaire\"",
|
||||
style = MaterialTheme.typography.h3
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize() // Fills the maximum available width
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
|
||||
) {
|
||||
Text(text = "Le code contient ${compareWords(glossaryWords, codeWords)}% des mots du glossaire")
|
||||
}
|
||||
|
||||
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("Retour")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun compareWords(glossaryWord: List<Word>, wordsCode: List<String>): Int {
|
||||
var foundWords = 0
|
||||
wordsCode.forEach { wordCode ->
|
||||
glossaryWord.forEach { word ->
|
||||
if (wordCode.equals(word.name, ignoreCase = true)) {
|
||||
foundWords++
|
||||
}
|
||||
}
|
||||
}
|
||||
println(foundWords * 100 / wordsCode.size)
|
||||
return foundWords * 100 / wordsCode.size
|
||||
}
|
|
@ -0,0 +1,223 @@
|
|||
package main
|
||||
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
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.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun glossaryDetailedPage(glossary: List<Word>, onBackClick: () -> Unit) {
|
||||
var searchQuery by remember { mutableStateOf("") }
|
||||
var sortOption by remember { mutableStateOf("Nom ↑") }
|
||||
|
||||
var filteredGlossary by remember { mutableStateOf(glossary) }
|
||||
|
||||
val menuExpanded = remember { mutableStateOf(false) }
|
||||
|
||||
// Sort the glossary according to the selected option
|
||||
val sortedGlossaire = remember(glossary, sortOption) {
|
||||
val glossaireCopy = glossary.toMutableList()
|
||||
|
||||
when (sortOption) {
|
||||
"Nom ↑" -> glossaireCopy.sortBy { it.name }
|
||||
"Nom ↓" -> glossaireCopy.sortByDescending { it.name }
|
||||
"Contexte ↑" -> glossaireCopy.sortBy { it.mainContext }
|
||||
"Contexte ↓" -> glossaireCopy.sortByDescending { it.mainContext }
|
||||
}
|
||||
|
||||
glossaireCopy
|
||||
}
|
||||
|
||||
// Update the filtered glossary when the search query changes
|
||||
filteredGlossary = if (searchQuery.isNotEmpty()) {
|
||||
glossary.filter { mot ->
|
||||
mot.name.contains(searchQuery, ignoreCase = true) ||
|
||||
mot.description.contains(searchQuery, ignoreCase = true) ||
|
||||
mot.mainContext.contains(searchQuery, ignoreCase = true) ||
|
||||
mot.secondaryContext.contains(searchQuery, ignoreCase = true) ||
|
||||
mot.relatedTo.contains(searchQuery, ignoreCase = true) ||
|
||||
mot.synonymous.contains(searchQuery, ignoreCase = true) ||
|
||||
mot.antonym.contains(searchQuery, ignoreCase = true)
|
||||
}
|
||||
} else {
|
||||
sortedGlossaire
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
TopAppBar(
|
||||
backgroundColor = customRedColor,
|
||||
title = { Text("Glossaire", color = Color.White) },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBackClick) {
|
||||
Icon(imageVector = Icons.Default.ArrowBack, contentDescription = "Retour", tint = Color.White)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.border(1.dp, customRedColor, RoundedCornerShape(4.dp))
|
||||
.padding(8.dp)
|
||||
.clickable {
|
||||
menuExpanded.value = !menuExpanded.value
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "Trier par: $sortOption",
|
||||
color = Color.Black
|
||||
)
|
||||
}
|
||||
|
||||
DropdownMenu(
|
||||
expanded = menuExpanded.value,
|
||||
onDismissRequest = {
|
||||
menuExpanded.value = false
|
||||
},
|
||||
) {
|
||||
DropdownMenuItem(onClick = {
|
||||
sortOption = "Nom ↑"
|
||||
menuExpanded.value = false
|
||||
}) {
|
||||
Text("Nom ↑")
|
||||
}
|
||||
|
||||
DropdownMenuItem(onClick = {
|
||||
sortOption = "Nom ↓"
|
||||
menuExpanded.value = false
|
||||
}) {
|
||||
Text("Nom ↓")
|
||||
}
|
||||
|
||||
DropdownMenuItem(onClick = {
|
||||
sortOption = "Contexte ↑"
|
||||
menuExpanded.value = false
|
||||
}) {
|
||||
Text("Contexte ↑")
|
||||
}
|
||||
|
||||
DropdownMenuItem(onClick = {
|
||||
sortOption = "Contexte ↓"
|
||||
menuExpanded.value = false
|
||||
}) {
|
||||
Text("Contexte ↓")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OutlinedTextField(
|
||||
value = searchQuery,
|
||||
onValueChange = {
|
||||
searchQuery = it
|
||||
},
|
||||
label = { Text("Rechercher dans le glossaire") },
|
||||
keyboardOptions = KeyboardOptions.Default.copy(
|
||||
imeAction = ImeAction.Search,
|
||||
keyboardType = KeyboardType.Text
|
||||
),
|
||||
singleLine = true, // Single line text field
|
||||
leadingIcon = {
|
||||
Icon(imageVector = Icons.Default.Search, contentDescription = null)
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp)
|
||||
)
|
||||
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Fixed(2),
|
||||
contentPadding = PaddingValues(16.dp),
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
items(filteredGlossary) { mot ->
|
||||
glossaryCard(mot, onDeleteClick = { wordToDelete ->
|
||||
deleteWordOfGlossary(wordToDelete)
|
||||
// Display the updated glossary
|
||||
filteredGlossary = loadDatasFromFile()
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun glossaryCard(word: Word, onDeleteClick: (Word) -> Unit) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(8.dp),
|
||||
|
||||
elevation = 8.dp
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(16.dp)
|
||||
) {
|
||||
Text(text = word.name, style = MaterialTheme.typography.h6)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(text = "Description: ${word.description}")
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(text = "Contexte principal: ${word.mainContext}")
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(text = "Contexte 2: ${word.secondaryContext}")
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(text = "Lié à: ${word.relatedTo}")
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(text = "Synonyme: ${word.synonymous}")
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(text = "Antonyme: ${word.antonym}")
|
||||
|
||||
// Add a delete button to delete the word
|
||||
IconButton(
|
||||
onClick = { onDeleteClick(word) },
|
||||
modifier = Modifier
|
||||
.align(Alignment.End)
|
||||
.padding(top = 8.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Delete,
|
||||
contentDescription = "Supprimer",
|
||||
tint = customRedColor
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteWordOfGlossary(word: Word) {
|
||||
val wordsList = loadDatasFromFile().toMutableList()
|
||||
|
||||
// Delete the word from the list
|
||||
wordsList.remove(word)
|
||||
|
||||
// Save the updated list to the file
|
||||
saveDatasInFile(wordsList)
|
||||
|
||||
println("Mot supprimé avec succès : ${word.name}")
|
||||
}
|
|
@ -0,0 +1,282 @@
|
|||
package main
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@Composable
|
||||
fun formPage(onCancelClick: () -> Unit) {
|
||||
// State to track whether to show the snackbar
|
||||
val requiredFieldsSnackbarVisibleState = remember { mutableStateOf(false) }
|
||||
val alreadyExistSnackbarVisibleState = remember { mutableStateOf(false) }
|
||||
|
||||
val name = remember { mutableStateOf("") }
|
||||
val description = remember { mutableStateOf("") }
|
||||
val mainContext = remember { mutableStateOf("") }
|
||||
val secondaryContext = remember { mutableStateOf("") }
|
||||
val relatedTo = remember { mutableStateOf("") }
|
||||
val synonymous = remember { mutableStateOf("") }
|
||||
val antonym = remember { mutableStateOf("") }
|
||||
|
||||
val openDialog = remember { mutableStateOf(false) }
|
||||
if (openDialog.value) {
|
||||
AlertDialog(
|
||||
onDismissRequest = {
|
||||
openDialog.value = false
|
||||
},
|
||||
title = {
|
||||
Text(text = "Confirmation d'ajout de mot")
|
||||
},
|
||||
text = {
|
||||
Text("Le mot a bien été ajouté au glossaire.")
|
||||
},
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = {
|
||||
openDialog.value = false
|
||||
resetFields(name, description, mainContext, secondaryContext, relatedTo, synonymous, antonym)
|
||||
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Fermer")
|
||||
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
MaterialTheme {
|
||||
Column(
|
||||
modifier = Modifier.padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = "Nouveau mot", style = MaterialTheme.typography.h5)
|
||||
|
||||
TextField(
|
||||
value = name.value,
|
||||
onValueChange = { name.value = it },
|
||||
label = { Text("Mot *") },
|
||||
)
|
||||
|
||||
TextField(
|
||||
value = description.value,
|
||||
onValueChange = { description.value = it },
|
||||
label = { Text("Description") },
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
focusedIndicatorColor = customRedColor,
|
||||
unfocusedIndicatorColor = Color.Gray
|
||||
)
|
||||
)
|
||||
|
||||
TextField(
|
||||
value = mainContext.value,
|
||||
onValueChange = { mainContext.value = it },
|
||||
label = { Text("Contexte principal *") },
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
focusedIndicatorColor = customRedColor,
|
||||
unfocusedIndicatorColor = Color.Gray
|
||||
)
|
||||
)
|
||||
|
||||
TextField(
|
||||
value = secondaryContext.value,
|
||||
onValueChange = { secondaryContext.value = it },
|
||||
label = { Text("Contexte 2") },
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
focusedIndicatorColor = customRedColor,
|
||||
unfocusedIndicatorColor = Color.Gray
|
||||
)
|
||||
)
|
||||
|
||||
TextField(
|
||||
value = relatedTo.value,
|
||||
onValueChange = { relatedTo.value = it },
|
||||
label = { Text("Lié à") },
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
focusedIndicatorColor = customRedColor,
|
||||
unfocusedIndicatorColor = Color.Gray
|
||||
)
|
||||
)
|
||||
|
||||
TextField(
|
||||
value = synonymous.value,
|
||||
onValueChange = { synonymous.value = it },
|
||||
label = { Text("Synonyme") },
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
focusedIndicatorColor = customRedColor,
|
||||
unfocusedIndicatorColor = Color.Gray
|
||||
)
|
||||
)
|
||||
|
||||
TextField(
|
||||
value = antonym.value,
|
||||
onValueChange = { antonym.value = it },
|
||||
label = { Text("Antonyme") },
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
focusedIndicatorColor = customRedColor,
|
||||
unfocusedIndicatorColor = Color.Gray
|
||||
)
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
Button(
|
||||
onClick = onCancelClick,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Icon(imageVector = Icons.Default.Close, contentDescription = null)
|
||||
Text("Annuler")
|
||||
}
|
||||
Button(
|
||||
onClick = {
|
||||
// Validate the fields
|
||||
if (name.value.isBlank() || mainContext.value.isBlank()) {
|
||||
// Show the snackbar when validation fails
|
||||
requiredFieldsSnackbarVisibleState.value = true
|
||||
return@Button
|
||||
}
|
||||
|
||||
val wordsList = loadDatasFromFile().toMutableList()
|
||||
|
||||
// Verify if the word already exists in the glossary
|
||||
if (wordsList.any { it.name.equals(name.value, ignoreCase = true) }) {
|
||||
println("Le mot '${name.value}' existe déjà dans le glossaire. Ajout annulé.")
|
||||
alreadyExistSnackbarVisibleState.value = true
|
||||
return@Button
|
||||
}
|
||||
|
||||
val newWord = Word(
|
||||
name = name.value,
|
||||
description = description.value,
|
||||
mainContext = mainContext.value,
|
||||
secondaryContext = secondaryContext.value,
|
||||
relatedTo = relatedTo.value,
|
||||
synonymous = synonymous.value,
|
||||
antonym = antonym.value
|
||||
)
|
||||
|
||||
addWordToGlossary(newWord)
|
||||
openDialog.value = true
|
||||
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Icon(imageVector = Icons.Default.Check, contentDescription = null)
|
||||
Text("Valider")
|
||||
}
|
||||
}
|
||||
|
||||
// Show the snackbar when the state is true
|
||||
if (requiredFieldsSnackbarVisibleState.value) {
|
||||
Snackbar(
|
||||
modifier = Modifier.padding(16.dp),
|
||||
action = {
|
||||
Button(onClick = { requiredFieldsSnackbarVisibleState.value = false }) {
|
||||
Text("OK")
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text("Les champs 'Mot' et 'Contexte principal' sont obligatoires.")
|
||||
}
|
||||
}
|
||||
if (alreadyExistSnackbarVisibleState.value) {
|
||||
Snackbar(
|
||||
modifier = Modifier.padding(16.dp),
|
||||
action = {
|
||||
Button(onClick = { alreadyExistSnackbarVisibleState.value = false }) {
|
||||
Text("OK")
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text("Le mot '${name.value}' existe déjà dans le glossaire. Ajout annulé.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun resetFields(
|
||||
name: MutableState<String>,
|
||||
description: MutableState<String>,
|
||||
mainContext: MutableState<String>,
|
||||
secondaryContext: MutableState<String>,
|
||||
relatedTo: MutableState<String>,
|
||||
synonymous: MutableState<String>,
|
||||
antonym: MutableState<String>
|
||||
) {
|
||||
name.value = ""
|
||||
description.value = ""
|
||||
mainContext.value = ""
|
||||
secondaryContext.value = ""
|
||||
relatedTo.value = ""
|
||||
synonymous.value = ""
|
||||
antonym.value = ""
|
||||
}
|
||||
|
||||
fun addWordToGlossary(newWord: Word) {
|
||||
val wordsList = loadDatasFromFile().toMutableList()
|
||||
|
||||
// Verify if the word already exists in the glossary
|
||||
if (wordsList.any { it.name.equals(newWord.name, ignoreCase = true) }) {
|
||||
println("Le mot '${newWord.name}' existe déjà dans le glossaire. Ajout annulé.")
|
||||
return
|
||||
}
|
||||
|
||||
// Add the new word to the glossary
|
||||
wordsList.add(newWord)
|
||||
saveDatasInFile(wordsList)
|
||||
|
||||
println("Mot ajouté avec succès : ${newWord.name}")
|
||||
}
|
||||
|
||||
fun saveDatasInFile(listeWords: List<Word>) {
|
||||
val json = Json { prettyPrint = true }
|
||||
try {
|
||||
val content = json.encodeToString(listeWords)
|
||||
File("glossaire.json").writeText(content)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun loadDatasFromFile(): List<Word> {
|
||||
// If file is empty, return empty list
|
||||
if (!File("glossaire.json").exists() || File("glossaire.json").length() == 0L) {
|
||||
return emptyList()
|
||||
}
|
||||
return try {
|
||||
val content = File("glossaire.json").readText()
|
||||
Json.decodeFromString<List<Word>>(content)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
emptyList() // Handle the exception as needed
|
||||
}
|
||||
}
|
|
@ -0,0 +1,295 @@
|
|||
package main
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
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.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
|
||||
import java.awt.FileDialog
|
||||
import java.awt.Frame
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileWriter
|
||||
import java.io.IOException
|
||||
|
||||
@Composable
|
||||
fun glossaryPage(
|
||||
onAddWordClick: () -> Unit,
|
||||
onImportClick: () -> Unit,
|
||||
onExportClick: () -> Unit,
|
||||
onSeeGlossaryClick: () -> Unit,
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Top, // Align content at the top
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = "Glossaire", 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,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Ajouter un mot")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onImportClick,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Importer un fichier CSV ou XLSX")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onExportClick,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Exporter un fichier CSV")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onSeeGlossaryClick,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Voir le glossaire")
|
||||
}
|
||||
}
|
||||
|
||||
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("Retour")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun selectFile(extensions: Set<String>, onFileSelected: (String) -> Unit) {
|
||||
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
|
||||
fileDialog.isMultipleMode = true // To enable selecting only one file
|
||||
fileDialog.file = "*." + extensions.joinToString(";*.")
|
||||
fileDialog.isVisible = true
|
||||
|
||||
|
||||
val selectedFiles = fileDialog.files
|
||||
|
||||
if (selectedFiles != null) {
|
||||
for (file in selectedFiles) {
|
||||
println("Selected file: $file")
|
||||
// Verify that the file extension is valid
|
||||
val fileExtension = File(file.absolutePath).extension.lowercase()
|
||||
if (extensions.contains(fileExtension)) {
|
||||
println("Opening: $file")
|
||||
onFileSelected(file.absolutePath)
|
||||
} else {
|
||||
println("Invalid file extension.")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println("Open command cancelled by user.")
|
||||
}
|
||||
}
|
||||
|
||||
fun exportToCSV(csvFilePath: String) {
|
||||
val glossary = loadDatasFromFile()
|
||||
val csvContent = buildString {
|
||||
appendLine("Mot;Description;Contexte principal;Contexte 2;Lié à;Synonyme;Antonyme;")
|
||||
glossary.forEach { entry ->
|
||||
appendLine(
|
||||
"${entry.name};${entry.description};${entry.mainContext};" +
|
||||
"${entry.secondaryContext};${entry.relatedTo};${entry.synonymous};${entry.antonym}"
|
||||
)
|
||||
}
|
||||
}
|
||||
try {
|
||||
FileWriter(csvFilePath).use { fileWriter ->
|
||||
fileWriter.write(csvContent)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun importFile(filePath: String) {
|
||||
val fileExtension = File(filePath).extension.lowercase()
|
||||
|
||||
when (fileExtension) {
|
||||
"csv" -> {
|
||||
importCSVFile(filePath)
|
||||
}
|
||||
|
||||
"xlsx" -> {
|
||||
importXLSXFile(filePath)
|
||||
}
|
||||
|
||||
else -> {
|
||||
println("Unsupported file format.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun importCSVFile(filePath: String) {
|
||||
val file = File(filePath).readText(Charsets.UTF_8)
|
||||
|
||||
val lines = file.split("\n")
|
||||
val header = lines.first().split(";")
|
||||
val dataLines = lines.drop(1)
|
||||
|
||||
dataLines.forEach { line ->
|
||||
// Check if the line is not empty or blank
|
||||
if (line.isNotBlank()) {
|
||||
val values = line.replace("\r", "").replace("\n", "").split(";")
|
||||
|
||||
values.forEach { value ->
|
||||
println(value)
|
||||
}
|
||||
val mot = header.zip(values).toMap().toMutableMap()
|
||||
val nouveauWord = Word(
|
||||
name = mot["Mot"]!!,
|
||||
description = mot["Description"]!!,
|
||||
mainContext = mot["Contexte principal"]!!,
|
||||
secondaryContext = mot["Contexte 2"]!!,
|
||||
relatedTo = mot["Lié à"]!!,
|
||||
synonymous = mot["Synonyme"]!!,
|
||||
antonym = mot["Antonyme"]!!
|
||||
)
|
||||
|
||||
if (mot["Antonyme"] == "\r") {
|
||||
mot["Antonyme"] = ""
|
||||
}
|
||||
if (mot["Mot"] == null || mot["Mot"] == "") {
|
||||
return
|
||||
}
|
||||
if (!verifyRequiredFields(mot)) {
|
||||
return
|
||||
}
|
||||
addWordToGlossary(nouveauWord)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun importXLSXFile(cheminFichier: String) {
|
||||
val workbook: Workbook
|
||||
try {
|
||||
FileInputStream(cheminFichier).use { fileInputStream ->
|
||||
workbook = XSSFWorkbook(fileInputStream)
|
||||
}
|
||||
|
||||
val sheet = workbook.getSheetAt(0) // Assuming the data is in the first sheet
|
||||
|
||||
val headerRow = sheet.getRow(0)
|
||||
val header = mutableListOf<String>()
|
||||
for (i in 0 until headerRow.lastCellNum) {
|
||||
header.add(headerRow.getCell(i).stringCellValue)
|
||||
}
|
||||
|
||||
val dataLines = mutableListOf<Map<String, String>>()
|
||||
|
||||
for (i in 1 until sheet.physicalNumberOfRows) {
|
||||
val currentRow = sheet.getRow(i)
|
||||
val data = mutableMapOf<String, String>()
|
||||
|
||||
for (j in 0 until currentRow.lastCellNum) {
|
||||
val cell = currentRow.getCell(j)
|
||||
val cellValue = when (cell.cellType) {
|
||||
CellType.STRING -> cell.stringCellValue
|
||||
CellType.NUMERIC -> cell.numericCellValue.toString()
|
||||
else -> ""
|
||||
}
|
||||
data[header[j]] = cellValue
|
||||
}
|
||||
|
||||
dataLines.add(data)
|
||||
}
|
||||
|
||||
dataLines.forEach { line ->
|
||||
// Check if the line is not empty or blank
|
||||
if (line.isNotEmpty()) {
|
||||
// Process each line as needed
|
||||
val newWord = Word(
|
||||
name = line["Mot"] ?: "",
|
||||
description = line["Description"] ?: "",
|
||||
mainContext = line["Contexte principal"] ?: "",
|
||||
secondaryContext = line["Contexte 2"] ?: "",
|
||||
relatedTo = line["Lié à"] ?: "",
|
||||
synonymous = line["Synonyme"] ?: "",
|
||||
antonym = line["Antonyme"] ?: ""
|
||||
)
|
||||
|
||||
if (newWord.name.isNotBlank() && verifyRequiredFields(line)) {
|
||||
addWordToGlossary(newWord)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun verifyRequiredFields(mot: Map<String, String>): Boolean {
|
||||
//Verify that the required fields are present
|
||||
val requiredFields = listOf(
|
||||
"Mot",
|
||||
"Description",
|
||||
"Contexte principal",
|
||||
"Contexte 2",
|
||||
"Lié à",
|
||||
"Synonyme",
|
||||
"Antonyme"
|
||||
)
|
||||
|
||||
val motKeys = mot.keys.map { it.trim() }
|
||||
|
||||
motKeys.forEach { key ->
|
||||
if (!requiredFields.contains(key)) {
|
||||
println("Le champ $key n'est pas reconnu")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package main
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.ButtonDefaults
|
||||
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.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
var mostUsedWordList = mutableMapOf<String, Int>()
|
||||
|
||||
@Composable
|
||||
fun homePage(
|
||||
onGlossaryClick: () -> Unit,
|
||||
onCodeToVerifyClick: () -> Unit
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
|
||||
) {
|
||||
Text("Quali'Nomme", style = MaterialTheme.typography.h3)
|
||||
|
||||
var isCompareClicked by remember { mutableStateOf(false) }
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
Button(
|
||||
onClick = onGlossaryClick,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Glossaire")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onCodeToVerifyClick,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Code à Vérifier")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
isCompareClicked = true
|
||||
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Comparer")
|
||||
}
|
||||
|
||||
if (isCompareClicked) {
|
||||
println(mostUsedWordList.keys.toList())
|
||||
compareResults(
|
||||
glossaryWords = loadDatasFromFile(),
|
||||
codeWords = mostUsedWordList.keys.toList(),
|
||||
onBackClick = { isCompareClicked = false }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,15 +0,0 @@
|
|||
package main
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Mot(
|
||||
val nom: String,
|
||||
val description: String,
|
||||
val contextePrincipal: String,
|
||||
val contexte2: String,
|
||||
val lieA: String,
|
||||
val synonyme: String,
|
||||
val antonyme: String
|
||||
)
|
|
@ -0,0 +1,89 @@
|
|||
package main
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
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.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun choixLangagePage(
|
||||
onBackClick: () -> Unit,
|
||||
onPythonClick: () -> Unit,
|
||||
onJavaClick: () -> Unit,
|
||||
onJavaScriptClick: () -> Unit
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Top, // Align content at the top
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = "Choix du langage", style = MaterialTheme.typography.h3)
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize() // Fills the maximum available width
|
||||
.padding(50.dp),
|
||||
// Align the content in the center vertically and horizontally
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
|
||||
) {
|
||||
Button(
|
||||
onClick = onPythonClick,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Python")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onJavaClick,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Java")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onJavaScriptClick,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("JavaScript")
|
||||
}
|
||||
}
|
||||
|
||||
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("Retour")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package main
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Word(
|
||||
val name: String,
|
||||
val description: String,
|
||||
val mainContext: String,
|
||||
val secondaryContext: String,
|
||||
val relatedTo: String,
|
||||
val synonymous: String,
|
||||
val antonym: String
|
||||
)
|
Loading…
Reference in New Issue