Refactor SearchController

This commit is contained in:
Marvin Elsen 2024-10-24 21:13:10 +02:00
parent a1a7567bd0
commit 959a5c2680
Signed by: marvinelsen
GPG Key ID: 820672408CC318C2

View File

@ -16,22 +16,18 @@ class SearchController(private val model: Model) {
@FXML
@Suppress("UnusedPrivateMember")
private fun initialize() {
textFieldSearch.textProperty().addListener { _, _, newValue ->
if (newValue.isNullOrBlank()) {
return@addListener
textFieldSearch.textProperty().addListener { _, _, _ -> search() }
searchModeToggleGroup.selectedToggleProperty().addListener { _, _, _ -> search() }
}
private fun search() {
val searchQuery = textFieldSearch.text
val searchMode = searchModeToggleGroup.selectedToggle.userData as SearchMode
model.search(newValue, searchMode)
if (searchQuery.isNullOrBlank()) {
return
}
searchModeToggleGroup.selectedToggleProperty().addListener { _, _, newValue ->
if (textFieldSearch.text.isNullOrBlank()) {
return@addListener
}
val searchMode = newValue.userData as SearchMode
model.search(textFieldSearch.text, searchMode)
}
model.search(searchQuery, searchMode)
}
}