From bb0a2f9713dfbdafb9339d6fcebb57d7b7f1f529 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 10 Sep 2020 03:33:47 +0200 Subject: [PATCH] Implemented displaying how many transactions currently are displayed and the balance of displayed transactions --- .../adapter/AccountTransactionAdapter.kt | 6 +- .../android/extensions/TextViewExtensions.kt | 17 ++++++ .../banking/ui/android/home/HomeFragment.kt | 11 ++++ .../src/main/res/layout/fragment_home.xml | 59 +++++++++++++++++-- .../src/main/res/values-de/strings.xml | 1 + .../src/main/res/values/dimens.xml | 1 + .../src/main/res/values/strings.xml | 1 + 7 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/extensions/TextViewExtensions.kt diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/AccountTransactionAdapter.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/AccountTransactionAdapter.kt index ded6d37e..e1abcc77 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/AccountTransactionAdapter.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/AccountTransactionAdapter.kt @@ -5,12 +5,11 @@ import android.view.ContextMenu import android.view.View import net.dankito.banking.ui.android.R import net.dankito.banking.ui.android.adapter.viewholder.AccountTransactionViewHolder +import net.dankito.banking.ui.android.extensions.showAmount 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 -import java.math.BigDecimal import java.text.DateFormat @@ -43,8 +42,7 @@ open class AccountTransactionAdapter(protected val presenter: BankingPresenter) viewHolder.txtvwUsage.text = item.usage - viewHolder.txtvwAmount.text = presenter.formatAmount(item.amount) - viewHolder.txtvwAmount.setTextColorToColorResource(if (item.amount >= BigDecimal.ZERO) R.color.positiveAmount else R.color.negativeAmount) + viewHolder.txtvwAmount.showAmount(presenter, item.amount) val iconUrl = item.bankAccount.customer.iconUrl if (iconUrl != null && presenter.areAllAccountSelected) { diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/extensions/TextViewExtensions.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/extensions/TextViewExtensions.kt new file mode 100644 index 00000000..729de163 --- /dev/null +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/extensions/TextViewExtensions.kt @@ -0,0 +1,17 @@ +package net.dankito.banking.ui.android.extensions + +import android.widget.TextView +import net.dankito.banking.ui.android.R +import net.dankito.banking.ui.presenter.BankingPresenter +import net.dankito.utils.android.extensions.setTextColorToColorResource +import net.dankito.utils.multiplatform.BigDecimal + + +fun TextView.showAmount(presenter: BankingPresenter, amount: BigDecimal) { + text = presenter.formatAmount(amount) + setTextColorForAmount(amount) +} + +fun TextView.setTextColorForAmount(amount: BigDecimal) { + setTextColorToColorResource(if (amount >= java.math.BigDecimal.ZERO) R.color.positiveAmount else R.color.negativeAmount) +} \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt index eccaed5a..e717e741 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt @@ -13,13 +13,16 @@ import androidx.lifecycle.ViewModelProviders import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import kotlinx.android.synthetic.main.fragment_home.* import net.dankito.banking.ui.android.R import net.dankito.banking.ui.android.di.BankingComponent import net.dankito.banking.ui.android.adapter.AccountTransactionAdapter +import net.dankito.banking.ui.android.extensions.showAmount import net.dankito.banking.ui.model.parameters.TransferMoneyData import net.dankito.banking.ui.model.responses.GetTransactionsResponse import net.dankito.banking.ui.presenter.BankingPresenter import net.dankito.utils.android.extensions.asActivity +import net.dankito.utils.multiplatform.sum import javax.inject.Inject @@ -211,6 +214,14 @@ class HomeFragment : Fragment() { // TODO: if transactions are filtered calculate and show balance of displayed transactions? mnitmBalance.title = presenter.formatAmount(presenter.balanceOfSelectedBankAccounts) mnitmBalance.isVisible = presenter.doSelectedBankAccountsSupportRetrievingBalance + + lytTransactionsSummary.visibility = if (presenter.doSelectedBankAccountsSupportRetrievingBalance) View.VISIBLE else View.GONE + + txtCountTransactions.text = context?.getString(R.string.fragment_home_count_transactions, transactionAdapter.items.size) + + val sumOfDisplayedTransactions = if (appliedTransactionsFilter.isBlank()) presenter.balanceOfSelectedBankAccounts + else transactionAdapter.items.map { it.amount }.sum() + txtTransactionsBalance.showAmount(presenter, sumOfDisplayedTransactions) } } \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/layout/fragment_home.xml b/ui/BankingAndroidApp/src/main/res/layout/fragment_home.xml index 22cad2eb..937175d4 100644 --- a/ui/BankingAndroidApp/src/main/res/layout/fragment_home.xml +++ b/ui/BankingAndroidApp/src/main/res/layout/fragment_home.xml @@ -4,15 +4,62 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + + + + + + + + + + + + \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/values-de/strings.xml b/ui/BankingAndroidApp/src/main/res/values-de/strings.xml index f5609e42..a628ea1f 100644 --- a/ui/BankingAndroidApp/src/main/res/values-de/strings.xml +++ b/ui/BankingAndroidApp/src/main/res/values-de/strings.xml @@ -29,6 +29,7 @@ Umsätze aktualisieren + %d Umsätze Kontoumsätze für \'%1$s\' konnten nicht empfangen werden.\n\nFehlermeldung Ihrer Bank:\n\n%2$s Neue Überweisung an %s Neue Überweisung mit gleichen Daten diff --git a/ui/BankingAndroidApp/src/main/res/values/dimens.xml b/ui/BankingAndroidApp/src/main/res/values/dimens.xml index 6b76968d..c6b002a5 100644 --- a/ui/BankingAndroidApp/src/main/res/values/dimens.xml +++ b/ui/BankingAndroidApp/src/main/res/values/dimens.xml @@ -15,6 +15,7 @@ 42dp 4dp + 24dp 74dp 0dp diff --git a/ui/BankingAndroidApp/src/main/res/values/strings.xml b/ui/BankingAndroidApp/src/main/res/values/strings.xml index e98002b8..c15d8e9e 100644 --- a/ui/BankingAndroidApp/src/main/res/values/strings.xml +++ b/ui/BankingAndroidApp/src/main/res/values/strings.xml @@ -29,6 +29,7 @@ Update transactions + %d transactions Could not retrieve account transactions for \'%1$s\'.\n\nError message from your bank:\n\n%2$s Transfer money to %s New transfer with same data