first refactor
parent
4a6f055473
commit
ef3ba67abe
|
@ -13,12 +13,7 @@ import androidx.compose.material.*
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.*
|
import androidx.compose.material.icons.filled.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.material.icons.filled.ArrowBack
|
|
||||||
import androidx.compose.material.icons.filled.Check
|
|
||||||
import androidx.compose.material.icons.filled.Close
|
|
||||||
import androidx.compose.runtime.*
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
|
@ -28,14 +23,15 @@ import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.*
|
import androidx.compose.ui.window.*
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import java.awt.FileDialog
|
|
||||||
import java.awt.Frame
|
|
||||||
import java.io.File
|
|
||||||
import java.io.IOException
|
|
||||||
import org.apache.poi.ss.usermodel.CellType
|
import org.apache.poi.ss.usermodel.CellType
|
||||||
import org.apache.poi.ss.usermodel.Workbook
|
import org.apache.poi.ss.usermodel.Workbook
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook
|
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.FileInputStream
|
||||||
|
import java.io.FileWriter
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
val customRedColor = Color(0xFFB70D1B)
|
val customRedColor = Color(0xFFB70D1B)
|
||||||
|
|
||||||
|
@ -123,8 +119,7 @@ fun homePage(
|
||||||
fun compareResults(
|
fun compareResults(
|
||||||
motsGlossaire: List<Mot>,
|
motsGlossaire: List<Mot>,
|
||||||
motsCode: List<String>,
|
motsCode: List<String>,
|
||||||
onRetourClick: () -> Unit,
|
onRetourClick: () -> Unit
|
||||||
navigationIcon: @Composable () -> Unit = { Icon(Icons.Filled.ArrowBack, contentDescription = null) }
|
|
||||||
|
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
|
@ -531,6 +526,7 @@ fun glossairePage(
|
||||||
onAjouterMotClick: () -> Unit,
|
onAjouterMotClick: () -> Unit,
|
||||||
onImporterClick: () -> Unit,
|
onImporterClick: () -> Unit,
|
||||||
onExporterClick: () -> Unit,
|
onExporterClick: () -> Unit,
|
||||||
|
onVoirGlossaireClick: () -> Unit,
|
||||||
onRetourClick: () -> Unit
|
onRetourClick: () -> Unit
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -611,13 +607,12 @@ fun glossairePage(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalComposeUiApi::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun glossaireDetailPage(glossaire: List<Mot>, onRetourClick: () -> Unit) {
|
fun glossaireDetailPage(glossaire: List<Mot>, onRetourClick: () -> Unit) {
|
||||||
var searchQuery by remember { mutableStateOf("") }
|
var searchQuery by remember { mutableStateOf("") }
|
||||||
var sortOption by remember { mutableStateOf("Nom ↑") }
|
var sortOption by remember { mutableStateOf("Nom ↑") }
|
||||||
|
|
||||||
var filteredGlossaire by remember { mutableStateOf<List<Mot>>(glossaire) }
|
var filteredGlossaire by remember { mutableStateOf(glossaire) }
|
||||||
|
|
||||||
val menuExpanded = remember { mutableStateOf(false) }
|
val menuExpanded = remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
@ -745,7 +740,7 @@ fun glossaireDetailPage(glossaire: List<Mot>, onRetourClick: () -> Unit) {
|
||||||
modifier = Modifier.fillMaxSize()
|
modifier = Modifier.fillMaxSize()
|
||||||
) {
|
) {
|
||||||
items(filteredGlossaire) { mot ->
|
items(filteredGlossaire) { mot ->
|
||||||
GlossaireCard(mot, onSupprimerClick = { motASupprimer ->
|
glossaireCard(mot, onSupprimerClick = { motASupprimer ->
|
||||||
supprimerMotDuGlossaire(motASupprimer)
|
supprimerMotDuGlossaire(motASupprimer)
|
||||||
//afficher à nouveau les mots du glossaire
|
//afficher à nouveau les mots du glossaire
|
||||||
filteredGlossaire = chargerDonneesDepuisFichier()
|
filteredGlossaire = chargerDonneesDepuisFichier()
|
||||||
|
@ -757,11 +752,12 @@ fun glossaireDetailPage(glossaire: List<Mot>, onRetourClick: () -> Unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun GlossaireCard(mot: Mot, onSupprimerClick: (Mot) -> Unit) {
|
fun glossaireCard(mot: Mot, onSupprimerClick: (Mot) -> Unit) {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(8.dp),
|
.padding(8.dp),
|
||||||
|
|
||||||
elevation = 8.dp
|
elevation = 8.dp
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
|
@ -822,8 +818,8 @@ fun resetFields(
|
||||||
@Composable
|
@Composable
|
||||||
fun formulairePage(onAnnulerClick: () -> Unit) {
|
fun formulairePage(onAnnulerClick: () -> Unit) {
|
||||||
// State to track whether to show the snackbar
|
// State to track whether to show the snackbar
|
||||||
val ChampsObligatoireSnackbarVisibleState = remember { mutableStateOf(false) }
|
val champsObligatoireSnackbarVisibleState = remember { mutableStateOf(false) }
|
||||||
val ExisteDejaSnackbarVisibleState = remember { mutableStateOf(false) }
|
val existeDejaSnackbarVisibleState = remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val nom = remember { mutableStateOf("") }
|
val nom = remember { mutableStateOf("") }
|
||||||
val description = remember { mutableStateOf("") }
|
val description = remember { mutableStateOf("") }
|
||||||
|
@ -957,7 +953,7 @@ fun formulairePage(onAnnulerClick: () -> Unit) {
|
||||||
// Validation du formulaire
|
// Validation du formulaire
|
||||||
if (nom.value.isBlank() || contextePrincipal.value.isBlank()) {
|
if (nom.value.isBlank() || contextePrincipal.value.isBlank()) {
|
||||||
// Show the snackbar when validation fails
|
// Show the snackbar when validation fails
|
||||||
ChampsObligatoireSnackbarVisibleState.value = true
|
champsObligatoireSnackbarVisibleState.value = true
|
||||||
return@Button
|
return@Button
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -966,7 +962,7 @@ fun formulairePage(onAnnulerClick: () -> Unit) {
|
||||||
// Vérifier si le mot existe déjà dans le glossaire
|
// Vérifier si le mot existe déjà dans le glossaire
|
||||||
if (listeMots.any { it.nom.equals(nom.value, ignoreCase = true) }) {
|
if (listeMots.any { it.nom.equals(nom.value, ignoreCase = true) }) {
|
||||||
println("Le mot '${nom.value}' existe déjà dans le glossaire. Ajout annulé.")
|
println("Le mot '${nom.value}' existe déjà dans le glossaire. Ajout annulé.")
|
||||||
ExisteDejaSnackbarVisibleState.value = true
|
existeDejaSnackbarVisibleState.value = true
|
||||||
return@Button
|
return@Button
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -995,11 +991,11 @@ fun formulairePage(onAnnulerClick: () -> Unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the snackbar when the state is true
|
// Show the snackbar when the state is true
|
||||||
if (ChampsObligatoireSnackbarVisibleState.value) {
|
if (champsObligatoireSnackbarVisibleState.value) {
|
||||||
Snackbar(
|
Snackbar(
|
||||||
modifier = Modifier.padding(16.dp),
|
modifier = Modifier.padding(16.dp),
|
||||||
action = {
|
action = {
|
||||||
Button(onClick = { ChampsObligatoireSnackbarVisibleState.value = false }) {
|
Button(onClick = { champsObligatoireSnackbarVisibleState.value = false }) {
|
||||||
Text("OK")
|
Text("OK")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1007,11 +1003,11 @@ fun formulairePage(onAnnulerClick: () -> Unit) {
|
||||||
Text("Les champs 'Mot' et 'Contexte principal' sont obligatoires.")
|
Text("Les champs 'Mot' et 'Contexte principal' sont obligatoires.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ExisteDejaSnackbarVisibleState.value) {
|
if (existeDejaSnackbarVisibleState.value) {
|
||||||
Snackbar(
|
Snackbar(
|
||||||
modifier = Modifier.padding(16.dp),
|
modifier = Modifier.padding(16.dp),
|
||||||
action = {
|
action = {
|
||||||
Button(onClick = { ExisteDejaSnackbarVisibleState.value = false }) {
|
Button(onClick = { existeDejaSnackbarVisibleState.value = false }) {
|
||||||
Text("OK")
|
Text("OK")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue