arimorty / floatingsearchview

A search view that implements a floating search bar also known as persistent search
https://github.com/arimorty/floatingsearchview/blob/master/README.md
Apache License 2.0
3.54k stars 668 forks source link

Wrong calculation of suggestions list height #264

Open eduardbosch opened 7 years ago

eduardbosch commented 7 years ago

Hi again 🎉

I've fixed another issue that causes the suggestions list to be positioned not in the first item when suggestions are swapped.

The problem

The problem was that sometimes the suggestions RecyclerView create fewer items than the number of swapped suggestions, but it says that the items do not fill all the height suggestions. This is impossible because suggestions could not fill all the suggestions list view only if he can draw all swapped suggestions. So, when some suggestions are not drawn, is a signal that there are more suggestions than what suggestions list could fit, and this means that the suggestions list height fill all the view height.


Test

To test this, I've used an emulator with 4,5'' and 480x854 resolution. Also, I've tested this on an LG x220ds.

Then, I've changed the DataHelper color suggestions to this values. This caused the suggestions RecyclerView to draw fewer children than using shorter names.

            sColorSuggestions= new ArrayList<>(Arrays.asList(
                    new ColorSuggestion("GREEN multi line text in tiny screens"),
                    new ColorSuggestion("BLUE multi line text in tiny screens"),
                    new ColorSuggestion("pink"),
                    new ColorSuggestion("purple"),
                    new ColorSuggestion("brown"),
                    new ColorSuggestion("gray"),
                    new ColorSuggestion("Granny Smith Apple"),
                    new ColorSuggestion("Indigo"),
                    new ColorSuggestion("Periwinkle"),
                    new ColorSuggestion("Mahogany"),
                    new ColorSuggestion("Maize"),
                    new ColorSuggestion("Mahogany"),
                    new ColorSuggestion("Outer Space"),
                    new ColorSuggestion("Melon"),
                    new ColorSuggestion("Yellow"),
                    new ColorSuggestion("Orange"),
                    new ColorSuggestion("Red"),
                    new ColorSuggestion("Orchid")));

I've also forced to show 10 suggestions every time I type a work by changing the listener to this in SlidingSearchResultsExampleFragment:

        mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {

            @Override
            public void onSearchTextChanged(String oldQuery, final String newQuery) {
                mSearchView.swapSuggestions(DataHelper.getHistory(getActivity(), 10));

                Log.d(TAG, "onSearchTextChanged()");
            }
        });

Before the fix

incorrect_height_calculation

After the fix

correct_height_calculation