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.KeyCode
|
||||||
import javafx.scene.input.KeyCodeCombination
|
import javafx.scene.input.KeyCodeCombination
|
||||||
import javafx.scene.input.KeyCombination
|
import javafx.scene.input.KeyCombination
|
||||||
|
import net.dankito.banking.ui.model.Account
|
||||||
import net.dankito.banking.ui.presenter.MainWindowPresenter
|
import net.dankito.banking.ui.presenter.MainWindowPresenter
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
|
@ -14,11 +15,11 @@ open class MainMenuBar(protected val presenter: MainWindowPresenter) : View() {
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
presenter.addAccountAddedListener {
|
presenter.addAccountsChangedListener {
|
||||||
checkIfAreAccountsThatCanTransferMoneyAdded()
|
checkIfThereAreAccountsThatCanTransferMoney(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
checkIfAreAccountsThatCanTransferMoneyAdded()
|
checkIfThereAreAccountsThatCanTransferMoney(presenter.accounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,8 +50,8 @@ open class MainMenuBar(protected val presenter: MainWindowPresenter) : View() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected open fun checkIfAreAccountsThatCanTransferMoneyAdded() {
|
protected open fun checkIfThereAreAccountsThatCanTransferMoney(accounts: List<Account>) {
|
||||||
areAccountsThatCanTransferMoneyAdded.value = presenter.accounts.isNotEmpty() // TODO: add check if they support transferring money
|
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.ContextMenuEvent
|
||||||
import javafx.scene.input.MouseButton
|
import javafx.scene.input.MouseButton
|
||||||
import javafx.scene.input.MouseEvent
|
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.AccountTransaction
|
||||||
import net.dankito.banking.ui.model.parameters.TransferMoneyData
|
import net.dankito.banking.ui.model.parameters.TransferMoneyData
|
||||||
import net.dankito.banking.ui.model.responses.GetTransactionsResponse
|
import net.dankito.banking.ui.model.responses.GetTransactionsResponse
|
||||||
|
@ -29,7 +30,7 @@ open class AccountTransactionsView(private val presenter: MainWindowPresenter) :
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
presenter.addAccountAddedListener { handleAccountAdded() }
|
presenter.addAccountsChangedListener { handleAccountsChanged(it) }
|
||||||
|
|
||||||
presenter.addRetrievedAccountTransactionsResponseListener { _, response ->
|
presenter.addRetrievedAccountTransactionsResponseListener { _, response ->
|
||||||
handleGetTransactionsResponseOffUiThread(response)
|
handleGetTransactionsResponseOffUiThread(response)
|
||||||
|
@ -109,8 +110,8 @@ open class AccountTransactionsView(private val presenter: MainWindowPresenter) :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected open fun handleAccountAdded() {
|
protected open fun handleAccountsChanged(accounts: List<Account>) {
|
||||||
isAccountSelected.value = presenter.accounts.isNotEmpty() // TODO: not correct, check if an account has been selected
|
isAccountSelected.value = accounts.isNotEmpty() // TODO: not correct, check if an account has been selected
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun handleGetTransactionsResponseOffUiThread(response: GetTransactionsResponse) {
|
protected open fun handleGetTransactionsResponseOffUiThread(response: GetTransactionsResponse) {
|
||||||
|
|
|
@ -17,8 +17,8 @@ open class AccountsView(protected val presenter: MainWindowPresenter) : View() {
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
presenter.addAccountAddedListener {
|
presenter.addAccountsChangedListener {
|
||||||
accounts.setAll(presenter.accounts)
|
accounts.setAll(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ open class MainWindowPresenter(
|
||||||
|
|
||||||
protected val clientsForAccounts = mutableMapOf<Account, IBankingClient>()
|
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>()
|
protected val retrievedAccountTransactionsResponseListeners = mutableListOf<(BankAccount, GetTransactionsResponse) -> Unit>()
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ open class MainWindowPresenter(
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
clientsForAccounts.put(account, newClient)
|
clientsForAccounts.put(account, newClient)
|
||||||
|
|
||||||
callAccountAddedListeners(account)
|
callAccountsChangedListeners()
|
||||||
|
|
||||||
if (response.supportsRetrievingTransactionsOfLast90DaysWithoutTan) {
|
if (response.supportsRetrievingTransactionsOfLast90DaysWithoutTan) {
|
||||||
account.bankAccounts.forEach { bankAccount ->
|
account.bankAccounts.forEach { bankAccount ->
|
||||||
|
@ -254,13 +254,19 @@ open class MainWindowPresenter(
|
||||||
get() = clientsForAccounts.keys.map { it.balance }.fold(BigDecimal.ZERO) { acc, e -> acc + e }
|
get() = clientsForAccounts.keys.map { it.balance }.fold(BigDecimal.ZERO) { acc, e -> acc + e }
|
||||||
|
|
||||||
|
|
||||||
open fun addAccountAddedListener(listener: (Account) -> Unit) {
|
open fun addAccountsChangedListener(listener: (List<Account>) -> Unit): Boolean {
|
||||||
accountAddedListeners.add(listener)
|
return accountsChangedListeners.add(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun callAccountAddedListeners(account: Account) {
|
open fun removeAccountsChangedListener(listener: (List<Account>) -> Unit): Boolean {
|
||||||
ArrayList(accountAddedListeners).forEach {
|
return accountsChangedListeners.add(listener)
|
||||||
it(account) // TODO: use RxJava for this
|
}
|
||||||
|
|
||||||
|
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
|
package net.dankito.banking.fints4java.android.ui.views
|
||||||
|
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
|
import com.github.clans.fab.FloatingActionButton
|
||||||
import com.github.clans.fab.FloatingActionMenu
|
import com.github.clans.fab.FloatingActionMenu
|
||||||
import kotlinx.android.synthetic.main.view_floating_action_button_main.view.*
|
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
|
import net.dankito.banking.ui.presenter.MainWindowPresenter
|
||||||
|
|
||||||
|
|
||||||
open class MainActivityFloatingActionMenuButton(floatingActionMenu: FloatingActionMenu, protected val presenter: MainWindowPresenter)
|
open class MainActivityFloatingActionMenuButton(floatingActionMenu: FloatingActionMenu, protected val presenter: MainWindowPresenter)
|
||||||
: FloatingActionMenuButton(floatingActionMenu) {
|
: FloatingActionMenuButton(floatingActionMenu) {
|
||||||
|
|
||||||
|
protected lateinit var fabTransferMoney: FloatingActionButton
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setupButtons(floatingActionMenu)
|
setupButtons(floatingActionMenu)
|
||||||
|
|
||||||
|
presenter.addAccountsChangedListener {
|
||||||
|
checkIfThereAreAccountsThatCanTransferMoney(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkIfThereAreAccountsThatCanTransferMoney(presenter.accounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupButtons(floatingActionMenu: FloatingActionMenu) {
|
private fun setupButtons(floatingActionMenu: FloatingActionMenu) {
|
||||||
|
@ -20,19 +29,17 @@ open class MainActivityFloatingActionMenuButton(floatingActionMenu: FloatingActi
|
||||||
executeAndCloseMenu { presenter.showAddAccountDialog() }
|
executeAndCloseMenu { presenter.showAddAccountDialog() }
|
||||||
}
|
}
|
||||||
|
|
||||||
val fabTransferMoney = floatingActionMenu.fabTransferMoney
|
fabTransferMoney = floatingActionMenu.fabTransferMoney
|
||||||
fabTransferMoney.isEnabled = false
|
|
||||||
|
|
||||||
floatingActionMenu.setOnMenuToggleListener {
|
|
||||||
if (floatingActionMenu.isOpened) {
|
|
||||||
fabTransferMoney.isEnabled = presenter.accounts.isNotEmpty()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fabTransferMoney.setOnClickListener {
|
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