Search in sources :

Example 16 with ObservableOnSubscribe

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

Example 17 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe in project LiYuJapanese 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 18 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe in project LiYuJapanese 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 19 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe in project LiYuJapanese 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);
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) GojuonItem(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 20 with ObservableOnSubscribe

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

Aggregations

ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)58 ObservableEmitter (io.reactivex.ObservableEmitter)48 Disposable (io.reactivex.disposables.Disposable)34 Observable (io.reactivex.Observable)13 ArrayList (java.util.ArrayList)12 List (java.util.List)11 SupportSQLiteDatabase (androidx.sqlite.db.SupportSQLiteDatabase)9 File (java.io.File)8 IOException (java.io.IOException)8 Intent (android.content.Intent)6 Bundle (android.os.Bundle)6 Consumer (io.reactivex.functions.Consumer)6 Bitmap (android.graphics.Bitmap)5 Uri (android.net.Uri)5 Observer (io.reactivex.Observer)5 NonNull (io.reactivex.annotations.NonNull)5 HashMap (java.util.HashMap)5 Log (android.util.Log)4 View (android.view.View)4 BindView (butterknife.BindView)4