Skip to content

Commit

Permalink
Added workaround that we only query once
Browse files Browse the repository at this point in the history
  • Loading branch information
xizzhu committed Mar 4, 2019
1 parent e80c34c commit f7e1229
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SearchToolbar : Toolbar, SearchView.OnQueryTextListener, ToolbarView {
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

private val searchView: SearchView
private var currentQuery: String = ""

init {
setLogo(R.drawable.ic_toolbar)
Expand All @@ -59,6 +60,14 @@ class SearchToolbar : Toolbar, SearchView.OnQueryTextListener, ToolbarView {
}

override fun onQueryTextSubmit(query: String): Boolean {
if (query == currentQuery) {
// Seems there's a bug inside SearchView.mOnEditorActionListener that onEditorAction()
// will be called both when the key is down and when the key is up.
// Therefore, if the query is the same, we do nothing.
return true
}
currentQuery = query

val handled = presenter.search(query)
if (handled) {
if (hasFocus()) {
Expand Down

0 comments on commit f7e1229

Please sign in to comment.