I have two collections in my firestore database, the first is list of all the documents (BlockList), and the second for the users. when the user bookmark post on Recyclerview on the app, send the id of the document and timestamp to sub-collection (Favorites) under Users Collection.
i retrieve the list of documents based on this ids from the main collection (BlockList), but i want to arrange them according to timestamp for each user, so i've tried to order them by timestamp before adding them to Arraylist and Log the list, i've got the correct result. but the recyclerview still retrieved them ascending order by document ID !
firebaseFirestore.collection("Users")
.document(userId).collection("Favorites").orderBy("timestamp", Query.Direction.DESCENDING).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
List<String> list = new ArrayList<>();
for (QueryDocumentSnapshot document : task.getResult()) {
list.add(document.getId());
}
Log.d(TAG, list.toString());
if (list.size() != 0){
blockReffav = firebaseFirestore.collection("BlockList")
.whereIn(FieldPath.documentId(), list);
blockReffav.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if(task.isSuccessful()){
onFirestoreTaskComplete.blockListDataAdded(task.getResult().toObjects(BlockListModel.class));
} else {
onFirestoreTaskComplete.onError(task.getException());
}
}
});
}
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});