use of rx.Subscription in project LookLook by xinghongfei.
the class ZhihuPresenterImpl method getTheDaily.
@Override
public void getTheDaily(String date) {
Subscription subscription = ApiManage.getInstence().getZhihuApiService().getTheDaily(date).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) {
e.printStackTrace();
mZhihuFragment.hidProgressDialog();
mZhihuFragment.showError(e.getMessage());
}
@Override
public void onNext(ZhihuDaily zhihuDaily) {
mZhihuFragment.hidProgressDialog();
mZhihuFragment.updateList(zhihuDaily);
}
});
addSubscription(subscription);
}
use of rx.Subscription in project LookLook by xinghongfei.
the class ZhihuStoryPresenterImpl method getZhihuStory.
@Override
public void getZhihuStory(String id) {
Subscription s = ApiManage.getInstence().getZhihuApiService().getZhihuStory(id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ZhihuStory>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
mIZhihuStory.showError(e.getMessage());
}
@Override
public void onNext(ZhihuStory zhihuStory) {
mIZhihuStory.showZhihuStory(zhihuStory);
}
});
addSubscription(s);
}
use of rx.Subscription in project requery by requery.
the class RxTest method testQuerySelfObservableMap.
@Test
public void testQuerySelfObservableMap() throws Exception {
final AtomicInteger count = new AtomicInteger();
Subscription subscription = data.select(Person.class).limit(2).get().toSelfObservable().flatMap(new Func1<RxResult<Person>, Observable<Person>>() {
@Override
public Observable<Person> call(RxResult<Person> persons) {
return persons.toObservable();
}
}).subscribe(new Action1<Person>() {
@Override
public void call(Person persons) {
count.incrementAndGet();
}
});
data.insert(randomPerson()).toBlocking().value();
data.insert(randomPerson()).toBlocking().value();
assertEquals(3, count.get());
subscription.unsubscribe();
}
use of rx.Subscription in project requery by requery.
the class RxTest method testQuerySelfObservableRelational.
@Test
public void testQuerySelfObservableRelational() throws Exception {
final AtomicInteger count = new AtomicInteger();
Subscription subscription = data.select(Person.class).get().toSelfObservable().subscribe(new Action1<Result<Person>>() {
@Override
public void call(Result<Person> persons) {
count.incrementAndGet();
}
});
Person person = randomPerson();
data.insert(person).toBlocking().value();
Phone phone = randomPhone();
person.getPhoneNumbers().add(phone);
data.update(person).toBlocking().value();
data.delete(phone).toBlocking().value();
assertEquals(4, count.get());
subscription.unsubscribe();
}
use of rx.Subscription in project Meizhi by drakeet.
the class PictureActivity method saveImageToGallery.
private void saveImageToGallery() {
// @formatter:off
Subscription s = RxMeizhi.saveImageAndGetPathObservable(this, mImageUrl, mImageTitle).observeOn(AndroidSchedulers.mainThread()).subscribe(uri -> {
File appDir = new File(Environment.getExternalStorageDirectory(), "Meizhi");
String msg = String.format(getString(R.string.picture_has_save_to), appDir.getAbsolutePath());
Toasts.showShort(msg);
}, error -> Toasts.showLong(error.getMessage() + "\n再试试..."));
// @formatter:on
addSubscription(s);
}
Aggregations