Improve responsivenes of suggestions in MerchantsFragment's SearchView by reducing the debounce effect and clearing the query results if the query is shorter than 2 chars.

This commit is contained in:
Severiano Jaramillo 2019-01-28 19:48:11 -06:00
parent 9ecac53f62
commit 978e8d6ee2

View file

@ -166,11 +166,14 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio
// Add listener to changes in the SearchView's text to update the suggestions // Add listener to changes in the SearchView's text to update the suggestions
mSearchView?.queryTextChangeEvents() mSearchView?.queryTextChangeEvents()
?.skipInitialValue() ?.skipInitialValue()
?.debounce(500, TimeUnit.MILLISECONDS) ?.debounce(200, TimeUnit.MILLISECONDS)
?.map { it.queryText.toString().toLowerCase() } ?.map { it.queryText.toString().toLowerCase() }
?.observeOn(AndroidSchedulers.mainThread()) ?.observeOn(AndroidSchedulers.mainThread())
?.subscribe { ?.subscribe {
updateSearchViewSuggestions(it) if (it.length < 2)
mSearchView?.suggestionsAdapter?.changeCursor(null)
else
updateSearchViewSuggestions(it)
}?.let { }?.let {
mDisposables.add(it) mDisposables.add(it)
} }