Search in sources :

Example 51 with Observable

use of io.reactivex.Observable in project butter-android by butterproject.

the class VodoProvider method items.

@NonNull
@Override
public Single<ItemsWrapper> items(@Nullable final Filter filter, @Nullable Pager pager) {
    String query = null;
    String genre = null;
    String sorter = null;
    if (filter != null) {
        if (filter.getGenre() != null) {
            genre = filter.getGenre().getKey();
        }
        if (filter.getSorter() != null) {
            sorter = filter.getSorter().getKey();
        }
        query = filter.getQuery();
    }
    final int page;
    if (pager != null && pager.getEndCursor() != null) {
        page = Integer.parseInt(pager.getEndCursor());
    } else {
        page = 0;
    }
    return vodoService.fetchMovies(query, genre, sorter, null, null, ITEMS_PER_PAGE, page).map(VodoResponse::getDownloads).flatMapObservable(Observable::fromArray).map(this::mapVodoMovie).cast(Media.class).toList().map(m -> new ItemsWrapper(m, new Paging(String.valueOf(page + 1), m.size() == ITEMS_PER_PAGE)));
}
Also used : Paging(butter.droid.provider.base.paging.Paging) ItemsWrapper(butter.droid.provider.base.paging.ItemsWrapper) Observable(io.reactivex.Observable) NonNull(android.support.annotation.NonNull)

Example 52 with Observable

use of io.reactivex.Observable in project MusicLake by caiyonglong.

the class BaiduApiServiceImpl method getTingSongInfo.

// {"errorCode":22232,"data":{"xcode":"","songList":""}}
public static Observable<Music> getTingSongInfo(String mid) {
    Map<String, String> params = new HashMap<>();
    String Url = "http://music.baidu.com/data/music/links?songIds=" + mid;
    return getApiService().getTingSongInfo(Url, params).flatMap(baiduSongInfo -> {
        Music music = new Music();
        BaiduSongInfo.DataBean.SongListBean songInfo = baiduSongInfo.getData().getSongList().get(0);
        music.setType(Music.Type.BAIDU);
        music.setOnline(true);
        music.setId(songInfo.getSongId());
        music.setAlbum(songInfo.getAlbumName());
        music.setAlbumId(songInfo.getAlbumId());
        music.setArtistId(songInfo.getArtistId());
        music.setArtist(songInfo.getArtistName());
        music.setTitle(songInfo.getSongName());
        music.setUri(songInfo.getSongLink());
        music.setFileSize(songInfo.getSize());
        music.setLrcPath(songInfo.getLrcLink());
        music.setCoverSmall(songInfo.getSongPicSmall());
        music.setCoverUri(songInfo.getSongPicBig());
        music.setCoverBig(songInfo.getSongPicRadio());
        return Observable.create((ObservableOnSubscribe<Music>) e -> {
            if (music.getUri() != null) {
                e.onNext(music);
                e.onComplete();
            } else {
                e.onError(new Throwable());
            }
        });
    });
}
Also used : List(java.util.List) Music(com.cyl.musiclake.bean.Music) LogUtil(com.cyl.musiclake.utils.LogUtil) FileUtils(com.cyl.musiclake.utils.FileUtils) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Map(java.util.Map) HashMap(java.util.HashMap) Observable(io.reactivex.Observable) Constants(com.cyl.musiclake.common.Constants) ApiManager(com.cyl.musiclake.net.ApiManager) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Music(com.cyl.musiclake.bean.Music)

Example 53 with Observable

use of io.reactivex.Observable in project CloudReader by youlookwhat.

the class JokeModel method showQSBKList.

