Search in sources :

Example 26 with ObservableEmitter

use of io.reactivex.ObservableEmitter in project kripton by xcesco.

the class BindKripton180RawInsertSelectDataSource method execute.

public <T> Observable<T> execute(final ObservableTransaction<T> transaction) {
    ObservableOnSubscribe<T> emitter = new ObservableOnSubscribe<T>() {

        @Override
        public void subscribe(ObservableEmitter<T> emitter) {
            boolean needToOpened = !BindKripton180RawInsertSelectDataSource.this.isOpenInWriteMode();
            boolean success = false;
            @SuppressWarnings("resource") SQLiteDatabase connection = needToOpened ? openWritableDatabase() : database();
            DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
            currentDaoFactory.onSessionOpened();
            try {
                connection.beginTransaction();
                if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
                    connection.setTransactionSuccessful();
                    success = true;
                }
                emitter.onComplete();
            } catch (Throwable e) {
                Logger.error(e.getMessage());
                e.printStackTrace();
                emitter.onError(e);
                currentDaoFactory.onSessionClear();
            } finally {
                try {
                    connection.endTransaction();
                } catch (Throwable e) {
                }
                if (needToOpened) {
                    close();
                }
                if (success) {
                    currentDaoFactory.onSessionClosed();
                } else {
                    currentDaoFactory.onSessionClear();
                }
            }
            return;
        }
    };
    Observable<T> result = Observable.create(emitter);
    if (globalSubscribeOn != null)
        result.subscribeOn(globalSubscribeOn);
    if (globalObserveOn != null)
        result.observeOn(globalObserveOn);
    return result;
}
Also used : ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 27 with ObservableEmitter

use of io.reactivex.ObservableEmitter in project kripton by xcesco.

the class BindApp0DataSource method execute.

public <T> Observable<T> execute(final ObservableTransaction<T> transaction) {
    ObservableOnSubscribe<T> emitter = new ObservableOnSubscribe<T>() {

        @Override
        public void subscribe(ObservableEmitter<T> emitter) {
            boolean needToOpened = !BindApp0DataSource.this.isOpenInWriteMode();
            boolean success = false;
            @SuppressWarnings("resource") SQLiteDatabase connection = needToOpened ? openWritableDatabase() : database();
            DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
            currentDaoFactory.onSessionOpened();
            try {
                connection.beginTransaction();
                if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
                    connection.setTransactionSuccessful();
                    success = true;
                }
                emitter.onComplete();
            } catch (Throwable e) {
                Logger.error(e.getMessage());
                e.printStackTrace();
                emitter.onError(e);
                currentDaoFactory.onSessionClear();
            } finally {
                try {
                    connection.endTransaction();
                } catch (Throwable e) {
                }
                if (needToOpened) {
                    close();
                }
                if (success) {
                    currentDaoFactory.onSessionClosed();
                } else {
                    currentDaoFactory.onSessionClear();
                }
            }
            return;
        }
    };
    Observable<T> result = Observable.create(emitter);
    if (globalSubscribeOn != null)
        result.subscribeOn(globalSubscribeOn);
    if (globalObserveOn != null)
        result.observeOn(globalObserveOn);
    return result;
}
Also used : ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 28 with ObservableEmitter

use of io.reactivex.ObservableEmitter in project kripton by xcesco.

the class BindXenoDataSource method execute.

public <T> Observable<T> execute(final ObservableTransaction<T> transaction) {
    ObservableOnSubscribe<T> emitter = new ObservableOnSubscribe<T>() {

        @Override
        public void subscribe(ObservableEmitter<T> emitter) {
            boolean needToOpened = !BindXenoDataSource.this.isOpenInWriteMode();
            boolean success = false;
            @SuppressWarnings("resource") SQLiteDatabase connection = needToOpened ? openWritableDatabase() : database();
            DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
            currentDaoFactory.onSessionOpened();
            try {
                connection.beginTransaction();
                if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
                    connection.setTransactionSuccessful();
                    success = true;
                }
                emitter.onComplete();
            } catch (Throwable e) {
                Logger.error(e.getMessage());
                e.printStackTrace();
                emitter.onError(e);
                currentDaoFactory.onSessionClear();
            } finally {
                try {
                    connection.endTransaction();
                } catch (Throwable e) {
                }
                if (needToOpened) {
                    close();
                }
                if (success) {
                    currentDaoFactory.onSessionClosed();
                } else {
                    currentDaoFactory.onSessionClear();
                }
            }
            return;
        }
    };
    Observable<T> result = Observable.create(emitter);
    if (globalSubscribeOn != null)
        result.subscribeOn(globalSubscribeOn);
    if (globalObserveOn != null)
        result.observeOn(globalObserveOn);
    return result;
}
Also used : ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 29 with ObservableEmitter

use of io.reactivex.ObservableEmitter in project My-MVP by REBOOTERS.

the class RxJavaBaseActivity method thread.

private void thread() {
    Observable mObservable = Observable.create(new ObservableOnSubscribe() {

        @Override
        public void subscribe(ObservableEmitter e) throws Exception {
            Log.e(TAG, "subscribe: currentThreadName==" + Thread.currentThread().getName());
            sb.append("\nsubscribe: currentThreadName==" + Thread.currentThread().getName());
            e.onNext("1000");
        }
    });
    Consumer mObserver = new Consumer<String>() {

        @Override
        public void accept(String s) throws Exception {
            Log.e(TAG, "accept: currentThreadName==" + Thread.currentThread().getName());
            Log.e(TAG, "accept: s=" + s);
            sb.append("\naccept: currentThreadName==" + Thread.currentThread().getName());
            logContent.setText(sb.toString());
        }
    };
    mObservable.subscribe(mObserver);
}
Also used : ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Consumer(io.reactivex.functions.Consumer) Observable(io.reactivex.Observable) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 30 with ObservableEmitter

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

Aggregations

ObservableEmitter (io.reactivex.ObservableEmitter)39 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)38 Disposable (io.reactivex.disposables.Disposable)24 IOException (java.io.IOException)7 Observable (io.reactivex.Observable)6 NonNull (io.reactivex.annotations.NonNull)6 File (java.io.File)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Intent (android.content.Intent)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 Consumer (io.reactivex.functions.Consumer)4 Word (pri.weiqiang.liyujapanese.mvp.bean.dic.Word)4 Observer (io.reactivex.Observer)3 Bitmap (android.graphics.Bitmap)2 Uri (android.net.Uri)2 NonNull (android.support.annotation.NonNull)2 OnClick (butterknife.OnClick)2 Progress (com.lzy.okgo.model.Progress)2 FileNotFoundException (java.io.FileNotFoundException)2