44066

Followers structure firebase android

Question:

I want to implement followers functionality in my android application. 'First' image refers to the list of user i followed. 'second' image have all ids of all the posts that users post and 'third' image havin post details. all i want to do is to load only the post of those users that i've followed.

What i am doing is, i get emails from followers node and by using indexed recyclerview i load the data but its not working because recyclerview is not getting dynamic reference. Any sugested solution ?

first

<a href="https://i.stack.imgur.com/cHTX7.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/cHTX7.png" data-original="https://i.stack.imgur.com/cHTX7.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

second

<a href="https://i.stack.imgur.com/QVSJA.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/QVSJA.png" data-original="https://i.stack.imgur.com/QVSJA.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

third

<a href="https://i.stack.imgur.com/B9O97.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/B9O97.png" data-original="https://i.stack.imgur.com/B9O97.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Answer1:

In order to achieve this, you need to query your database for three times like this:

FirebaseUser firebaseUser = firebaseAuth.getCurrentUser(); String userEmail = firebaseUser.getEmail(); String encodedUserEmail = userEmail.replace(".", ","); DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference(); DatabaseReference userEmailFromFollowersRef = rootRef.child("followers").child(encodedUserEmail); ValueEventListener eventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for(DataSnapshot ds : dataSnapshot.getChildren()) { String followerEmail = ds.getKey(); DatabaseReference my_postsRef = rootRef.child("my_posts").child(followerEmail); ValueEventListener valueEventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for(DataSnapshot dSnapshot : dataSnapshot.getChildren()) { String postId = dSnapshot.getKey(); DatabaseReference postsRef = rootRef.child("posts").child(postId); ValueEventListener vel = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for(DataSnapshot child : dataSnapshot.getChildren()) { String postText = child.child("postText").getValue(String.class); Log.d("TAG", postText); } } @Override public void onCancelled(DatabaseError databaseError) {} }; postsRef.addListenerForSingleValueEvent(vel); } } @Override public void onCancelled(DatabaseError databaseError) {} }; my_postsRef.addListenerForSingleValueEvent(valueEventListener); } } @Override public void onCancelled(DatabaseError databaseError) {} }; userEmailFromFollowersRef.addListenerForSingleValueEvent(eventListener);

Recommend

  • Access Google spreadsheet API without Oauth token
  • Regular Expressions, understanding lookbehind in combination with the or operator
  • send midi messages from C++
  • Typescript 2.1.5 Function calls are not supported
  • Android Studio error: cannot find symbol class AdapterViewCompat with compileSdkVersion 23 and build
  • how to style pagination links without config - codeigniter
  • How to correctly append dynamic GetUIKit accordions?
  • How to pause a python script running in terminal
  • boost::format vs sprintf
  • How to get length of a dynamic array in Delphi? [closed]
  • Finding max value of a weighted subset sum of a power set
  • RxJava,Retrofit Error :Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
  • Difficulties implementing the Hysteresis step of Canny Algorithm in Halide without define_extern fun
  • Recycler View Inside Recycler View not Scrolling
  • a concept similar to pointers in as3?
  • Ability to use Bootstrap 3 grid system to specify width of select element
  • How to synchronize two scrollview in Android?
  • F#: In which memory area is the continuation stored: stack or heap?
  • using System.Speech.Synthesis with Windows10 universal app (XAML-C#)
  • GAE: Way to get reference to an HttpSession from its ID?
  • Spring boot 2.0.0.M4 required a bean named 'entityManagerFactory' that could not be found
  • What is the purpose of TaskExecutor in spring?
  • Access Android Market through SSH tunnel
  • Breeze - Deleted Items nav properties bug
  • Get data from AJAX - How to
  • Adding a button at the bottom of a table view
  • Fetching methods from BroadcastReceiver to update UI
  • javaw.exe and eclipse startup problems
  • Excel - Autoshape get it's name from cell (value)
  • Check if a string to interpolate provides expected placeholders
  • RestKit - RKRequestDelegate does not exist
  • Traverse Array and Display in markup
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • embed rChart in Markdown
  • need help with bizarre java.net.HttpURLConnection behavior
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • Android Heatmap on canvas or ImageView
  • Conditional In-Line CSS for IE and Others?