I stored all the users information in the firestore with their UID as a document. Now i create a Node as Friends in realtimeDatabase with the UID as child. Now i want to retrieve only the users whose UID is present in Friends node but the users are not showing in the recyclerView or i don't know the right way.
Firestore where all the user's info saved
And this is how were node Friends created on an operation.
FirebaseDatabase.getInstance().reference
.child("Friends")
.child(currentUserID)
.child(profileId)
.setValue("Friend")
.addOnSuccessListener{
FirebaseDatabase.getInstance().reference
.child("Friends")
.child(profileId)
.child(currentUserID)
.setValue("Friend")}
And this is how i am trying to retrieve them in a recyclerView in a fragment according to Realtime-Database
private fun retrieveFriends()
{
val usersRef = FirebaseDatabase.getInstance().reference.child("Friends")
usersRef.addValueEventListener(object : ValueEventListener
{
override fun onDataChange(dataSnapshot: DataSnapshot)
{
mFriend?.clear()
for (snapshot in dataSnapshot.children)
{
val friend = snapshot.getValue(User::class.java)
if (friend != null)
{
mFriend?.add(friend)
}
friendAdapter?.notifyDataSetChanged()
}
}
})
}
In the userAdapter, setting up the values like this
private fun friendInfo(fullName: TextView, about: TextView, location: TextView, profileImage: CircleImageView) {
val pref = mContext.getSharedPreferences("PREF", Context.MODE_PRIVATE)
if (pref != null) {
this.profileId = pref.getString("profileId", "none").toString()
}
val userRef = FirebaseFirestore.getInstance().collection("Users").document(profileId)
userRef.get()
.addOnSuccessListener { documentSnapshot ->
if (documentSnapshot != null && documentSnapshot.exists()) {
val user = documentSnapshot.toObject(User::class.java)
Picasso.get().load(user!!.getImage()).placeholder(R.drawable.default_pro_pic).into(profileImage)
fullName.text = user.getFullName()
about.text = user.getAbout()
location.text = user.getLocation()
}
}
}