Fix lazy loading of detail tabs
All checks were successful
Pull Request / build (pull_request) Successful in 3m59s

This commit is contained in:
Marvin Elsen 2024-11-03 13:34:09 +01:00
parent 64ecdd84aa
commit baa4b9bd1a
Signed by: marvinelsen
GPG Key ID: 820672408CC318C2
2 changed files with 24 additions and 4 deletions

View File

@ -34,6 +34,11 @@ class Model(
private val internalIsFindingCharacters: BooleanProperty = SimpleBooleanProperty(false)
private val internalIsFindingSentences: BooleanProperty = SimpleBooleanProperty(false)
private val internalFinishedFindingWordsBeginning: BooleanProperty = SimpleBooleanProperty(false)
private val internalFinishedFindingWordsContaining: BooleanProperty = SimpleBooleanProperty(false)
private val internalFinishedFindingCharacters: BooleanProperty = SimpleBooleanProperty(false)
private val internalFinishedFindingSentences: BooleanProperty = SimpleBooleanProperty(false)
val selectedEntry: ReadOnlyObjectProperty<DictionaryEntryFx> = internalSelectedEntry
val searchResults: ObservableList<DictionaryEntryFx> =
@ -53,6 +58,11 @@ class Model(
val isFindingCharacters: ReadOnlyBooleanProperty = internalIsFindingCharacters
val isFindingSentences: ReadOnlyBooleanProperty = internalIsFindingSentences
val finishedFindingWordsBeginning: ReadOnlyBooleanProperty = internalFinishedFindingWordsBeginning
val finishedFindingWordsContaining: ReadOnlyBooleanProperty = internalFinishedFindingWordsContaining
val finishedFindingCharacters: ReadOnlyBooleanProperty = internalFinishedFindingCharacters
val finishedFindingSentences: ReadOnlyBooleanProperty = internalFinishedFindingSentences
private val coroutineScope = MainScope()
fun search(query: String, searchMode: SearchMode) {
@ -72,6 +82,7 @@ class Model(
.map { it.toFx() }
)
internalIsFindingWordsBeginning.value = false
internalFinishedFindingWordsBeginning.value = true
}
}
@ -84,6 +95,7 @@ class Model(
.map { it.toFx() }
)
internalIsFindingWordsContaining.value = false
internalFinishedFindingWordsContaining.value = true
}
}
@ -96,6 +108,7 @@ class Model(
.map { it.toFx() }
)
internalIsFindingCharacters.value = false
internalFinishedFindingCharacters.value = true
}
}
@ -108,6 +121,7 @@ class Model(
.map { it.toFx() }
)
internalIsFindingSentences.value = false
internalFinishedFindingSentences.value = true
}
}
@ -116,6 +130,12 @@ class Model(
internalWordsContaining.setAll(emptyList())
internalCharacters.setAll(emptyList())
internalSentences.setAll(emptyList())
internalFinishedFindingCharacters.value = false
internalFinishedFindingWordsBeginning.value = false
internalFinishedFindingWordsContaining.value = false
internalFinishedFindingSentences.value = false
internalSelectedEntry.value = entry
}

View File

@ -275,22 +275,22 @@ class DetailsController(
private fun lazyUpdateTabContent(selectedTabId: String?) {
when (selectedTabId) {
"tabWords" -> {
if (model.wordsContaining.isEmpty()) {
if (!model.finishedFindingWordsContaining.value) {
model.findWordsContaining()
}
if (model.wordsBeginning.isEmpty()) {
if (!model.finishedFindingWordsBeginning.value) {
model.findWordsBeginning()
}
}
"tabCharacters" -> {
if (model.characters.isNotEmpty()) return
if (model.finishedFindingCharacters.value) return
model.findCharacters()
}
"tabSentences" -> {
if (model.sentences.isNotEmpty()) return
if (model.finishedFindingSentences.value) return
model.findSentences()
}