I'm developing an Android messenger app. To do so, users sign up with phone number that are stored on Firebase Realtime Database.
To start texting someone, user should have, in his contacts, other signed up users on the DB.
To do that I have a method to retrieve contacts from user's phone and signedUp users on the DB.
private List<String> getContactsFromFirebase(final MyCallback myCallback){
FirebaseDatabase.getInstance().getReference().child("Users")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
Users user = snapshot.getValue(Users.class);
assert user != null;
String contact_found = user.getPhone_number();
mContactsFromFirebase.add(contact_found);
}
myCallback.onCallback(mContactsFromFirebase);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return mContactsFromFirebase;
}
And compared users found on DB with user's contacts
private List<String> findSignedUpContacts(Map<String, String> contactsStored, List<String> firebaseNumbers) {
List<String> values = new ArrayList<>();
for (String firebaseNumberKey : firebaseNumbers) {
values.add(contactsStored.get(firebaseNumberKey));
}
return values;
}
Now, I want to retrieve from Firebase DB, only information regarding numbers stored in the list created above(numbers that match across DB & contacts) and display the result in a FirebaseRecyclerAdapter.
How can I please do that?
Here is my DB structure.
Users
5AWIQqYkdoZwFBqM0YrvZiqBj633
image: "https://firebasestorage.googleapis.com/v0/b/cha..."
name: "Plasita"
phone_number: "+50940404200"
status: "Coding is my life.."
thumbnail: "Default"