Last active
February 8, 2018 18:21
-
-
Save gonzalonm/b2b273a2a1b4d3880827f529b67b004b to your computer and use it in GitHub Desktop.
Retrieve an Observable (including key) using RxFirebaseDatabase
This file contains hidden or 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
RxFirebaseDatabase | |
.observeValueEvent(database.getReference("list")) | |
.map(new Function<DataSnapshot, List<DataEntity>>() { | |
@Override | |
public List<DataEntity> apply(@NonNull DataSnapshot parent) throws Exception { | |
List<DataEntity> list = new ArrayList<>(); | |
for (DataSnapshot item : parent.getChildren()) { | |
DataEntity entity = new DataEntity(); | |
entity.setEndDate((Integer) item.child("endDate").getValue()); | |
entity.setStartDate((Integer) item.child("startDate").getValue()); | |
entity.setKey(item.getKey()); | |
list.add(entity); | |
} | |
return list; | |
} | |
}) | |
.toObservable(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment