Skip to content

Instantly share code, notes, and snippets.

@florent37
Last active February 19, 2016 16:15
Show Gist options
  • Save florent37/5190f4315e1a42e52a6b to your computer and use it in GitHub Desktop.
Save florent37/5190f4315e1a42e52a6b to your computer and use it in GitHub Desktop.
#ADD
interface Callback<T>{
void onSuccess();
void onError(T data);
}
userEntityManager.addAsync(List<User> users, new Callback<List<User>>{
void onSuccess(){}
void onError(List<User> data){}
});
#RX
Observable<List<User>> getUsersFromNetwork(...);
Observable<User> getSingleUserFromNetwork(...);
getUsersFromNetwork(...)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.flatMap(userEntityManager::addAsync)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(users -> {
//notifyItemInserted(object);
});
#SELECT
userEntityManager.select()
.name().equalsTo("florent")
.async(new Callback<List<User>>(){
public void onResult(List<User> objects){
}
});
#RX
userEntityManager.select()
.name().equalsTo("florent")
.asObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<User>>(){
public void call(List<User> objects){
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment