Changed addAccountAddedListener() to addAccountsChangedListener()
This commit is contained in:
parent
c8d1f89964
commit
fde728b72e
|
@ -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<Account>) {
|
||||
areAccountsThatCanTransferMoneyAdded.value = accounts.isNotEmpty() // TODO: add check if they support transferring money
|
||||
}
|
||||
|
||||
}
|
|
@ -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<Account>) {
|
||||
isAccountSelected.value = accounts.isNotEmpty() // TODO: not correct, check if an account has been selected
|
||||
}
|
||||
|
||||
protected open fun handleGetTransactionsResponseOffUiThread(response: GetTransactionsResponse) {
|
||||
|
|
|
@ -17,8 +17,8 @@ open class AccountsView(protected val presenter: MainWindowPresenter) : View() {
|
|||
|
||||
|
||||
init {
|
||||
presenter.addAccountAddedListener {
|
||||
accounts.setAll(presenter.accounts)
|
||||
presenter.addAccountsChangedListener {
|
||||
accounts.setAll(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ open class MainWindowPresenter(
|
|||
|
||||
protected val clientsForAccounts = mutableMapOf<Account, IBankingClient>()
|
||||
|
||||
protected val accountAddedListeners = mutableListOf<(Account) -> Unit>()
|
||||
protected val accountsChangedListeners = mutableListOf<(List<Account>) -> 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<Account>) -> 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<Account>) -> Unit): Boolean {
|
||||
return accountsChangedListeners.add(listener)
|
||||
}
|
||||
|
||||
protected open fun callAccountsChangedListeners() {
|
||||
val accounts = this.accounts
|
||||
|
||||
ArrayList(accountsChangedListeners).forEach {
|
||||
it(accounts) // TODO: use RxJava for this
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Account>) {
|
||||
fabTransferMoney.isEnabled = accounts.isNotEmpty() // TODO: add check if they support transferring money
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue