I am having trouble creating an observable that will return a list of Objects. I have a list of ids and want to make a request to my database. In this case I am using firebase. When a result is gotten i will like to compile each of these objects into a list and then return that list. I need to wait for all the objects to be returned before i return. I am doing this in my view model deserializer class. Here is my code.
private class Deserializer implements Function<QuerySnapshot, ArrayList<User>>{
@Override
public ArrayList<User> apply(QuerySnapshot input) {
List<DocumentSnapshot> temp = input.getDocuments();
final ArrayList<User> users = new ArrayList<>();
List<String> idList = new ArrayList<>();
for (DocumentSnapshot snapshot: temp){
String userId= snapshot.get("userId").toString();
idList.add(userId);
}
//Create observable and make request to firebase
//compile all the returned into a list return that list
}
}
There are several ways ways i could get data back from my firebase database, i could return the Documentsnapshot Task or i could use a call back to get my data back like so
public void getUser(String userId, final Callback callback){
DocumentReference docRef = db.collection(DATABASE_COLLECTION_USERS).document(userId);
docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
callback.result(documentSnapshot.toObject(User.class));
}
});
}
and then add a callback when calling this function. like getUser(id, new Callback {});
The real problem i am having is how to tie all the request together. I know using RxJava is would be a solution. But i am not knowledgeable on RxJava. It is pretty similar to this question resolving a promise using mongodb and nodejs i asked earlier. That was in nodejs. But i would want to do this using RxJava