title: Android repository pattern for firestore
body: <p>To have a better separation of concerns I'd like to implement a repository which handles all the firestore interaction. </p>
  
  <p>Currently, my code looks like this:</p>
  
  <p>UserRepository:</p>
  
  <pre><code>public class UserRepository {
  
      private static final String TAG = "UserRepository";
  
      private FirebaseFirestore db = FirebaseFirestore.getInstance();
      private CollectionReference usersRef = db.collection("users");
  
      public Task&lt;DocumentSnapshot&gt; get(String email) {
          DocumentReference docRef = usersRef.document(email); // Users are referenced by email
          Log.d(TAG, "Checking DocumentReference exists for: " + email);
          return docRef.get();
      }
  }
  </code></pre>
  
  <p>MainActivity</p>
  
  <pre><code>                final UserRepository userRepository = new UserRepository();
  
                  userRepository.get(currentUser.getEmail()).addOnSuccessListener(new OnSuccessListener&lt;DocumentSnapshot&gt;() {
                      @Override
                      public void onSuccess(DocumentSnapshot documentSnapshot) {
                          Log.d(TAG, "DocumentSnapshot got");
                          // Do something with user
                      }
                  }).addOnFailureListener(new OnFailureListener() {
                      @Override
                      public void onFailure(@NonNull Exception e) {
                          Log.d(TAG, "Could not get DocumentReference", e);
                      }
                  });
  </code></pre>
  
  <p>User is a POJO</p>
  
  <p>What I would like to achieve is a Repository which instead of Task returns Task somewhat like this:</p>
  
  <pre><code>public Task&lt;User&gt; get(String email) {
      DocumentReference docRef = usersRef.document(email);
      /* Convert and return task? */
  }
  </code></pre>
  
  <p>Which then could be used like usual, attaching a listener in the MainActivity. I'm afraid I am somewhat lacking skill in concurrency but I feel like this should be possible without having to synchronize. Could you give me a hint on how to achieve this?</p>
  
  <p>Thanks in advance!</p>