Search in sources :

Example 41 with Subscription

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);
}
Also used : ZhihuDaily(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDaily) ZhihuDailyItem(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDailyItem) Subscription(rx.Subscription) Func1(rx.functions.Func1)

Example 42 with 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);
}
Also used : Subscription(rx.Subscription) IZhihuStory(com.looklook.xinghongfei.looklook.presenter.implView.IZhihuStory) ZhihuStory(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuStory)

Example 43 with Subscription

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(rx.Subscription) Func1(rx.functions.Func1) Person(io.requery.test.model.Person) RxResult(io.requery.rx.RxResult) Test(org.junit.Test)

Example 44 with Subscription

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Phone(io.requery.test.model.Phone) Subscription(rx.Subscription) Person(io.requery.test.model.Person) RxResult(io.requery.rx.RxResult) Result(io.requery.query.Result) Test(org.junit.Test)

Example 45 with Subscription

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);
}
Also used : Subscription(rx.Subscription) File(java.io.File)

Aggregations

Subscription (rx.Subscription)302 Test (org.junit.Test)82 List (java.util.List)75 CompositeSubscription (rx.subscriptions.CompositeSubscription)55 Action0 (rx.functions.Action0)45 ArrayList (java.util.ArrayList)41 CountDownLatch (java.util.concurrent.CountDownLatch)38 Func1 (rx.functions.Func1)24 AtomicReference (java.util.concurrent.atomic.AtomicReference)20 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 Observable (rx.Observable)17 LinkedList (java.util.LinkedList)13 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)11 PlayList (io.github.ryanhoo.music.data.model.PlayList)11 MetaChangedEvent (io.hefuyi.listener.event.MetaChangedEvent)10 View (android.view.View)9 IOException (java.io.IOException)9 AndroidSchedulers (rx.android.schedulers.AndroidSchedulers)8 Intent (android.content.Intent)7