Search in sources :

Example 21 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe in project MyJapanese by 54wall.

the class GojuonMemoryFragmentModelImpl method getData.

@Override
public void getData(final int category, Consumer<List<GojuonMemory>> consumer) {
    Disposable disposable = Observable.create(new ObservableOnSubscribe<List<GojuonMemory>>() {

        @Override
        public void subscribe(ObservableEmitter<List<GojuonMemory>> emitter) throws Exception {
            List<GojuonMemory> list;
            switch(category) {
                case Constants.GOJUON_MEMORY:
                    list = DBManager.getInstance().getGojuonMemory();
                    break;
                case Constants.GOJUON_CHENGYU:
                    list = DBManager.getInstance().getGojuonChengyu();
                    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);
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) GojuonMemory(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonMemory) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 22 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe 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 23 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe 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 24 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe 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 25 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe 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)

Aggregations

ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)64 ObservableEmitter (io.reactivex.ObservableEmitter)54 Disposable (io.reactivex.disposables.Disposable)36 Observable (io.reactivex.Observable)14 ArrayList (java.util.ArrayList)12 List (java.util.List)12 File (java.io.File)11 SupportSQLiteDatabase (androidx.sqlite.db.SupportSQLiteDatabase)9 NonNull (io.reactivex.annotations.NonNull)8 IOException (java.io.IOException)8 Intent (android.content.Intent)7 Observer (io.reactivex.Observer)7 Consumer (io.reactivex.functions.Consumer)7 Bitmap (android.graphics.Bitmap)6 Bundle (android.os.Bundle)6 OnClick (butterknife.OnClick)6 Uri (android.net.Uri)5 View (android.view.View)5 BindView (butterknife.BindView)5 HashMap (java.util.HashMap)5