From 071c0a1b8d6da3eaf948cc9c23242dedc7ad35b8 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 29 Apr 2020 00:54:53 +0200 Subject: [PATCH] Fixed that AccountsChangedListener may gets called off UI thread --- .../ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt | 4 +++- .../ui/javafx/controls/AccountTransactionsControlView.kt | 2 +- .../net/dankito/banking/ui/javafx/controls/AccountsView.kt | 6 +++--- .../ui/views/MainActivityFloatingActionMenuButton.kt | 5 ++++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt b/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt index ddbcd4a7..0f9c2a0d 100644 --- a/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt +++ b/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt @@ -16,7 +16,9 @@ open class MainMenuBar(protected val presenter: BankingPresenter) : View() { init { presenter.addAccountsChangedListener { - checkIfThereAreAccountsThatCanTransferMoney() + runLater { + checkIfThereAreAccountsThatCanTransferMoney() + } } checkIfThereAreAccountsThatCanTransferMoney() diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsControlView.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsControlView.kt index daf1931a..a321d25e 100644 --- a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsControlView.kt +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsControlView.kt @@ -99,7 +99,7 @@ open class AccountTransactionsControlView( protected open fun initLogic() { - presenter.addAccountsChangedListener { accountsChanged() } + presenter.addAccountsChangedListener { runLater { accountsChanged() } } presenter.addSelectedBankAccountsChangedListener { selectedBankAccountsChanged() } checkIfSupportsTransferringMoneyOnUiThread() diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountsView.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountsView.kt index fecb176f..44b0e799 100644 --- a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountsView.kt +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountsView.kt @@ -3,11 +3,9 @@ package net.dankito.banking.ui.javafx.controls import javafx.collections.FXCollections import javafx.geometry.Pos import javafx.scene.control.TreeItem -import javafx.scene.control.TreeView import javafx.scene.layout.Priority import net.dankito.banking.ui.javafx.model.AccountsAccountTreeItem import net.dankito.banking.ui.javafx.model.AccountsBankAccountTreeItem -import net.dankito.banking.ui.javafx.model.AccountsRootTreeItem import net.dankito.banking.ui.presenter.BankingPresenter import net.dankito.utils.javafx.ui.controls.addButton import net.dankito.utils.javafx.ui.extensions.fixedHeight @@ -22,7 +20,9 @@ open class AccountsView(protected val presenter: BankingPresenter) : View() { init { presenter.addAccountsChangedListener { - accounts.setAll(it) + runLater { + accounts.setAll(it) + } } } diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/MainActivityFloatingActionMenuButton.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/MainActivityFloatingActionMenuButton.kt index 7f62f8fe..1dcdfdf0 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/MainActivityFloatingActionMenuButton.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/MainActivityFloatingActionMenuButton.kt @@ -5,6 +5,7 @@ import com.github.clans.fab.FloatingActionButton import com.github.clans.fab.FloatingActionMenu import kotlinx.android.synthetic.main.view_floating_action_button_main.view.* import net.dankito.banking.ui.presenter.BankingPresenter +import net.dankito.utils.android.extensions.asActivity open class MainActivityFloatingActionMenuButton(floatingActionMenu: FloatingActionMenu, protected val presenter: BankingPresenter) @@ -16,7 +17,9 @@ open class MainActivityFloatingActionMenuButton(floatingActionMenu: FloatingActi setupButtons(floatingActionMenu) presenter.addAccountsChangedListener { - checkIfThereAreAccountsThatCanTransferMoney() + fabTransferMoney.context.asActivity()?.runOnUiThread { + checkIfThereAreAccountsThatCanTransferMoney() + } } checkIfThereAreAccountsThatCanTransferMoney()