use of rx.Subscription in project realm-java by realm.
the class GotchasActivity method testSubscribeOn.
/**
* Shows how to be careful with `subscribeOn()`
*/
private Subscription testSubscribeOn() {
Subscription subscribeOn = realm.asObservable().map(new Func1<Realm, Person>() {
@Override
public Person call(Realm realm) {
return realm.where(Person.class).findAllSorted("name").get(0);
}
}).subscribeOn(//
Schedulers.io()).subscribe(new Action1<Person>() {
@Override
public void call(Person person) {
// Do nothing
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
showStatus("subscribeOn: " + throwable.toString());
}
});
// Use Realms Async API instead
Subscription asyncSubscribeOn = realm.where(Person.class).findAllSortedAsync("name").get(0).<Person>asObservable().subscribe(new Action1<Person>() {
@Override
public void call(Person person) {
showStatus("subscribeOn/async: " + person.getName() + ":" + person.getAge());
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
showStatus("subscribeOn/async: " + throwable.toString());
}
});
return new CompositeSubscription(subscribeOn, asyncSubscribeOn);
}
use of rx.Subscription in project realm-java by realm.
the class GotchasActivity method onResume.
@Override
protected void onResume() {
super.onResume();
Subscription distinctSubscription = testDistinct();
Subscription bufferSubscription = testBuffer();
Subscription subscribeOnSubscription = testSubscribeOn();
// Trigger updates
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
realm.where(Person.class).findAllSorted("name", Sort.ASCENDING).get(0).setAge(new Random().nextInt(100));
}
});
subscription = new CompositeSubscription(distinctSubscription, bufferSubscription, subscribeOnSubscription);
}
use of rx.Subscription in project reark by reark.
the class GitHubRepositoryFetcher method fetchGitHubRepository.
private void fetchGitHubRepository(final int repositoryId) {
Log.d(TAG, "fetchGitHubRepository(" + repositoryId + ")");
if (isOngoingRequest(repositoryId)) {
Log.d(TAG, "Found an ongoing request for repository " + repositoryId);
return;
}
final String uri = getUniqueId(repositoryId);
Subscription subscription = createNetworkObservable(repositoryId).subscribeOn(Schedulers.computation()).doOnSubscribe(() -> startRequest(uri)).doOnError(doOnError(uri)).doOnCompleted(() -> completeRequest(uri)).subscribe(gitHubRepositoryStore::put, e -> Log.e(TAG, "Error fetching GitHub repository " + repositoryId, e));
addRequest(repositoryId, subscription);
}
use of rx.Subscription in project LookLook by xinghongfei.
the class TopNewsPrensenterImpl method getNewsList.
@Override
public void getNewsList(int t) {
mITopNewsFragment.showProgressDialog();
Subscription subscription = ApiManage.getInstence().getTopNewsService().getNews(t).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<NewsList>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
mITopNewsFragment.hidProgressDialog();
mITopNewsFragment.showError(e.toString());
}
@Override
public void onNext(NewsList newsList) {
mITopNewsFragment.hidProgressDialog();
mITopNewsFragment.upListItem(newsList);
}
});
addSubscription(subscription);
}
use of rx.Subscription in project LookLook by xinghongfei.
the class ZhihuPresenterImpl method getLastZhihuNews.
@Override
public void getLastZhihuNews() {
mZhihuFragment.showProgressDialog();
Subscription subscription = ApiManage.getInstence().getZhihuApiService().getLastDaily().map(new Func1<ZhihuDaily, ZhihuDaily>() {
@Override
public ZhihuDaily call(ZhihuDaily zhihuDaily) {
String date = zhihuDaily.getDate();
for (ZhihuDailyItem zhihuDailyItem : zhihuDaily.getStories()) {
zhihuDailyItem.setDate(date);
}
return zhihuDaily;
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ZhihuDaily>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
mZhihuFragment.hidProgressDialog();
mZhihuFragment.showError(e.getMessage());
}
@Override
public void onNext(ZhihuDaily zhihuDaily) {
mZhihuFragment.hidProgressDialog();
mCacheUtil.put(Config.ZHIHU, gson.toJson(zhihuDaily));
mZhihuFragment.updateList(zhihuDaily);
}
});
addSubscription(subscription);
}
Aggregations