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

FirebaseIndexRecyclerAdapter - Calling getItemCount() inside onDataChanged always return 0 #719

Closed
Shirane85 opened this issue May 21, 2017 · 2 comments

Comments

@Shirane85
Copy link

Step 2: Describe your environment

  • Android device: _____
  • Android OS version: _____
  • Google Play Services version: _____
  • Firebase/Play Services SDK version: _____
  • FirebaseUI version: 10.2.0

Step 3: Describe the problem:

I'm using FirebaseIndexRecyclerAdapter and I'm overriding onDataChanged for hiding a progress bar and/or displaying an empty state depends on the itemsCount (Something which i've already done with FirebaseRecyclerAdapter and works as expected) but getItemCount always return 0(!)

I've investigate it and the reason is that FirebaseIndexRecyclerAdapter is using FirebaseIndexArray which is overriding getItemCount and return mDataSnapshots.size() but the data was not loaded yet - the onDataChanged was called because the keyRef loaded - and indeed i can see in debug that the keys are loaded (with the correct count) but unfortunately they are private so i can't use them to get the count.

I know i can override onChildChanged and then call getItemCount and get the correct count (which i've done) but still i can't know if there are no items and i need to display the empty state.

Is there something i'm missing?

Note - I know i can manage my own count (child) beside the data and just load it before setting the adapter but i'm saving this as a last resort.

Steps to reproduce:

  1. Set new FirebaseIndexRecyclerAdapter to a RecyclerView
  2. Override onChildChanged
  3. Call getItemCount inside

Observed Results:

  • It returns 0 always

Expected Results:

  • Should return the data child actual count

Relevant Code:

Thanks

@SUPERCILEX
Copy link
Collaborator

@Shirane85 Yeah, don't rely on onDataChanged when using the index adapters pre v2.0; they're completely broken. This is fixed in v2.0 which will be coming out soon.

If you really need onDataChanged, I'm happy to get you setup with the latest v2.0 build, just ask. 😄

@Shirane85
Copy link
Author

I really need it, but if you say it will be coming out soon then i'll wait :)
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

3 participants