Please see how to use it in recycler view:
// Get Chats List From FireStore
private void getChatListFromFireBase(String hiddenStatus) {
lIndividualChatList = new ArrayList<>();
lIndividualChatListIds = new ArrayList<>();
lIndividualChatList.clear();
lIndividualChatListIds.clear();
fbFs.collection("individual_chats")
.document(mySqlUserId)
.collection("lists")
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(QuerySnapshot documentSnapshots,
FirebaseFirestoreException e) {
if (e != null) {
}
for (DocumentChange dc : documentSnapshots.getDocumentChanges()) {
switch (dc.getType()) {
case ADDED:
key = dc.getDocument()
.getId();
firebaseRetrofitQuery(dc,
"Added",
key);
break;
case MODIFIED:
key = dc.getDocument()
.getId();
// Do The Change Function
firebaseRetrofitQuery(dc,
"Changed",
key);
break;
case REMOVED:
break;
}
}
}
});
}
// FireBase And Retrofit Query
private void firebaseRetrofitQuery(DocumentChange documentChange,
final String childActivityType,
final String key) {
if (childActivityType.equals("Added")) {
lIndividualChatListIds.add(key);
}
// Get The Receiver Id To Get Data From Other Nodes
final String mySqlFriendUserId = documentChange.getDocument()
.getId();
final String hideStatus = (String) documentChange.getDocument()
.getData()
.get("hide_status");
if (childActivityType.equals("Added")) {
// Populate The Array List With Data From Both Nodes
lIndividualChatList.add(new IndividualListModel(mySqlFriendUserId,
hideStatus));
}
if (childActivityType.equals("Changed")) {
int index = lIndividualChatListIds.indexOf(key);
lIndividualChatList.set(index,
new IndividualListModel(mySqlFriendUserId,
hideStatus));
}
// Use The Adapter To Populate The Recycler View
aIndividualChatList = new IndividualListAdapter(getContext(),
lIndividualChatList,
senderActivity,
new IndividualListAdapter.OnItemClickListener() {
@Override
public void onItemClicked(final Map data) {
}
});
rvList.setAdapter(aIndividualChatList);
aIndividualChatList.notifyDataSetChanged();
}