Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GroupAdapter item count is misrepresented if empty groups are present #432

Open
jsoberg opened this issue Oct 12, 2022 · 0 comments
Open
Labels

Comments

@jsoberg
Copy link

jsoberg commented Oct 12, 2022

Describe the bug
If you add empty NestedGroups to a GroupAdapter, they aren't accounted for when you call GroupAdapter.getItemCount() and therefore the item count that you see from your adapter will technically be off by how many empty groups exist in your adapter at the time.

I tracked this bug down while trying to do some automated scrolling to bottom of the GroupAdapter's RecyclerView on certain events, and noticed that my scrolls were off by a certain amount every time. After debugging through GroupUtils.getItemCount -> NestedGroup.getItemCount, I noticed that I had 2 empty Groups in my adapter that weren't being counted. I confirmed by adding 2 to the item count when scrolling, and it was scrolling to the expected position each time afterward.

To Reproduce
Steps to reproduce the behavior:

  1. Add an arbitrary number of NestedGroups to a GroupAdapter, attached to a RecyclerView.
  2. Attempt to scroll to a certain position (RecyclerView.smoothScrollToPosition). My test case was for the bottom (itemCount - 1)
  3. RecyclerView scrolls to two Groups before your specified position (e.g. if you try and scroll to bottom, it will instead scroll to the second Group above the bottom).

Expected behavior
Expected behavior would be to include empty NestedGroups in the GroupAdapter's item count, so that we have the "correct" number of items in the adapter for situations like this.

Library version
2.10.1

Additional context
It probably makes more sense to not add empty Groups, though there might be (semi-valid) reasons to do so.

@jsoberg jsoberg added the bug label Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant