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,6 +28,9 @@ fun homePage(
val noFileSnackbarVisibleState = remember { mutableStateOf(false) } val noFileSnackbarVisibleState = remember { mutableStateOf(false) }
var isCompareClicked by remember { mutableStateOf(false) } var isCompareClicked by remember { mutableStateOf(false) }
var selectedGlossary by remember { mutableStateOf<Glossary?>(null) }
if (!isCompareClicked && selectedGlossary == null) {
// Utilisez un Box pour placer le drapeau en haut à droite // Utilisez un Box pour placer le drapeau en haut à droite
Box( Box(
modifier = Modifier modifier = Modifier
@ -117,14 +122,61 @@ fun homePage(
Text("Veuillez d'abord importer un fichier") 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à.")
} }
} }
} }
} }