Search in sources :

Example 66 with ObservableOnSubscribe

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();
        }
    });
}
Also used : ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) SearchHistoryBean(com.mp.android.apps.book.bean.SearchHistoryBean) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 67 with ObservableOnSubscribe

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();
            }
        });
    }
}
Also used : ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) CollBookBean(com.mp.android.apps.readActivity.bean.CollBookBean) ObservableSource(io.reactivex.ObservableSource) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 68 with ObservableOnSubscribe

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());
        }
    });
}
Also used : Arrays(java.util.Arrays) AppBaseFragment(com.king.app.workhelper.common.AppBaseFragment) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) OnClick(butterknife.OnClick) R(com.king.app.workhelper.R) BindView(butterknife.BindView) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) Log(android.util.Log) ConnectivityManager(android.net.ConnectivityManager) Student(com.king.app.workhelper.model.entity.Student) Course(com.king.app.workhelper.model.entity.Course) NonNull(io.reactivex.annotations.NonNull) FlowableEmitter(io.reactivex.FlowableEmitter) IntentFilter(android.content.IntentFilter) ObservableEmitter(io.reactivex.ObservableEmitter) BroadcastReceiver(android.content.BroadcastReceiver) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) NumberUtil(com.king.applib.util.NumberUtil) Context(android.content.Context) RxCountDownHelper(com.king.app.workhelper.common.RxCountDownHelper) NetworkUtil(com.king.applib.util.NetworkUtil) Intent(android.content.Intent) SystemClock(android.os.SystemClock) Logger(com.king.applib.log.Logger) Timed(io.reactivex.schedulers.Timed) Flowable(io.reactivex.Flowable) RxView(com.jakewharton.rxbinding2.view.RxView) Observable(io.reactivex.Observable) Subscriber(org.reactivestreams.Subscriber) StringUtil(com.king.applib.util.StringUtil) BackpressureStrategy(io.reactivex.BackpressureStrategy) Action(io.reactivex.functions.Action) Publisher(org.reactivestreams.Publisher) ObservableOperator(io.reactivex.ObservableOperator) RxTextView(com.jakewharton.rxbinding2.widget.RxTextView) Predicate(io.reactivex.functions.Predicate) Consumer(io.reactivex.functions.Consumer) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) FlowableOnSubscribe(io.reactivex.FlowableOnSubscribe) Bitmap(android.graphics.Bitmap) Function(io.reactivex.functions.Function) Subscription(org.reactivestreams.Subscription) Observer(io.reactivex.Observer) AppendOnlyLinkedArrayList(io.reactivex.internal.util.AppendOnlyLinkedArrayList) PublishProcessor(io.reactivex.processors.PublishProcessor) EditText(android.widget.EditText) Observable(io.reactivex.Observable)

Example 69 with ObservableOnSubscribe

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()));
}
Also used : ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver) SuppressLint(android.annotation.SuppressLint)

Aggregations

ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)69 ObservableEmitter (io.reactivex.ObservableEmitter)57 Disposable (io.reactivex.disposables.Disposable)38 Observable (io.reactivex.Observable)15 File (java.io.File)13 ArrayList (java.util.ArrayList)12 List (java.util.List)12 Intent (android.content.Intent)10 NonNull (io.reactivex.annotations.NonNull)10 IOException (java.io.IOException)10 SupportSQLiteDatabase (androidx.sqlite.db.SupportSQLiteDatabase)9 Consumer (io.reactivex.functions.Consumer)8 Bitmap (android.graphics.Bitmap)7 Observer (io.reactivex.Observer)7 Uri (android.net.Uri)6 Bundle (android.os.Bundle)6 OnClick (butterknife.OnClick)6 Log (android.util.Log)5 View (android.view.View)5 BindView (butterknife.BindView)5