use of io.reactivex.ObservableOnSubscribe in project ManPinAPP by AnyMarvel.
the class SearchPresenterImpl method insertSearchHistory.
@Override
public void insertSearchHistory() {
final int type = SearchPresenterImpl.BOOK;
final String content = mView.getEdtContent().getText().toString().trim();
Observable.create(new ObservableOnSubscribe<SearchHistoryBean>() {
@Override
public void subscribe(ObservableEmitter<SearchHistoryBean> e) throws Exception {
List<SearchHistoryBean> datas = DaoDbHelper.getInstance().getSession().getSearchHistoryBeanDao().queryBuilder().where(SearchHistoryBeanDao.Properties.Type.eq(type), SearchHistoryBeanDao.Properties.Content.eq(content)).limit(1).build().list();
SearchHistoryBean searchHistoryBean = null;
if (null != datas && datas.size() > 0) {
searchHistoryBean = datas.get(0);
searchHistoryBean.setDate(System.currentTimeMillis());
DaoDbHelper.getInstance().getSession().getSearchHistoryBeanDao().update(searchHistoryBean);
} else {
searchHistoryBean = new SearchHistoryBean(type, content, System.currentTimeMillis());
DaoDbHelper.getInstance().getSession().getSearchHistoryBeanDao().insert(searchHistoryBean);
}
e.onNext(searchHistoryBean);
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SimpleObserver<SearchHistoryBean>() {
@Override
public void onNext(SearchHistoryBean value) {
mView.insertSearchHistorySuccess(value);
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
});
}
use of io.reactivex.ObservableOnSubscribe in project ManPinAPP by AnyMarvel.
the class BookDetailPresenterImpl method getBookShelfInfo.
@Override
public void getBookShelfInfo() {
CollBookBean collBookInfo = new CollBookBean().getCollBookBeanFromSearch(searchBook);
// 图书详情是否使用本地数据获取,本地数据会导致爬虫数据失效
boolean UseLocalData = !"noimage".equals(collBookInfo.getCover()) && !TextUtils.isEmpty(collBookInfo.getBookChapterUrl());
if (UseLocalData) {
CollBookBean localCollBookBean = BookRepository.getInstance().getSession().getCollBookBeanDao().queryBuilder().where(CollBookBeanDao.Properties._id.eq(collBookInfo.get_id())).build().unique();
if (localCollBookBean != null) {
inBookShelf = true;
}
collBookBean = collBookInfo;
mView.updateView();
} else {
Observable.create(new ObservableOnSubscribe<CollBookBean>() {
@Override
public void subscribe(ObservableEmitter<CollBookBean> emitter) throws Exception {
emitter.onNext(collBookInfo);
}
}).flatMap(new Function<CollBookBean, ObservableSource<CollBookBean>>() {
@Override
public ObservableSource<CollBookBean> apply(CollBookBean collBookBean) throws Exception {
return WebBookModelControl.getInstance().getBookInfo(collBookBean);
}
}).subscribeOn(Schedulers.io()).compose(((BaseActivity) mView.getContext()).<CollBookBean>bindUntilEvent(ActivityEvent.DESTROY)).observeOn(AndroidSchedulers.mainThread()).subscribe(new SimpleObserver<CollBookBean>() {
@Override
public void onNext(CollBookBean value) {
CollBookBean localCollBookBean = BookRepository.getInstance().getSession().getCollBookBeanDao().queryBuilder().where(CollBookBeanDao.Properties._id.eq(value.get_id())).build().unique();
if (localCollBookBean != null) {
inBookShelf = true;
}
collBookBean = value;
mView.updateView();
}
@Override
public void onError(Throwable e) {
collBookBean = null;
mView.getBookShelfError();
}
});
}
}
use of io.reactivex.ObservableOnSubscribe in project WorkHelperApp by hubme.
the class RxJavaSampleFragment method testMerge.
public void testMerge() {
Observable o1 = Observable.create((ObservableOnSubscribe<Integer>) e -> new Thread(() -> {
SystemClock.sleep(1000);
e.onNext(1);
e.onComplete();
}).start());
Observable o2 = Observable.create((ObservableOnSubscribe<Integer>) e -> {
e.onNext(2);
e.onComplete();
});
Observable.merge(o1, o2).subscribe(new Consumer<Integer>() {
@Override
public void accept(@NonNull Integer o) throws Exception {
Log.i("aaa", o.toString());
}
});
}
use of io.reactivex.ObservableOnSubscribe in project Android-Video-Trimmer by iknow4.
the class VideoRxJavaLoader method load.
@SuppressLint("CheckResult")
@Override
public void load(final Context mContext, final SimpleCallback listener) {
Observable.create((ObservableOnSubscribe<Cursor>) emitter -> {
try {
ContentResolver contentResolver = mContext.getContentResolver();
Cursor cursors = contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, MEDIA_PROJECTION, SELECTION, null, ORDER_BY);
emitter.onNext(cursors);
} catch (Throwable t) {
emitter.onError(t);
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(cursors -> {
if (listener != null)
listener.success(cursors);
}, throwable -> Log.e("jason", throwable.getMessage()));
}
Aggregations