Refactor SearchController
This commit is contained in:
parent
a1a7567bd0
commit
959a5c2680
@ -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() }
|
||||
}
|
||||
|
||||
val searchMode = searchModeToggleGroup.selectedToggle.userData as SearchMode
|
||||
model.search(newValue, searchMode)
|
||||
private fun search() {
|
||||
val searchQuery = textFieldSearch.text
|
||||
val searchMode = searchModeToggleGroup.selectedToggle.userData as 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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user