Hello,
I want to run 2 queries to effectively create and != operator. Each query uses the orderBy method to order the results. But when I run these 2 queries independently, it's not guaranteed that one finishes before the other, right?
I am trying to figure out how to merge these 2 tasks locally to get the results in the correct order. There is no specific documentation about this case in Firestore. There is general Firebase documentation, but I don't know if I put 2 and 2 together properly, because there are multiple way of doing this I can think of.
Should I merge these 2 queries with whenAllSuccess? Is this the appropriate way of doing this? If yes, how do I use the List<Object> objects? It contains my QuerySnapshots, right? But how do I cast it properly? I am confused.
(I just put them into a TextView for testing purposes. I know that I should use a RecyclerView instead)
Enter code here...public void loadNotes(View v) {
Task task1 = notebookRef
.whereLessThan("priority", 2)
.orderBy("priority")
.get();
Task task2 = notebookRef
.whereGreaterThan("priority", 2)
.orderBy("priority")
.get();
Tasks.whenAllSuccess(task1, task2).addOnSuccessListener(new OnSuccessListener<List<Object>>() {
@Override
public void onSuccess(List<Object> objects) {
String data = "";
for (Object object : objects) {
QuerySnapshot queryDocumentSnapshots = (QuerySnapshot) object;
for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
Note note = documentSnapshot.toObject(Note.class);
note.setDocumentId(documentSnapshot.getId());
String documentId = note.getDocumentId();
String title = note.getTitle();
String description = note.getDescription();
int priority = note.getPriority();
data += "ID: " + documentId
+ "\nTitle: " + title + "\nDescription: " + description
+ "\nPriority: " + priority + "\n\n";
}
textViewData.setText(data);
}
}
});
}