public void showQSBKList(final WanNavigator.JokeModelNavigator listener, int page) {
    Function<QsbkListBean, Observable<List<DuanZiBean>>> func1 = new Function<QsbkListBean, Observable<List<DuanZiBean>>>() {

        @Override
        public Observable<List<DuanZiBean>> apply(QsbkListBean bean) {
            List<DuanZiBean> lists = new ArrayList<>();
            if (bean != null && bean.getItems() != null && bean.getItems().size() > 0) {
                List<QsbkListBean.ItemsBean> items = bean.getItems();
                for (QsbkListBean.ItemsBean bean1 : items) {
                    DuanZiBean duanZiBean = new DuanZiBean();
                    duanZiBean.setContent(bean1.getContent());
                    duanZiBean.setCreateTime(bean1.getPublished_at());
                    QsbkListBean.ItemsBean.TopicBean topic = bean1.getTopic();
                    QsbkListBean.ItemsBean.UserBean user = bean1.getUser();
                    if (topic != null) {
                        duanZiBean.setCategoryName(topic.getContent());
                    }
                    if (user != null) {
                        duanZiBean.setName(user.getLogin());
                        String thumb = user.getThumb();
                        if (!TextUtils.isEmpty(thumb)) {
                            if (!thumb.contains("http")) {
                                StringBuilder stringBuilder = new StringBuilder();
                                stringBuilder.append("http:");
                                stringBuilder.append(thumb);
                                duanZiBean.setAvatarUrl(stringBuilder.toString());
                            } else {
                                duanZiBean.setAvatarUrl(thumb);
                            }
                        }
                    }
                    lists.add(duanZiBean);
                }
            }
            return Observable.just(lists);
        }
    };
    Observer<List<DuanZiBean>> observer = new Observer<List<DuanZiBean>>() {

        @Override
        public void onError(Throwable e) {
            listener.loadFailed();
        }

        @Override
        public void onComplete() {
        }

        @Override
        public void onSubscribe(Disposable d) {
            listener.addSubscription(d);
        }

        @Override
        public void onNext(List<DuanZiBean> lists) {
            listener.loadSuccess(lists);
        }
    };
    HttpClient.Builder.getQSBKServer().getQsbkList(page).flatMap(func1).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(observer);
}
Also used : Disposable(io.reactivex.disposables.Disposable) ArrayList(java.util.ArrayList) QsbkListBean(com.example.jingbin.cloudreader.bean.wanandroid.QsbkListBean) Observable(io.reactivex.Observable) Function(io.reactivex.functions.Function) Observer(io.reactivex.Observer) ArrayList(java.util.ArrayList) List(java.util.List) DuanZiBean(com.example.jingbin.cloudreader.bean.wanandroid.DuanZiBean)

Example 54 with Observable

use of io.reactivex.Observable in project requery by requery.

the class ReactiveTest method testInsertCount.

@Test
public void testInsertCount() throws Exception {
    Person person = randomPerson();
    Observable.just(person).concatMap(new Function<Person, Observable<Person>>() {

        @Override
        public Observable<Person> apply(Person person) {
            return data.insert(person).toObservable();
        }
    });
    Person p = data.insert(person).blockingGet();
    assertTrue(p.getId() > 0);
    int count = data.count(Person.class).get().single().blockingGet();
    assertEquals(1, count);
}
Also used : Person(io.requery.test.model.Person) Observable(io.reactivex.Observable) Test(org.junit.Test)

Example 55 with Observable

use of io.reactivex.Observable in project GwellDemo by dxsdyhm.

the class DeviceActivity method initServer.

private void initServer() {
    Observable observable = Observable.create(new ObservableOnSubscribe<String>() {

        @Override
        public void subscribe(ObservableEmitter<String> subscriber) throws Exception {
            String ip = Util.IPPasser(NetAddressDefault);
            if (TextUtils.isEmpty(ip)) {
                subscriber.onError(new Exception("net error"));
            } else {
                subscriber.onNext(ip);
            }
            subscriber.onComplete();
        }
    });
    // 指定 subscribe() 发生在 IO 线程
    observable.subscribeOn(Schedulers.io()).observeOn(// 指定 Subscriber 的回调发生在主线程
    AndroidSchedulers.mainThread()).subscribe(new Observer<String>() {

        @Override
        public void onError(Throwable e) {
            txLog.append(Util.getLogStr(getString(R.string.netaddress_error)));
            txLog.append(Util.getLogStr(testEnd));
        }

        @Override
        public void onComplete() {
            UserInitData();
            sendLogPort();
        }

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onNext(String s) {
            IPDefault = s;
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) Observable(io.reactivex.Observable)

Aggregations

Observable (io.reactivex.Observable)170 List (java.util.List)54 ArrayList (java.util.ArrayList)39 Test (org.junit.Test)36 Collectors (java.util.stream.Collectors)29 InOrder (org.mockito.InOrder)27 TestException (io.reactivex.exceptions.TestException)24 Page (io.nem.symbol.sdk.api.Page)19 Address (io.nem.symbol.sdk.model.account.Address)18 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)18 Disposable (io.reactivex.disposables.Disposable)18 Bundle (android.os.Bundle)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 Function (io.reactivex.functions.Function)15 TestObserver (io.reactivex.observers.TestObserver)15 Schedulers (io.reactivex.schedulers.Schedulers)15 Nullable (android.support.annotation.Nullable)14 MerkleStateInfo (io.nem.symbol.sdk.model.blockchain.MerkleStateInfo)14 ApiClient (io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient)14 AsyncResult (io.vertx.core.AsyncResult)14