Search in sources :

Example 11 with ObservableEmitter

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);
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) ArrayList(java.util.ArrayList) List(java.util.List) PixivIllustBean(pri.weiqiang.liyujapanese.mvp.bean.pixivIllust.PixivIllustBean) ObservableEmitter(io.reactivex.ObservableEmitter) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody)

Example 12 with ObservableEmitter

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);
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Intent(android.content.Intent) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 13 with ObservableEmitter

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);
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Book(pri.weiqiang.liyujapanese.mvp.bean.dic.Book) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 14 with ObservableEmitter

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);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Word(pri.weiqiang.liyujapanese.mvp.bean.dic.Word) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 15 with ObservableEmitter

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("你碰到了问题咯");
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) NonNull(io.reactivex.annotations.NonNull) IOException(java.io.IOException) ObservableEmitter(io.reactivex.ObservableEmitter)

Aggregations

ObservableEmitter (io.reactivex.ObservableEmitter)39 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)38 Disposable (io.reactivex.disposables.Disposable)24 IOException (java.io.IOException)7 Observable (io.reactivex.Observable)6 NonNull (io.reactivex.annotations.NonNull)6 File (java.io.File)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Intent (android.content.Intent)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 Consumer (io.reactivex.functions.Consumer)4 Word (pri.weiqiang.liyujapanese.mvp.bean.dic.Word)4 Observer (io.reactivex.Observer)3 Bitmap (android.graphics.Bitmap)2 Uri (android.net.Uri)2 NonNull (android.support.annotation.NonNull)2 OnClick (butterknife.OnClick)2 Progress (com.lzy.okgo.model.Progress)2 FileNotFoundException (java.io.FileNotFoundException)2