mancj / mancj/MaterialSearchBar
Notify Listeners when tapping Arrow and Clear buttons
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2k
- Forks
- 324
- PR merge metrics
- No merged PRs in 30d
Description
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? :)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the MaterialSearchBar onClick implementation shown in the issue, focusing on the R.id.mt_arrow and R.id.mt_clear branches and the OnSearchActionListener callbacks. Verify the expected button codes and confirm that tapping both controls notifies the listener while preserving their existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100