MaterialSearchBar
MaterialSearchBar copied to clipboard
Notify Listeners when tapping Arrow and Clear buttons
Hi,
First of all, thanks for this awesome lib.
I've implemented a simple OnSearchActionListener
and have noticed that onButtonClicked
is not being called when I tap on the clear
and the back
(left arrow) buttons of the MaterialSearchBar
. This is my code:
searchBar.setOnSearchActionListener(object : MaterialSearchBar.OnSearchActionListener {
override fun onButtonClicked(buttonCode: Int) {
toast("Pressed: $buttonCode")
}
override fun onSearchStateChanged(enabled: Boolean) = Unit
override fun onSearchConfirmed(text: CharSequence?) {
// My SearchConfirmed stuff
}
})
Having a look at the library code, I found that the onSearchActionListener
is not being notified in these cases (R.id.mt_arrow
and R.id.mt_clear
)
@Override
public void onClick(View v) {
int id = v.getId();
if (id == getId()) {
if (!searchEnabled) {
enableSearch();
}
} else if (id == R.id.mt_arrow) {
disableSearch();
} else if (id == R.id.mt_search) {
if (listenerExists())
onSearchActionListener.onButtonClicked(BUTTON_SPEECH);
} else if (id == R.id.mt_clear) {
searchEdit.setText("");
} else if (id == R.id.mt_menu) {
popupMenu.show();
} else if (id == R.id.mt_nav)
if (listenerExists()) {
if (navIconShown) {
onSearchActionListener.onButtonClicked(BUTTON_NAVIGATION);
} else {
onSearchActionListener.onButtonClicked(BUTTON_BACK);
}
}
}
Is this the expected behaviour of the library? Maybe it'd be a good idea to notify the listeners on these cases. If you want, I can submit a pull request with the modification (just two lines in the corresponding else
if
's).
What's your opinion? :)
Yea, i agree, i tried to implement search bar on main screen instead of toolbar, and also use nav drawer icon, but still icons doesnt respond at all. Try to fix opening drawer also.