Skip to content

Instantly share code, notes, and snippets.

@gonzalonm
Last active February 8, 2018 18:21
Show Gist options
  • Save gonzalonm/b2b273a2a1b4d3880827f529b67b004b to your computer and use it in GitHub Desktop.
Save gonzalonm/b2b273a2a1b4d3880827f529b67b004b to your computer and use it in GitHub Desktop.
Retrieve an Observable (including key) using RxFirebaseDatabase
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