From f2550d4e9e5a47ecfe976df2e239e55e40d93aab Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 30 Apr 2020 17:55:46 +0200 Subject: [PATCH] Implemented that balance and account transaction's amount are formatted the same --- .../banking/ui/javafx/controls/AccountTransactionsTable.kt | 2 +- .../banking/ui/javafx/controls/AccountTransactionsView.kt | 2 +- .../net/dankito/banking/ui/presenter/BankingPresenter.kt | 5 +++++ .../android/ui/adapter/AccountTransactionAdapter.kt | 5 +++-- .../banking/fints4java/android/ui/home/HomeFragment.kt | 6 ++++-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsTable.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsTable.kt index 5a9bdea0..222a3c25 100644 --- a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsTable.kt +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsTable.kt @@ -105,7 +105,7 @@ open class AccountTransactionsTable @JvmOverloads constructor( cellValueFactory = Callback { object : ObjectBinding() { override fun computeValue(): String { - return it.value.amount.toString() + " " + it.value.currency + return presenter.formatAmount(it.value.amount) + " " + it.value.currency } } } 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 6908f895..d77abbf5 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 @@ -126,7 +126,7 @@ open class AccountTransactionsView(private val presenter: BankingPresenter) : Vi transactionsToDisplay.setAll(presenter.searchSelectedAccountTransactions(filter)) // TODO: if transactions are filtered calculate and show balance of displayed transactions? - balance.value = presenter.balanceOfSelectedBankAccounts.toString() + balance.value = presenter.formatAmount(presenter.balanceOfSelectedBankAccounts) } protected open fun handleGetTransactionsResponseOffUiThread(response: GetTransactionsResponse) { diff --git a/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt b/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt index 55fd562f..d21a69b5 100644 --- a/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -294,6 +294,11 @@ open class BankingPresenter( persistAccountTransactions(response.bookedTransactions, response.unbookedTransactions) } + open fun formatAmount(amount: BigDecimal): String { + return String.format("%.02f", amount) + } + + protected open fun persistAccount(account: Account) { persister.saveOrUpdateAccount(account, accounts) } diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/AccountTransactionAdapter.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/AccountTransactionAdapter.kt index b27051eb..441263f1 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/AccountTransactionAdapter.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/AccountTransactionAdapter.kt @@ -5,6 +5,7 @@ import android.view.View import net.dankito.banking.fints4java.android.R import net.dankito.banking.fints4java.android.ui.adapter.viewholder.AccountTransactionViewHolder import net.dankito.banking.ui.model.AccountTransaction +import net.dankito.banking.ui.presenter.BankingPresenter import net.dankito.utils.android.extensions.asActivity import net.dankito.utils.android.extensions.setTextColorToColorResource import net.dankito.utils.android.ui.adapter.ListRecyclerAdapter @@ -12,7 +13,7 @@ import java.math.BigDecimal import java.text.DateFormat -open class AccountTransactionAdapter +open class AccountTransactionAdapter(protected val presenter: BankingPresenter) : ListRecyclerAdapter() { companion object { @@ -46,7 +47,7 @@ open class AccountTransactionAdapter viewHolder.txtvwUsage2.visibility = View.GONE // TODO viewHolder.txtvwUsage2.text = "" // TODO - viewHolder.txtvwAmount.text = String.format("%.02f", item.amount) + viewHolder.txtvwAmount.text = presenter.formatAmount(item.amount) viewHolder.txtvwAmount.setTextColorToColorResource(if (item.amount >= BigDecimal.ZERO) R.color.positiveAmount else R.color.negativeAmount) } diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt index e6ab5deb..b1d93907 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt @@ -34,7 +34,7 @@ class HomeFragment : Fragment() { private lateinit var mnitmUpdateTransactions: MenuItem - private val transactionAdapter = AccountTransactionAdapter() + private val transactionAdapter: AccountTransactionAdapter protected var appliedTransactionsFilter = "" @@ -45,6 +45,8 @@ class HomeFragment : Fragment() { init { BankingComponent.component.inject(this) + + transactionAdapter = AccountTransactionAdapter(presenter) } @@ -203,7 +205,7 @@ class HomeFragment : Fragment() { transactionAdapter.items = presenter.searchSelectedAccountTransactions(appliedTransactionsFilter) // TODO: if transactions are filtered calculate and show balance of displayed transactions? - mnitmBalance.title = presenter.balanceOfSelectedBankAccounts.toString() + mnitmBalance.title = presenter.formatAmount(presenter.balanceOfSelectedBankAccounts) mnitmBalance.isVisible = presenter.doSelectedBankAccountsSupportRetrievingBalance }