Last active
July 11, 2017 08:25
-
-
Save iammert/cb89ef6e11de0900d6e628be6cfda912 to your computer and use it in GitHub Desktop.
FirebaseService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FirebaseService { | |
// ... | |
public Single<List<Genre>> getGenres() { | |
return Single.create(e -> | |
firebaseDatabase.getReference().child("genres") | |
.addListenerForSingleValueEvent(new ValueEventListener() { | |
@Override | |
public void onDataChange(DataSnapshot dataSnapshot) { | |
List<Genre> genreList = new ArrayList<>(); | |
for (DataSnapshot child : dataSnapshot.getChildren()) { | |
genreList.add(child.getValue(Genre.class)); | |
} | |
e.onSuccess(genreList); | |
} | |
@Override | |
public void onCancelled(DatabaseError databaseError) { | |
e.onError(new Throwable()); | |
} | |
})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment