From f7e1229730a3f5fb8c4ec81ea4506fba6413eeb2 Mon Sep 17 00:00:00 2001 From: Xizhi Zhu Date: Mon, 4 Mar 2019 00:09:50 -0800 Subject: [PATCH] Added workaround that we only query once --- .../android/joshua/search/toolbar/SearchToolbar.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/kotlin/me/xizzhu/android/joshua/search/toolbar/SearchToolbar.kt b/app/src/main/kotlin/me/xizzhu/android/joshua/search/toolbar/SearchToolbar.kt index 9b1b4be57..c6e378b6c 100644 --- a/app/src/main/kotlin/me/xizzhu/android/joshua/search/toolbar/SearchToolbar.kt +++ b/app/src/main/kotlin/me/xizzhu/android/joshua/search/toolbar/SearchToolbar.kt @@ -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) @@ -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()) {