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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations