use of io.reactivex.ObservableOnSubscribe in project MyJapanese by 54wall.
the class FavWordsFragmentModelImpl method getData.
@Override
public void getData(Consumer<List<Word>> consumer, Consumer<Throwable> throwable, final String lessonId) {
Disposable disposable = Observable.create(new ObservableOnSubscribe<List<Word>>() {
@Override
public void subscribe(ObservableEmitter<List<Word>> emitter) throws Exception {
List<Word> list;
list = DBManager.getInstance().getFav(lessonId);
if (list == null) {
Log.e(TAG, "list == null");
// emitter.onError(new Exception());//经常报这个错误io.reactivex.exceptions.OnErrorNotImplementedException
} else {
emitter.onNext(list);
}
emitter.onComplete();
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(consumer, throwable);
mCompositeDisposable.add(disposable);
}
use of io.reactivex.ObservableOnSubscribe in project MyJapanese by 54wall.
the class GojuonFragmentModelImpl method getData.
@Override
public void getData(final int category, Consumer<List<GojuonItem>> consumer) {
Disposable disposable = Observable.create(new ObservableOnSubscribe<List<GojuonItem>>() {
@Override
public void subscribe(ObservableEmitter<List<GojuonItem>> emitter) throws Exception {
List<GojuonItem> list;
switch(category) {
case Constants.CATEGORY_QINGYIN:
list = DBManager.getInstance().getQingYin();
break;
case Constants.CATEGORY_ZHUOYIN:
list = DBManager.getInstance().getZhuoYin();
break;
case Constants.CATEGORY_AOYIN:
list = DBManager.getInstance().getAoYin();
break;
default:
list = null;
break;
}
if (list == null) {
emitter.onError(new Exception());
} else {
emitter.onNext(list);
}
emitter.onComplete();
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(consumer);
mCompositeDisposable.add(disposable);
}
use of io.reactivex.ObservableOnSubscribe in project LiYuJapanese by 54wall.
the class PixivIllustFragmentModelImpl method getIllusts.
@Override
public void getIllusts(final String mode, Consumer<List<PixivIllustBean>> consumer) {
Disposable disposable = Observable.create(new ObservableOnSubscribe<List<PixivIllustBean>>() {
@Override
public void subscribe(final ObservableEmitter<List<PixivIllustBean>> emitter) throws Exception {
service.getIllusts(mode, new Consumer<ResponseBody>() {
@Override
public void accept(ResponseBody responseBody) throws Exception {
List<PixivIllustBean> list = handleResponseBody(responseBody);
if (list == null) {
emitter.onError(new Exception());
} else {
emitter.onNext(list);
}
}
});
emitter.onComplete();
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(consumer);
mCompositeDisposable.add(disposable);
}
use of io.reactivex.ObservableOnSubscribe in project EnableHands by LeviWGG.
the class ScanQRCodeFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 101) {
if (RESULT_OK != resultCode)
return;
if (data == null)
return;
Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
Uri uri = data.getData();
String result = null;
ContentResolver cr = getActivity().getContentResolver();
try {
Bitmap bmp = BitmapFactory.decodeStream(cr.openInputStream(uri));
result = QRCodeDecoder.syncDecodeQRCode(bmp);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
emitter.onNext(result);
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
Bundle bundle = new Bundle();
bundle.putString("QRCODE", s);
setFragmentResult(RESULT_OK, bundle);
pop();
}
});
}
}
use of io.reactivex.ObservableOnSubscribe in project Offer by woshiyizhijiao.
the class RxJavaActivity method zip1.
/**
* zip操作符
* 将上游的两个管道按顺序合并,合并的最终长度为管道事件最少的的管道。默认是在同一个线程中完成,想要同时进行,需要设置Schedulers.io()
*/
public void zip1(View v) {
Observable observable1 = Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
emitter.onNext(1);
LogUtils.e("onNext 1");
emitter.onNext(2);
LogUtils.e("onNext 2");
emitter.onNext(3);
LogUtils.e("onNext 3");
emitter.onNext(4);
LogUtils.e("onNext 4");
emitter.onComplete();
LogUtils.e("onComplete 1");
}
}).subscribeOn(Schedulers.io());
Observable observable2 = Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
emitter.onNext("A");
LogUtils.e("onNext A");
emitter.onNext("B");
LogUtils.e("onNext B");
emitter.onNext("C");
LogUtils.e("onNext C");
emitter.onComplete();
LogUtils.e("onComplete 2");
}
}).subscribeOn(Schedulers.io());
Observable.zip(observable1, observable2, new BiFunction<Integer, String, String>() {
@Override
public String apply(Integer integer, String s) throws Exception {
return integer + s;
}
}).subscribe(new Observer() {
@Override
public void onSubscribe(Disposable d) {
LogUtils.e("onSubscribe");
}
@Override
public void onNext(Object value) {
LogUtils.e("onNext : " + value);
}
@Override
public void onError(Throwable e) {
LogUtils.e("onError : ");
}
@Override
public void onComplete() {
LogUtils.e("onComplete : ");
}
});
}
Aggregations