Fix crash related to using the wrong RxBinding method with the Transactions SearchView, make some improvements and remove the old code used with the SearchView before using the SearchView's RxBinding method.

This commit is contained in:
Severiano Jaramillo 2018-12-24 11:15:25 -06:00
parent a39daaf155
commit e4391dad73

View file

@ -10,20 +10,21 @@ import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.LinearLayoutManager
import com.jakewharton.rxbinding3.appcompat.queryTextChanges
import com.jakewharton.rxbinding3.appcompat.queryTextChangeEvents
import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.adapters.TransfersDetailsAdapter
import cy.agorise.bitsybitshareswallet.database.joins.TransferDetail
import cy.agorise.bitsybitshareswallet.utils.BounceTouchListener
import cy.agorise.bitsybitshareswallet.utils.Constants
import cy.agorise.bitsybitshareswallet.viewmodels.TransferDetailViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.fragment_transactions.*
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.collections.ArrayList
class TransactionsFragment : Fragment(), SearchView.OnQueryTextListener {
class TransactionsFragment : Fragment() {
private lateinit var mTransferDetailViewModel: TransferDetailViewModel
@ -89,10 +90,11 @@ class TransactionsFragment : Fragment(), SearchView.OnQueryTextListener {
val searchItem = menu.findItem(R.id.menuSearch)
val searchView = searchItem.actionView as SearchView
mDisposables.add(
searchView.queryTextChanges()
searchView.queryTextChangeEvents()
.skipInitialValue()
.debounce(500, TimeUnit.MILLISECONDS)
.map { it.toString().toLowerCase() }
.map { it.queryText.toString().toLowerCase() }
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
filterQuery = it
applyFilterOptions()
@ -115,14 +117,6 @@ class TransactionsFragment : Fragment(), SearchView.OnQueryTextListener {
return size.x
}
override fun onQueryTextChange(query: String): Boolean {
filterQuery = query.toLowerCase()
applyFilterOptions()
return true
}
override fun onQueryTextSubmit(query: String?) = false // Not needed since we are filtering as the user types
/**
* Filters the TransferDetail list given the user selected filter options.
* TODO move this to a background thread