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)));
}
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());
}
});
});
}
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);
}
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);
}
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;
}
});
}
Aggregations