From baa4b9bd1a80247c119793b49e5875d78f5da450 Mon Sep 17 00:00:00 2001 From: Marvin Elsen Date: Sun, 3 Nov 2024 13:34:09 +0100 Subject: [PATCH] Fix lazy loading of detail tabs --- .../kotlin/com/marvinelsen/willow/Model.kt | 20 +++++++++++++++++++ .../ui/controllers/DetailsController.kt | 8 ++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/marvinelsen/willow/Model.kt b/src/main/kotlin/com/marvinelsen/willow/Model.kt index d483ea5..31e5fba 100644 --- a/src/main/kotlin/com/marvinelsen/willow/Model.kt +++ b/src/main/kotlin/com/marvinelsen/willow/Model.kt @@ -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 = internalSelectedEntry val searchResults: ObservableList = @@ -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 } diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt index 50fad3c..ef84eb7 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt @@ -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() }