Change views for compare

main
CAPEL Maxime 2024-01-18 15:58:23 +01:00
parent 08e8577a5c
commit a72708d76c
5 changed files with 78 additions and 74 deletions

View File

@ -26,6 +26,7 @@ fun glossaryList(
) { ) {
var isCompareClicked by remember { mutableStateOf(false) } var isCompareClicked by remember { mutableStateOf(false) }
var selectedGlossary by remember { mutableStateOf<Glossary?>(null) }
val noFileSnackbarVisibleState = remember { mutableStateOf(false) } val noFileSnackbarVisibleState = remember { mutableStateOf(false) }
Column( Column(
@ -62,7 +63,13 @@ fun glossaryList(
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
buttonComponent(glossary.name, { onGlossarySelected(glossary) }, width = 200) buttonComponent(
glossary.name,
{
onGlossarySelected(glossary)
currentPage.value = "compareTable"
}
)
} }
} }
} }
@ -96,4 +103,10 @@ fun glossaryList(
} }
} }
} }
when {
isCompareClicked && selectedGlossary == null -> {
currentPage.value = "compareGlossary"
}
}
} }

View File

@ -62,7 +62,13 @@ fun projectList(
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
buttonComponent(project.name, { onProjectSelected(project) }, width = 200) buttonComponent(
project.name,
{
onProjectSelected(project)
currentPage.value = "compareGlossary"
}
)
} }
} }
} }

View File

@ -1,10 +1,8 @@
package main package main
import androidx.compose.foundation.* import androidx.compose.foundation.Image
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.foundation.lazy.rememberLazyListState
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
@ -25,9 +23,9 @@ enum class Language {
fun homePage( fun homePage(
languageManager: LanguageManager, languageManager: LanguageManager,
onProjectClick: () -> Unit, onProjectClick: () -> Unit,
onCodeToVerifyClick: () -> Unit onCodeToVerifyClick: () -> Unit,
onCompareClick: () -> Unit,
) { ) {
val appState = AppState
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) } var selectedGlossary by remember { mutableStateOf<Glossary?>(null) }
@ -83,7 +81,7 @@ fun homePage(
noFileSnackbarVisibleState.value = true noFileSnackbarVisibleState.value = true
return@Button return@Button
} else { } else {
isCompareClicked = true onCompareClick()
} }
}, },
modifier = Modifier.width(200.dp), modifier = Modifier.width(200.dp),
@ -124,69 +122,12 @@ fun homePage(
noFileSnackbarVisibleState.value = true noFileSnackbarVisibleState.value = true
return@dropdownButtonComponent return@dropdownButtonComponent
} else { } else {
isCompareClicked = true currentPage.value = "compareProject"
} }
} }
} }
} }
} }
var selectedProject by remember { mutableStateOf<Project?>(null) }
when {
isCompareClicked && selectedProject == null && selectedGlossary == null -> {
projectList(
projects = loadProjects(),
onProjectSelected = { project ->
selectedProject = project
appState.selectedProject = selectedProject
},
onBackClick = {
isCompareClicked = false
selectedGlossary = null
selectedProject = null
},
onProjectClick = { currentPage.value = "projects" },
languageManager = languageManager,
onCodeToVerifyClick = { currentPage.value = "choixLangage" }
)
}
isCompareClicked && selectedGlossary == null -> {
glossaryList(
glossaries = loadGlossaries(appState.selectedProject!!),
onGlossarySelected = { glossary ->
selectedGlossary = glossary
},
onBackClick = {
isCompareClicked = false
selectedGlossary = null
selectedProject = null
},
onProjectClick = { currentPage.value = "projects" },
languageManager = languageManager,
onCodeToVerifyClick = { currentPage.value = "choixLangage" }
)
}
isCompareClicked -> {
selectedGlossary?.let {
compareResults(
languageManager = languageManager,
glossaryWords = loadDatasFromFile(it.jsonFilePath),
codeWords = mostUsedWordList.keys.toList(),
onBackClick = {
isCompareClicked = false
selectedGlossary = null
selectedProject = null
},
onProjectClick = { currentPage.value = "projects" },
onCodeToVerifyClick = { currentPage.value = "choixLangage" },
)
}
}
}
HelpButton { HelpButton {
showHelpPage = true showHelpPage = true

View File

@ -5,12 +5,12 @@ import androidx.compose.foundation.layout.padding
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
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
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.* import androidx.compose.ui.window.*
import main.AppState.selectedGlossary
import java.awt.FileDialog import java.awt.FileDialog
import java.awt.Frame import java.awt.Frame
import java.io.File import java.io.File
@ -29,7 +29,7 @@ object AppState {
var selectedGlossary: Glossary? = null var selectedGlossary: Glossary? = null
} }
@OptIn(ExperimentalMaterialApi::class, ExperimentalComposeUiApi::class) @OptIn(ExperimentalMaterialApi::class)
@Composable @Composable
@Preview @Preview
fun app() { fun app() {
@ -53,6 +53,7 @@ fun app() {
languageManager, languageManager,
onProjectClick = { currentPage.value = "projects" }, onProjectClick = { currentPage.value = "projects" },
onCodeToVerifyClick = { currentPage.value = "choixLangage" }, onCodeToVerifyClick = { currentPage.value = "choixLangage" },
onCompareClick = { currentPage.value = "compareProject" },
) )
} }
@ -83,6 +84,52 @@ fun app() {
) )
} }
"compareProject" -> {
var selectedProject by remember { mutableStateOf<Project?>(null) }
projectList(
projects = loadProjects(),
onProjectSelected = { project ->
selectedProject = project
appState.selectedProject = selectedProject
},
onBackClick = {
currentPage.value = "accueil"
},
onProjectClick = { currentPage.value = "projects" },
languageManager = languageManager,
onCodeToVerifyClick = { currentPage.value = "choixLangage" }
)
}
"compareGlossary" -> {
var selectedGlossary by remember { mutableStateOf<Glossary?>(null) }
glossaryList(
glossaries = loadGlossaries(appState.selectedProject!!),
onGlossarySelected = { glossary ->
selectedGlossary = glossary
},
onBackClick = {
currentPage.value = "compareProject"
},
onProjectClick = { currentPage.value = "projects" },
languageManager = languageManager,
onCodeToVerifyClick = { currentPage.value = "choixLangage" }
)
}
"compareTable" -> {
compareResults(
languageManager = languageManager,
glossaryWords = selectedGlossary?.jsonFilePath?.let { loadDatasFromFile(it) } ?: emptyList(),
codeWords = mostUsedWordList.keys.toList(),
onBackClick = {
currentPage.value = "compareGlossary"
},
onProjectClick = { currentPage.value = "projects" },
onCodeToVerifyClick = { currentPage.value = "choixLangage" },
)
}
"nouveauProjet" ->{ "nouveauProjet" ->{
newProject( newProject(
languageManager, languageManager,

View File

@ -1,10 +1,7 @@
package main package main
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.material.Button import androidx.compose.material.*
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.* import androidx.compose.runtime.*
@ -131,7 +128,7 @@ fun choixLangagePage(
noFileSnackbarVisibleState.value = true noFileSnackbarVisibleState.value = true
return@dropdownButtonComponent return@dropdownButtonComponent
} else { } else {
isCompareClicked = true currentPage.value = "compareProject"
} }
} }
} }