Added glossary choose before comparing and bugfix

main
Cemal Odabasioglu 2023-12-19 15:30:07 +01:00
parent 3a514674a8
commit 7ecf4cd68d
2 changed files with 138 additions and 85 deletions

View File

@ -3,6 +3,8 @@ package main
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -26,105 +28,155 @@ fun homePage(
val noFileSnackbarVisibleState = remember { mutableStateOf(false) } val noFileSnackbarVisibleState = remember { mutableStateOf(false) }
var isCompareClicked by remember { mutableStateOf(false) } var isCompareClicked by remember { mutableStateOf(false) }
// Utilisez un Box pour placer le drapeau en haut à droite var selectedGlossary by remember { mutableStateOf<Glossary?>(null) }
Box(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
contentAlignment = Alignment.TopEnd
) {
// Utilisez les images des drapeaux
Image(
painter = painterResource(if (languageManager.currentLanguage == Language.FRENCH) "FR.png" else "EN.png"),
contentDescription = "Language Flag",
modifier = Modifier.size(48.dp)
.clickable { languageManager.changeLanguage() }
)
}
Column( if (!isCompareClicked && selectedGlossary == null) {
modifier = Modifier.fillMaxSize(), // Utilisez un Box pour placer le drapeau en haut à droite
verticalArrangement = Arrangement.Center, Box(
horizontalAlignment = Alignment.CenterHorizontally modifier = Modifier
) { .fillMaxSize()
Text("Quali'Nomme", style = MaterialTheme.typography.h3) .padding(16.dp),
contentAlignment = Alignment.TopEnd
Spacer(modifier = Modifier.height(16.dp)) ) {
// Utilisez les images des drapeaux
Column { Image(
Row( painter = painterResource(if (languageManager.currentLanguage == Language.FRENCH) "FR.png" else "EN.png"),
horizontalArrangement = Arrangement.spacedBy(16.dp) contentDescription = "Language Flag",
) { modifier = Modifier.size(48.dp)
Button( .clickable { languageManager.changeLanguage() }
onClick = onGlossaryClick, )
modifier = Modifier.width(200.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
) {
Text(languageManager.getGlossaryText())
}
Button(
onClick = onCodeToVerifyClick,
modifier = Modifier.width(200.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
) {
Text(languageManager.getCodeToVerifyText())
}
Button(
onClick = {
if (mostUsedWordList.isEmpty()) {
noFileSnackbarVisibleState.value = true
println("Veuillez d'abord importer un fichier")
return@Button
} else {
isCompareClicked = true
}
},
modifier = Modifier.width(200.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
),
enabled = mostUsedWordList.isNotEmpty()
) {
Text(languageManager.getCompareText())
}
}
} }
if (noFileSnackbarVisibleState.value) { Column(
Snackbar( modifier = Modifier.fillMaxSize(),
modifier = Modifier.padding(16.dp), verticalArrangement = Arrangement.Center,
action = { horizontalAlignment = Alignment.CenterHorizontally
) {
Text("Quali'Nomme", style = MaterialTheme.typography.h3)
Spacer(modifier = Modifier.height(16.dp))
Column {
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
Button( Button(
onClick = { noFileSnackbarVisibleState.value = false }, onClick = onGlossaryClick,
modifier = Modifier.width(200.dp),
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
) )
) { ) {
Text("OK") Text(languageManager.getGlossaryText())
}
Button(
onClick = onCodeToVerifyClick,
modifier = Modifier.width(200.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
) {
Text(languageManager.getCodeToVerifyText())
}
Button(
onClick = {
if (mostUsedWordList.isEmpty()) {
noFileSnackbarVisibleState.value = true
println("Veuillez d'abord importer un fichier")
return@Button
} else {
isCompareClicked = true
}
},
modifier = Modifier.width(200.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
),
enabled = mostUsedWordList.isNotEmpty()
) {
Text(languageManager.getCompareText())
} }
} }
) { }
Text("Veuillez d'abord importer un fichier")
if (noFileSnackbarVisibleState.value) {
Snackbar(
modifier = Modifier.padding(16.dp),
action = {
Button(
onClick = { noFileSnackbarVisibleState.value = false },
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
) {
Text("OK")
}
}
) {
Text("Veuillez d'abord importer un fichier")
}
} }
} }
}
if (isCompareClicked) { if (isCompareClicked && selectedGlossary == null) {
println(mostUsedWordList.keys.toList()) GlossaryList(glossaries = loadGlossaries()) { glossary ->
selectedGlossary = glossary
}
} else if (isCompareClicked) {
selectedGlossary?.let {
compareResults( compareResults(
glossaryWords = loadDatasFromFile("glossaire.json"), glossaryWords = loadDatasFromFile(it.jsonFilePath),
codeWords = mostUsedWordList.keys.toList(), codeWords = mostUsedWordList.keys.toList(),
onBackClick = { isCompareClicked = false } onBackClick = { isCompareClicked = false; selectedGlossary = null }
) )
} }
} }
} }
@Composable
fun GlossaryList(glossaries: List<Glossary>, onGlossarySelected: (Glossary) -> Unit) {
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))
LazyColumn(
modifier = Modifier.padding(10.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
items(glossaries) { glossary ->
Row(
modifier = Modifier.width(200.dp).fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Button(
onClick = {
onGlossarySelected(glossary)
},
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
) {
Text(glossary.name)
}
}
}
}
Spacer(modifier = Modifier.height(6.dp))
}
}

View File

@ -21,6 +21,7 @@ import java.util.*
val customRedColor = Color(0xFFB70D1B) val customRedColor = Color(0xFFB70D1B)
val currentPage = mutableStateOf("accueil")
@OptIn(ExperimentalMaterialApi::class) @OptIn(ExperimentalMaterialApi::class)
@Composable @Composable
@ -28,7 +29,6 @@ val customRedColor = Color(0xFFB70D1B)
fun app() { fun app() {
val languageManager = remember { LanguageManager() } val languageManager = remember { LanguageManager() }
MaterialTheme { MaterialTheme {
val currentPage = remember { mutableStateOf("accueil") }
var glossaryDetail: List<Word> by remember { mutableStateOf(emptyList()) } var glossaryDetail: List<Word> by remember { mutableStateOf(emptyList()) }
var isJavaScriptFileSelected by remember { mutableStateOf(false) } var isJavaScriptFileSelected by remember { mutableStateOf(false) }
@ -52,7 +52,7 @@ fun app() {
homePage( homePage(
languageManager, languageManager,
onGlossaryClick = { currentPage.value = "glossaires" }, onGlossaryClick = { currentPage.value = "glossaires" },
onCodeToVerifyClick = { currentPage.value = "choixLangage" } onCodeToVerifyClick = { currentPage.value = "choixLangage" },
) )
} }
@ -372,6 +372,7 @@ fun app() {
Text("Ce glossaire existe déjà.") Text("Ce glossaire existe déjà.")
} }
} }
} }
} }