diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt index 764ae37d..e5544447 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt @@ -4,10 +4,7 @@ import net.dankito.banking.fints4java.android.Base64ServiceAndroid import net.dankito.fints.FinTsClient import net.dankito.fints.FinTsClientCallback import net.dankito.fints.banks.BankFinder -import net.dankito.fints.model.BankData -import net.dankito.fints.model.BankInfo -import net.dankito.fints.model.CustomerData -import net.dankito.fints.model.GetTransactionsParameter +import net.dankito.fints.model.* import net.dankito.fints.model.mapper.BankDataMapper import net.dankito.fints.response.client.FinTsClientResponse import net.dankito.fints.response.client.GetTransactionsResponse @@ -26,6 +23,10 @@ open class MainWindowPresenter(callback: FinTsClientCallback) { protected val bankDataMapper = BankDataMapper() + protected val bookedTransactions = mutableSetOf() // TODO: map by account + + protected val unbookedTransactions = mutableSetOf() + protected val accountAddedListeners = mutableListOf<(BankData, CustomerData) -> Unit>() @@ -48,7 +49,14 @@ open class MainWindowPresenter(callback: FinTsClientCallback) { open fun getAccountTransactionsAsync(bank: BankData, customer: CustomerData, 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 { + 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) { accountAddedListeners.add(listener) } 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 54b4fa89..4388c94d 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 @@ -1,11 +1,16 @@ package net.dankito.banking.fints4java.android.ui.home +import android.app.SearchManager import android.arch.lifecycle.ViewModelProviders +import android.content.Context import android.os.Bundle import android.support.v4.app.Fragment import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView +import android.support.v7.widget.SearchView 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.R import net.dankito.banking.fints4java.android.ui.MainWindowPresenter @@ -25,7 +30,9 @@ class HomeFragment : Fragment() { private lateinit var homeViewModel: HomeViewModel - private var mnitmBalance: MenuItem? = null + private lateinit var mnitmBalance: MenuItem + + private lateinit var mnitmSearchTransactions: MenuItem private val transactionAdapter = AccountTransactionAdapter() @@ -66,7 +73,31 @@ class HomeFragment : Fragment() { override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { 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 response.balance?.let { - mnitmBalance?.title = it.toString() + mnitmBalance.title = it.toString() } } 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) + } + } \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/layout/list_item_account_transaction.xml b/fints4javaAndroidApp/src/main/res/layout/list_item_account_transaction.xml index bd2851eb..7b23f19f 100644 --- a/fints4javaAndroidApp/src/main/res/layout/list_item_account_transaction.xml +++ b/fints4javaAndroidApp/src/main/res/layout/list_item_account_transaction.xml @@ -39,7 +39,6 @@ android:id="@+id/txtvwBookingText" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="Ueberweisung" /> diff --git a/fints4javaAndroidApp/src/main/res/menu/main.xml b/fints4javaAndroidApp/src/main/res/menu/main.xml index da1dccd9..dfac23de 100644 --- a/fints4javaAndroidApp/src/main/res/menu/main.xml +++ b/fints4javaAndroidApp/src/main/res/menu/main.xml @@ -3,9 +3,16 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + + + /> diff --git a/fints4javaAndroidApp/src/main/res/values/strings.xml b/fints4javaAndroidApp/src/main/res/values/strings.xml index 059d1b35..29615b69 100644 --- a/fints4javaAndroidApp/src/main/res/values/strings.xml +++ b/fints4javaAndroidApp/src/main/res/values/strings.xml @@ -4,6 +4,8 @@ Select Cancel + Search + Open navigation drawer Close navigation drawer Android Studio