Skip to content

Instantly share code, notes, and snippets.

@PierceZ
Created October 3, 2017 20:43
Show Gist options
  • Save PierceZ/4950f6f0a1807b945809a78cc6770136 to your computer and use it in GitHub Desktop.
Save PierceZ/4950f6f0a1807b945809a78cc6770136 to your computer and use it in GitHub Desktop.
public class ZooDAO {
private static Box<Zoo> getZooBox() {
BoxStore boxStore = App.getBoxStore();
return boxStore.boxFor(Zoo.class);
}
public static DataSubscription subscribeToZooList(DataObserver<List<Zoo>> observer) {
return getZooBox().query().build().subscribe().on(AndroidScheduler.mainThread()).observer(observer);
}
public static DataSubscription subscribeToZoo(DataObserver<Zoo> observer, long id, boolean singleUpdate) {
SubscriptionBuilder<Zoo> builder = getZooBox().query().eager(Zoo_.animals).equal(Zoo_.id, id).build().subscribe().transform(list -> {
if (list.size() == 0) {
return null;
} else {
return list.get(0);
}
}).on(AndroidScheduler.mainThread());
if (singleUpdate) {
builder.single();
}
return builder.observer(observer);
}
public static void insertZoo(Zoo zoo) {
getZooBox().put(zoo);
}
public static void insertZoos(Collection<Zoo> zoos) {
getZooBox().put(zoos);
}
}
@panmona
Copy link

panmona commented Mar 30, 2018

How do you get access to the App?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment