MaterialSearchBar icon indicating copy to clipboard operation
MaterialSearchBar copied to clipboard

After filtering suggestions, list size doesn't change

Open emitchel opened this issue 5 years ago • 0 comments

image

Using a filter as the user enters in text (as shown in the library example) which works as expected - but am unable to animate suggestions without listening to the filter and calling searchBar.updateSuggestions(...). Would expect this to happen natively.

As of now, doing away with the adapter filter and manually updating suggestions within the text changed listener.

override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {
                if (!search_bar.isSearchEnabled) return

                if (charSequence.isNotEmpty()) {
                    search_bar.updateLastSuggestions(search_bar.lastSuggestions.filter {
                        val artist = it as Artist
                        artist.name?.contains(charSequence.toString(), true) ?: false
                    })
                } else {
                    search_bar.updateLastSuggestions(mainViewModel.lastSearchedArtists.value?.getData())
                }
            }

Which I guess isn't a terrible approach, just feels like an antipattern with adapter filter logic.

Feel free to close if this is indeed the suggested use case, if so, maybe update the example? https://github.com/mancj/MaterialSearchBar/blob/master/app/src/main/java/com/mancj/example/custom/CustomAdapterActivity.java

emitchel avatar Jan 02 '19 15:01 emitchel