Created
October 3, 2017 20:43
-
-
Save PierceZ/4950f6f0a1807b945809a78cc6770136 to your computer and use it in GitHub Desktop.
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 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you get access to the App?