From fde728b72e01e900d4ec9f26d2ed8f16a24dec61 Mon Sep 17 00:00:00 2001 From: dankl Date: Sun, 12 Jan 2020 00:42:52 +0100 Subject: [PATCH] Changed addAccountAddedListener() to addAccountsChangedListener() --- .../mainwindow/controls/MainMenuBar.kt | 11 ++++---- .../controls/AccountTransactionsView.kt | 7 ++--- .../ui/javafx/controls/AccountsView.kt | 4 +-- .../ui/presenter/MainWindowPresenter.kt | 20 +++++++++----- .../MainActivityFloatingActionMenuButton.kt | 27 ++++++++++++------- 5 files changed, 42 insertions(+), 27 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 50ec73b4..1531911b 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 @@ -4,6 +4,7 @@ import javafx.beans.property.SimpleBooleanProperty import javafx.scene.input.KeyCode import javafx.scene.input.KeyCodeCombination import javafx.scene.input.KeyCombination +import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.presenter.MainWindowPresenter import tornadofx.* @@ -14,11 +15,11 @@ open class MainMenuBar(protected val presenter: MainWindowPresenter) : View() { init { - presenter.addAccountAddedListener { - checkIfAreAccountsThatCanTransferMoneyAdded() + presenter.addAccountsChangedListener { + checkIfThereAreAccountsThatCanTransferMoney(it) } - checkIfAreAccountsThatCanTransferMoneyAdded() + checkIfThereAreAccountsThatCanTransferMoney(presenter.accounts) } @@ -49,8 +50,8 @@ open class MainMenuBar(protected val presenter: MainWindowPresenter) : View() { } - protected open fun checkIfAreAccountsThatCanTransferMoneyAdded() { - areAccountsThatCanTransferMoneyAdded.value = presenter.accounts.isNotEmpty() // TODO: add check if they support transferring money + protected open fun checkIfThereAreAccountsThatCanTransferMoney(accounts: List) { + areAccountsThatCanTransferMoneyAdded.value = accounts.isNotEmpty() // TODO: add check if they support transferring money } } \ No newline at end of file diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsView.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsView.kt index b1dcb34d..55992da9 100644 --- a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsView.kt +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsView.kt @@ -7,6 +7,7 @@ import javafx.scene.control.ContextMenu import javafx.scene.input.ContextMenuEvent import javafx.scene.input.MouseButton import javafx.scene.input.MouseEvent +import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.model.AccountTransaction import net.dankito.banking.ui.model.parameters.TransferMoneyData import net.dankito.banking.ui.model.responses.GetTransactionsResponse @@ -29,7 +30,7 @@ open class AccountTransactionsView(private val presenter: MainWindowPresenter) : init { - presenter.addAccountAddedListener { handleAccountAdded() } + presenter.addAccountsChangedListener { handleAccountsChanged(it) } presenter.addRetrievedAccountTransactionsResponseListener { _, response -> handleGetTransactionsResponseOffUiThread(response) @@ -109,8 +110,8 @@ open class AccountTransactionsView(private val presenter: MainWindowPresenter) : } - protected open fun handleAccountAdded() { - isAccountSelected.value = presenter.accounts.isNotEmpty() // TODO: not correct, check if an account has been selected + protected open fun handleAccountsChanged(accounts: List) { + isAccountSelected.value = accounts.isNotEmpty() // TODO: not correct, check if an account has been selected } protected open fun handleGetTransactionsResponseOffUiThread(response: GetTransactionsResponse) { 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 ea1f6431..6e6844c0 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 @@ -17,8 +17,8 @@ open class AccountsView(protected val presenter: MainWindowPresenter) : View() { init { - presenter.addAccountAddedListener { - accounts.setAll(presenter.accounts) + presenter.addAccountsChangedListener { + accounts.setAll(it) } } diff --git a/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/MainWindowPresenter.kt b/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/MainWindowPresenter.kt index 8dc811b9..9e685766 100644 --- a/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/MainWindowPresenter.kt +++ b/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/MainWindowPresenter.kt @@ -45,7 +45,7 @@ open class MainWindowPresenter( protected val clientsForAccounts = mutableMapOf() - protected val accountAddedListeners = mutableListOf<(Account) -> Unit>() + protected val accountsChangedListeners = mutableListOf<(List) -> Unit>() protected val retrievedAccountTransactionsResponseListeners = mutableListOf<(BankAccount, GetTransactionsResponse) -> Unit>() @@ -74,7 +74,7 @@ open class MainWindowPresenter( if (response.isSuccessful) { clientsForAccounts.put(account, newClient) - callAccountAddedListeners(account) + callAccountsChangedListeners() if (response.supportsRetrievingTransactionsOfLast90DaysWithoutTan) { account.bankAccounts.forEach { bankAccount -> @@ -254,13 +254,19 @@ open class MainWindowPresenter( get() = clientsForAccounts.keys.map { it.balance }.fold(BigDecimal.ZERO) { acc, e -> acc + e } - open fun addAccountAddedListener(listener: (Account) -> Unit) { - accountAddedListeners.add(listener) + open fun addAccountsChangedListener(listener: (List) -> Unit): Boolean { + return accountsChangedListeners.add(listener) } - protected open fun callAccountAddedListeners(account: Account) { - ArrayList(accountAddedListeners).forEach { - it(account) // TODO: use RxJava for this + open fun removeAccountsChangedListener(listener: (List) -> Unit): Boolean { + return accountsChangedListeners.add(listener) + } + + protected open fun callAccountsChangedListeners() { + val accounts = this.accounts + + ArrayList(accountsChangedListeners).forEach { + it(accounts) // TODO: use RxJava for this } } 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 40b01a63..0c8e0699 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 @@ -1,17 +1,26 @@ package net.dankito.banking.fints4java.android.ui.views import android.support.v7.app.AppCompatActivity +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.fints4java.android.ui.dialogs.TransferMoneyDialog +import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.presenter.MainWindowPresenter open class MainActivityFloatingActionMenuButton(floatingActionMenu: FloatingActionMenu, protected val presenter: MainWindowPresenter) : FloatingActionMenuButton(floatingActionMenu) { + protected lateinit var fabTransferMoney: FloatingActionButton + init { setupButtons(floatingActionMenu) + + presenter.addAccountsChangedListener { + checkIfThereAreAccountsThatCanTransferMoney(it) + } + + checkIfThereAreAccountsThatCanTransferMoney(presenter.accounts) } private fun setupButtons(floatingActionMenu: FloatingActionMenu) { @@ -20,19 +29,17 @@ open class MainActivityFloatingActionMenuButton(floatingActionMenu: FloatingActi executeAndCloseMenu { presenter.showAddAccountDialog() } } - val fabTransferMoney = floatingActionMenu.fabTransferMoney - fabTransferMoney.isEnabled = false - - floatingActionMenu.setOnMenuToggleListener { - if (floatingActionMenu.isOpened) { - fabTransferMoney.isEnabled = presenter.accounts.isNotEmpty() - } - } + fabTransferMoney = floatingActionMenu.fabTransferMoney fabTransferMoney.setOnClickListener { - executeAndCloseMenu { TransferMoneyDialog().show(activity, presenter, null) } + executeAndCloseMenu { presenter.showTransferMoneyDialog() } } } } + + protected open fun checkIfThereAreAccountsThatCanTransferMoney(accounts: List) { + fabTransferMoney.isEnabled = accounts.isNotEmpty() // TODO: add check if they support transferring money + } + } \ No newline at end of file