use of io.reactivex.ObservableEmitter in project MyJapanese 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.ObservableEmitter in project MyJapanese by 54wall.
the class SplashActivity method initData.
private void initData() {
// 预加载数据库,音频与GIF资源(GIF资源觉得可以放在后边)
Disposable disposable = Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
emitter.onNext(ResourceUtils.getString(SplashActivity.this, R.string.loading_data));
DBManager.getInstance().init();
GifManager.getInstance().init();
// SoundPoolManager.init考虑后续变为异步处理进入五十音图在启动
SoundPoolManager.getInstance().init();
emitter.onNext(ResourceUtils.getString(SplashActivity.this, R.string.loading_data_success));
emitter.onComplete();
// 添加有米广告需要屏蔽下两行代码
// Thread.sleep(1000);
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
mTextView.setText(s);
}
});
addDisposable(disposable);
}
use of io.reactivex.ObservableEmitter in project MyJapanese by 54wall.
the class LessonsFragmentModelImpl method getData.
@Override
public void getData(Consumer<List<Book>> consumer) {
Disposable disposable = Observable.create(new ObservableOnSubscribe<List<Book>>() {
@Override
public void subscribe(ObservableEmitter<List<Book>> emitter) throws Exception {
List<Book> list;
list = DBManager.getInstance().getBooks();
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.ObservableEmitter in project MyJapanese by 54wall.
the class WordsFragmentModelImpl method getData.
@Override
public void getData(Consumer<List<Word>> consumer, final String lesson) {
Disposable disposable = Observable.create(new ObservableOnSubscribe<List<Word>>() {
@Override
public void subscribe(ObservableEmitter<List<Word>> emitter) throws Exception {
List<Word> list = DBManager.getInstance().queryWord(lesson);
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.ObservableEmitter in project RxTools by vondear.
the class RxCameraTool method takePic.
public static void takePic(Context mContext, final RxCameraView mCameraView) {
try {
if (mCameraView.isCameraOpened()) {
RxVibrateTool.vibrateOnce(mContext, 150);
RxToast.normal("正在拍照..");
try {
mCameraView.takePicture();
} catch (Exception var2) {
RxToast.normal("你碰到问题咯");
}
} else {
mCameraView.start();
RxVibrateTool.vibrateOnce(mContext, 150);
RxToast.normal("正在拍照..");
Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(@NonNull ObservableEmitter<Integer> e) {
// 延时
SystemClock.sleep(500);
e.onNext(1);
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Integer>() {
// 第二步:初始化Observer
private Disposable mDisposable;
@Override
public void onSubscribe(@NonNull Disposable d) {
mDisposable = d;
}
@Override
public void onNext(@NonNull Integer integer) {
switch(integer) {
case 1:
try {
mCameraView.takePicture();
} catch (Exception var2) {
RxToast.normal("你碰到问题咯");
}
break;
default:
break;
}
}
@Override
public void onError(@NonNull Throwable e) {
}
@Override
public void onComplete() {
}
});
}
} catch (Exception var3) {
RxToast.normal("你碰到了问题咯");
}
}
Aggregations