Implemented displaying how many transactions currently are displayed and the balance of displayed transactions

This commit is contained in:
dankito 2020-09-10 03:33:47 +02:00
parent 921447bda8
commit bb0a2f9713
7 changed files with 86 additions and 10 deletions

View File

@ -5,12 +5,11 @@ import android.view.ContextMenu
import android.view.View import android.view.View
import net.dankito.banking.ui.android.R import net.dankito.banking.ui.android.R
import net.dankito.banking.ui.android.adapter.viewholder.AccountTransactionViewHolder 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.model.AccountTransaction
import net.dankito.banking.ui.presenter.BankingPresenter import net.dankito.banking.ui.presenter.BankingPresenter
import net.dankito.utils.android.extensions.asActivity import net.dankito.utils.android.extensions.asActivity
import net.dankito.utils.android.extensions.setTextColorToColorResource
import net.dankito.utils.android.ui.adapter.ListRecyclerAdapter import net.dankito.utils.android.ui.adapter.ListRecyclerAdapter
import java.math.BigDecimal
import java.text.DateFormat import java.text.DateFormat
@ -43,8 +42,7 @@ open class AccountTransactionAdapter(protected val presenter: BankingPresenter)
viewHolder.txtvwUsage.text = item.usage viewHolder.txtvwUsage.text = item.usage
viewHolder.txtvwAmount.text = presenter.formatAmount(item.amount) viewHolder.txtvwAmount.showAmount(presenter, item.amount)
viewHolder.txtvwAmount.setTextColorToColorResource(if (item.amount >= BigDecimal.ZERO) R.color.positiveAmount else R.color.negativeAmount)
val iconUrl = item.bankAccount.customer.iconUrl val iconUrl = item.bankAccount.customer.iconUrl
if (iconUrl != null && presenter.areAllAccountSelected) { if (iconUrl != null && presenter.areAllAccountSelected) {

View File

@ -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)
}

View File

@ -13,13 +13,16 @@ import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView 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.R
import net.dankito.banking.ui.android.di.BankingComponent import net.dankito.banking.ui.android.di.BankingComponent
import net.dankito.banking.ui.android.adapter.AccountTransactionAdapter 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.parameters.TransferMoneyData
import net.dankito.banking.ui.model.responses.GetTransactionsResponse import net.dankito.banking.ui.model.responses.GetTransactionsResponse
import net.dankito.banking.ui.presenter.BankingPresenter import net.dankito.banking.ui.presenter.BankingPresenter
import net.dankito.utils.android.extensions.asActivity import net.dankito.utils.android.extensions.asActivity
import net.dankito.utils.multiplatform.sum
import javax.inject.Inject import javax.inject.Inject
@ -211,6 +214,14 @@ class HomeFragment : Fragment() {
// TODO: if transactions are filtered calculate and show balance of displayed transactions? // TODO: if transactions are filtered calculate and show balance of displayed transactions?
mnitmBalance.title = presenter.formatAmount(presenter.balanceOfSelectedBankAccounts) mnitmBalance.title = presenter.formatAmount(presenter.balanceOfSelectedBankAccounts)
mnitmBalance.isVisible = presenter.doSelectedBankAccountsSupportRetrievingBalance 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)
} }
} }

View File

@ -4,15 +4,62 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/fragment_account_transaction_margin_start_and_end"
android:layout_marginEnd="@dimen/fragment_account_transaction_margin_start_and_end"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
<RelativeLayout
android:id="@+id/lytTransactionsSummary"
android:layout_width="match_parent"
android:layout_height="@dimen/fragment_account_transaction_transactions_summary_height"
android:layout_marginTop="4dp"
>
<TextView
android:id="@+id/txtCountTransactions"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:textAlignment="gravity"
/>
<TextView
android:id="@+id/txtTransactionsBalance"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:textAlignment="gravity"
/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcyvwAccountTransactions" android:id="@+id/rcyvwAccountTransactions"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/fragment_account_transaction_margin_start_and_end" android:layout_below="@+id/lytTransactionsSummary"
android:layout_marginEnd="@dimen/fragment_account_transaction_margin_start_and_end" android:layout_alignParentLeft="true"
app:layout_constraintEnd_toEndOf="parent" android:layout_alignParentStart="true"
app:layout_constraintStart_toStartOf="parent" android:layout_alignParentRight="true"
app:layout_constraintTop_toTopOf="parent" android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/> />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -29,6 +29,7 @@
<string name="menu_main_update_transactions">Umsätze aktualisieren</string> <string name="menu_main_update_transactions">Umsätze aktualisieren</string>
<string name="fragment_home_count_transactions">%d Umsätze</string>
<string name="fragment_home_could_not_retrieve_account_transactions">Kontoumsätze für \'%1$s\' konnten nicht empfangen werden.\n\nFehlermeldung Ihrer Bank:\n\n%2$s</string> <string name="fragment_home_could_not_retrieve_account_transactions">Kontoumsätze für \'%1$s\' konnten nicht empfangen werden.\n\nFehlermeldung Ihrer Bank:\n\n%2$s</string>
<string name="fragment_home_transfer_money_to">Neue Überweisung an %s</string> <string name="fragment_home_transfer_money_to">Neue Überweisung an %s</string>
<string name="fragment_home_transfer_money_with_same_data">Neue Überweisung mit gleichen Daten</string> <string name="fragment_home_transfer_money_with_same_data">Neue Überweisung mit gleichen Daten</string>

View File

@ -15,6 +15,7 @@
<dimen name="fab_margin_bottom_with_toolbar">42dp</dimen> <dimen name="fab_margin_bottom_with_toolbar">42dp</dimen>
<dimen name="fragment_account_transaction_margin_start_and_end">4dp</dimen> <dimen name="fragment_account_transaction_margin_start_and_end">4dp</dimen>
<dimen name="fragment_account_transaction_transactions_summary_height">24dp</dimen>
<dimen name="list_item_account_transaction_height">74dp</dimen> <dimen name="list_item_account_transaction_height">74dp</dimen>
<dimen name="list_item_account_transaction_padding">0dp</dimen> <dimen name="list_item_account_transaction_padding">0dp</dimen>

View File

@ -29,6 +29,7 @@
<string name="menu_main_update_transactions">Update transactions</string> <string name="menu_main_update_transactions">Update transactions</string>
<string name="fragment_home_count_transactions">%d transactions</string>
<string name="fragment_home_could_not_retrieve_account_transactions">Could not retrieve account transactions for \'%1$s\'.\n\nError message from your bank:\n\n%2$s</string> <string name="fragment_home_could_not_retrieve_account_transactions">Could not retrieve account transactions for \'%1$s\'.\n\nError message from your bank:\n\n%2$s</string>
<string name="fragment_home_transfer_money_to">Transfer money to %s</string> <string name="fragment_home_transfer_money_to">Transfer money to %s</string>
<string name="fragment_home_transfer_money_with_same_data">New transfer with same data</string> <string name="fragment_home_transfer_money_with_same_data">New transfer with same data</string>