Implemented searching account transactions
This commit is contained in:
parent
7e930ff1d7
commit
3aae75c62b
|
@ -4,10 +4,7 @@ import net.dankito.banking.fints4java.android.Base64ServiceAndroid
|
||||||
import net.dankito.fints.FinTsClient
|
import net.dankito.fints.FinTsClient
|
||||||
import net.dankito.fints.FinTsClientCallback
|
import net.dankito.fints.FinTsClientCallback
|
||||||
import net.dankito.fints.banks.BankFinder
|
import net.dankito.fints.banks.BankFinder
|
||||||
import net.dankito.fints.model.BankData
|
import net.dankito.fints.model.*
|
||||||
import net.dankito.fints.model.BankInfo
|
|
||||||
import net.dankito.fints.model.CustomerData
|
|
||||||
import net.dankito.fints.model.GetTransactionsParameter
|
|
||||||
import net.dankito.fints.model.mapper.BankDataMapper
|
import net.dankito.fints.model.mapper.BankDataMapper
|
||||||
import net.dankito.fints.response.client.FinTsClientResponse
|
import net.dankito.fints.response.client.FinTsClientResponse
|
||||||
import net.dankito.fints.response.client.GetTransactionsResponse
|
import net.dankito.fints.response.client.GetTransactionsResponse
|
||||||
|
@ -26,6 +23,10 @@ open class MainWindowPresenter(callback: FinTsClientCallback) {
|
||||||
protected val bankDataMapper = BankDataMapper()
|
protected val bankDataMapper = BankDataMapper()
|
||||||
|
|
||||||
|
|
||||||
|
protected val bookedTransactions = mutableSetOf<AccountTransaction>() // TODO: map by account
|
||||||
|
|
||||||
|
protected val unbookedTransactions = mutableSetOf<Any>()
|
||||||
|
|
||||||
protected val accountAddedListeners = mutableListOf<(BankData, CustomerData) -> Unit>()
|
protected val accountAddedListeners = mutableListOf<(BankData, CustomerData) -> Unit>()
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +49,14 @@ open class MainWindowPresenter(callback: FinTsClientCallback) {
|
||||||
open fun getAccountTransactionsAsync(bank: BankData, customer: CustomerData,
|
open fun getAccountTransactionsAsync(bank: BankData, customer: CustomerData,
|
||||||
callback: (GetTransactionsResponse) -> Unit) {
|
callback: (GetTransactionsResponse) -> Unit) {
|
||||||
|
|
||||||
finTsClient.getTransactionsAsync(GetTransactionsParameter(), bank, customer, callback)
|
finTsClient.getTransactionsAsync(GetTransactionsParameter(), bank, customer) { response ->
|
||||||
|
if (response.isSuccessful) {
|
||||||
|
bookedTransactions.addAll(response.bookedTransactions)
|
||||||
|
unbookedTransactions.addAll(response.unbookedTransactions)
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(response)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,6 +71,21 @@ open class MainWindowPresenter(callback: FinTsClientCallback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
open fun searchAccountTransactions(query: String): List<AccountTransaction> {
|
||||||
|
val queryLowercase = query.trim().toLowerCase()
|
||||||
|
|
||||||
|
if (queryLowercase.isEmpty()) {
|
||||||
|
return bookedTransactions.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
return bookedTransactions.filter {
|
||||||
|
it.otherPartyName?.toLowerCase()?.contains(queryLowercase) == true
|
||||||
|
|| it.usage.toLowerCase().contains(queryLowercase)
|
||||||
|
|| it.bookingText?.toLowerCase()?.contains(queryLowercase) == true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
open fun addAccountAddedListener(listener: (BankData, CustomerData) -> Unit) {
|
open fun addAccountAddedListener(listener: (BankData, CustomerData) -> Unit) {
|
||||||
accountAddedListeners.add(listener)
|
accountAddedListeners.add(listener)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package net.dankito.banking.fints4java.android.ui.home
|
package net.dankito.banking.fints4java.android.ui.home
|
||||||
|
|
||||||
|
import android.app.SearchManager
|
||||||
import android.arch.lifecycle.ViewModelProviders
|
import android.arch.lifecycle.ViewModelProviders
|
||||||
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.RecyclerView
|
||||||
|
import android.support.v7.widget.SearchView
|
||||||
import android.view.*
|
import android.view.*
|
||||||
|
import android.view.inputmethod.EditorInfo
|
||||||
|
import android.widget.EditText
|
||||||
import net.dankito.banking.fints4java.android.MainActivity
|
import net.dankito.banking.fints4java.android.MainActivity
|
||||||
import net.dankito.banking.fints4java.android.R
|
import net.dankito.banking.fints4java.android.R
|
||||||
import net.dankito.banking.fints4java.android.ui.MainWindowPresenter
|
import net.dankito.banking.fints4java.android.ui.MainWindowPresenter
|
||||||
|
@ -25,7 +30,9 @@ class HomeFragment : Fragment() {
|
||||||
|
|
||||||
private lateinit var homeViewModel: HomeViewModel
|
private lateinit var homeViewModel: HomeViewModel
|
||||||
|
|
||||||
private var mnitmBalance: MenuItem? = null
|
private lateinit var mnitmBalance: MenuItem
|
||||||
|
|
||||||
|
private lateinit var mnitmSearchTransactions: MenuItem
|
||||||
|
|
||||||
private val transactionAdapter = AccountTransactionAdapter()
|
private val transactionAdapter = AccountTransactionAdapter()
|
||||||
|
|
||||||
|
@ -66,7 +73,31 @@ class HomeFragment : Fragment() {
|
||||||
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
|
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
|
||||||
super.onCreateOptionsMenu(menu, inflater)
|
super.onCreateOptionsMenu(menu, inflater)
|
||||||
|
|
||||||
mnitmBalance = menu?.findItem(R.id.mnitmBalance)
|
menu?.let {
|
||||||
|
mnitmBalance = menu.findItem(R.id.mnitmBalance)
|
||||||
|
|
||||||
|
mnitmSearchTransactions = menu.findItem(R.id.mnitmSearchTransactions)
|
||||||
|
|
||||||
|
initSearchView()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initSearchView() {
|
||||||
|
context?.asActivity()?.let { context ->
|
||||||
|
(context.getSystemService(Context.SEARCH_SERVICE) as? SearchManager)?.let { searchManager ->
|
||||||
|
(mnitmSearchTransactions.actionView as? SearchView)?.let { searchView ->
|
||||||
|
searchView.setSearchableInfo(searchManager.getSearchableInfo(context.componentName))
|
||||||
|
|
||||||
|
// if imeOptions aren't set like this searchView would take whole remaining screen when focused in landscape mode (see https://stackoverflow.com/questions/15296129/searchview-and-keyboard)
|
||||||
|
val searchInput =
|
||||||
|
searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text) as? EditText
|
||||||
|
searchInput?.imeOptions = EditorInfo.IME_ACTION_SEARCH or EditorInfo.IME_FLAG_NO_EXTRACT_UI
|
||||||
|
|
||||||
|
searchView.setOnQueryTextListener(searchAccountTransactionsTextListener)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,7 +120,7 @@ class HomeFragment : Fragment() {
|
||||||
transactionAdapter.items = response.bookedTransactions
|
transactionAdapter.items = response.bookedTransactions
|
||||||
|
|
||||||
response.balance?.let {
|
response.balance?.let {
|
||||||
mnitmBalance?.title = it.toString()
|
mnitmBalance.title = it.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -99,4 +130,20 @@ class HomeFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private val searchAccountTransactionsTextListener: SearchView.OnQueryTextListener = object : SearchView.OnQueryTextListener {
|
||||||
|
override fun onQueryTextChange(query: String): Boolean {
|
||||||
|
searchAccountTransactions(query)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onQueryTextSubmit(query: String): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun searchAccountTransactions(query: String) {
|
||||||
|
transactionAdapter.items = presenter.searchAccountTransactions(query)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -39,7 +39,6 @@
|
||||||
android:id="@+id/txtvwBookingText"
|
android:id="@+id/txtvwBookingText"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Ueberweisung"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -48,14 +47,12 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/list_item_account_transaction_other_party_name_margin_top_and_bottom"
|
android:layout_marginTop="@dimen/list_item_account_transaction_other_party_name_margin_top_and_bottom"
|
||||||
android:layout_marginBottom="@dimen/list_item_account_transaction_other_party_name_margin_top_and_bottom"
|
android:layout_marginBottom="@dimen/list_item_account_transaction_other_party_name_margin_top_and_bottom"
|
||||||
android:text="Device Insight GmbH"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/txtvwUsage1"
|
android:id="@+id/txtvwUsage1"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="1908301/EUR 8144.36/2019-10-02/..."
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -63,7 +60,6 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
android:text="2019-09-27T19.44 Debitk.3 2019-12"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -3,6 +3,13 @@
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
|
||||||
|
<item android:id="@+id/mnitmSearchTransactions"
|
||||||
|
android:icon="@android:drawable/ic_menu_search"
|
||||||
|
app:showAsAction="always|collapseActionView"
|
||||||
|
app:actionViewClass="android.support.v7.widget.SearchView"
|
||||||
|
android:title="@string/search"
|
||||||
|
/>
|
||||||
|
|
||||||
<item android:id="@+id/mnitmBalance"
|
<item android:id="@+id/mnitmBalance"
|
||||||
android:title=""
|
android:title=""
|
||||||
app:showAsAction="always"
|
app:showAsAction="always"
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
<string name="select">Select</string>
|
<string name="select">Select</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
|
|
||||||
|
<string name="search">Search</string>
|
||||||
|
|
||||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||||
<string name="nav_header_title">Android Studio</string>
|
<string name="nav_header_title">Android Studio</string>
|
||||||
|
|
Loading…
Reference in New Issue