當前位置: 首頁>>代碼示例>>Java>>正文


Java SingleObserver類代碼示例

本文整理匯總了Java中io.reactivex.SingleObserver的典型用法代碼示例。如果您正苦於以下問題:Java SingleObserver類的具體用法?Java SingleObserver怎麽用?Java SingleObserver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SingleObserver類屬於io.reactivex包,在下文中一共展示了SingleObserver類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getObserver

import io.reactivex.SingleObserver; //導入依賴的package包/類
private SingleObserver<Integer> getObserver() {

        return new SingleObserver<Integer>() {
            @Override
            public void onSubscribe(Disposable d) {
                Log.d(TAG, " onSubscribe : " + d.isDisposed());
            }

            @Override
            public void onSuccess(Integer value) {
                textView.append(" onSuccess : value : " + value);
                textView.append(AppConstant.LINE_SEPARATOR);
                Log.d(TAG, " onSuccess : value : " + value);
            }

            @Override
            public void onError(Throwable e) {
                textView.append(" onError : " + e.getMessage());
                textView.append(AppConstant.LINE_SEPARATOR);
                Log.d(TAG, " onError : " + e.getMessage());
            }
        };
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:FlowableExampleActivity.java

示例2: getSingleObserver

import io.reactivex.SingleObserver; //導入依賴的package包/類
private SingleObserver<String> getSingleObserver() {
    return new SingleObserver<String>() {
        @Override
        public void onSubscribe(Disposable d) {
            Log.d(TAG, " onSubscribe : " + d.isDisposed());
        }

        @Override
        public void onSuccess(String value) {
            textView.append(" onNext : value : " + value);
            textView.append(AppConstant.LINE_SEPARATOR);
            Log.d(TAG, " onNext value : " + value);
        }

        @Override
        public void onError(Throwable e) {
            textView.append(" onError : " + e.getMessage());
            textView.append(AppConstant.LINE_SEPARATOR);
            Log.d(TAG, " onError : " + e.getMessage());
        }
    };
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:SingleObserverExampleActivity.java

示例3: getObserver

import io.reactivex.SingleObserver; //導入依賴的package包/類
private SingleObserver<String> getObserver() {
    return new SingleObserver<String>() {

        @Override
        public void onSubscribe(Disposable d) {
            Log.d(TAG, " onSubscribe : " + d.isDisposed());
        }

        @Override
        public void onSuccess(String value) {
            textView.append(" onNext : value : " + value);
            textView.append(AppConstant.LINE_SEPARATOR);
            Log.d(TAG, " onNext value : " + value);
        }


        @Override
        public void onError(Throwable e) {
            textView.append(" onError : " + e.getMessage());
            textView.append(AppConstant.LINE_SEPARATOR);
            Log.d(TAG, " onError : " + e.getMessage());
        }
    };
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:LastOperatorExampleActivity.java

示例4: subscribeActual

import io.reactivex.SingleObserver; //導入依賴的package包/類
@Override
protected void subscribeActual(@NonNull SingleObserver<? super GraphResponse> observer) {
    mObserver = observer;

    GraphRequest request = GraphRequest.newMeRequest(mAccessToken, new GraphRequest.GraphJSONObjectCallback() {
        @Override
        public void onCompleted(JSONObject object, GraphResponse response) {

            if (response.getError() == null) {
                mObserver.onSuccess(response);
            } else {
                mObserver.onError(response.getError().getException());
            }
        }
    });

    Bundle parameters = new Bundle();
    parameters.putString("fields", mFields);
    request.setParameters(parameters);
    request.executeAsync();
}
 
開發者ID:YouClap,項目名稱:RxFacebook,代碼行數:22,代碼來源:RxFacebookGraphRequestSingle.java

示例5: subscribeActual

import io.reactivex.SingleObserver; //導入依賴的package包/類
@Override
protected void subscribeActual(SingleObserver<? super T> observer) {
    ValueSourceDisposable disposable = new ValueSourceDisposable();
    valueSource.addCallbacks(
            result -> {
                try {
                    observer.onSuccess(result);
                } catch (Throwable e) {
                    observer.onError(e);
                }
            },
            ex -> {
                if (!disposable.isDisposed()) {
                    observer.onError(ex);
                }
            }
    );
    observer.onSubscribe(disposable);
}
 
開發者ID:noorulhaq,項目名稱:reactive.loanbroker.system,代碼行數:20,代碼來源:RxJava2FutureUtils.java

示例6: apply

import io.reactivex.SingleObserver; //導入依賴的package包/類
@Override
public SingleObserver<? super T> apply(final SingleObserver<? super T> observer) {
    return new SingleObserver<T>() {
        @Override
        public void onSubscribe(Disposable d) {
            if (subscribedOnce.getAndSet(true)) {
                throw new NullPointerException("You cannot directly subscribe to a gRPC service multiple times " +
                        "concurrently. Use Flowable.share() instead.");
            } else {
                observer.onSubscribe(d);
            }
        }

        @Override
        public void onSuccess(T t) {
            observer.onSuccess(t);
        }

        @Override
        public void onError(Throwable e) {
            observer.onError(e);
        }
    };
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:25,代碼來源:SubscribeOnlyOnceSingleOperator.java

示例7: subscribeOnlyOnceSingleOperatorErrorsWhenMultipleSubscribe

import io.reactivex.SingleObserver; //導入依賴的package包/類
@Test
public void subscribeOnlyOnceSingleOperatorErrorsWhenMultipleSubscribe() {
    SubscribeOnlyOnceSingleOperator<Object> op = new SubscribeOnlyOnceSingleOperator<Object>();
    SingleObserver<Object> innerSub = mock(SingleObserver.class);
    final Disposable disposable = mock(Disposable.class);

    final SingleObserver<Object> outerSub = op.apply(innerSub);

    outerSub.onSubscribe(disposable);
    assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
        @Override
        public void call() {
            outerSub.onSubscribe(disposable);
        }
    })
            .isInstanceOf(NullPointerException.class)
            .hasMessageContaining("cannot directly subscribe to a gRPC service multiple times");

    verify(innerSub, times(1)).onSubscribe(disposable);
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:21,代碼來源:SubscribeOnlyOnceTest.java

示例8: refreshBook

import io.reactivex.SingleObserver; //導入依賴的package包/類
private void refreshBook(){
    RemoteRepository
            .getInstance()
            .getBookDetail(bookId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new SingleObserver<BookDetailBean>() {
                @Override
                public void onSubscribe(Disposable d) {
                    addDisposable(d);
                }

                @Override
                public void onSuccess(BookDetailBean value){
                    mView.finishRefresh(value);
                    mView.complete();
                }

                @Override
                public void onError(Throwable e) {
                    mView.showError();
                }
            });
}
 
開發者ID:newbiechen1024,項目名稱:NovelReader,代碼行數:25,代碼來源:BookDetailPresenter.java

示例9: getSingleSubscriber

import io.reactivex.SingleObserver; //導入依賴的package包/類
protected <E> SingleObserver<E> getSingleSubscriber(final RxSingleSubscriberEvents singleSubscriberEvents) {
    return new SingleObserver<E>() {

        @Override
        public void onSubscribe(@NonNull Disposable d) {
            queueSubscriptionForDisposal(d);
        }

        @Override
        public void onSuccess(E value) {
            singleSubscriberEvents.onSuccess(value);
        }

        @Override
        public void onError(Throwable error) {
            singleSubscriberEvents.onError(error);
        }
    };
}
 
開發者ID:anad7,項目名稱:CleanArchitecture,代碼行數:20,代碼來源:BaseInteractor.java

示例10: renameFile

import io.reactivex.SingleObserver; //導入依賴的package包/類
@Override public void renameFile(int adapterPosition, String value) {
  rename(recordingItems.get(adapterPosition), adapterPosition, value).subscribe(
      new SingleObserver<Integer>() {
        @Override public void onSubscribe(Disposable d) {

        }

        @Override public void onSuccess(Integer position) {
          getAttachedView().notifyListItemChange(position);
        }

        @Override public void onError(Throwable e) {
          getAttachedView().showError(e.getMessage());
        }
      });
}
 
開發者ID:Arjun-sna,項目名稱:Android-AudioRecorder-App,代碼行數:17,代碼來源:PlayListPresenterImpl.java

示例11: subscribeActual

import io.reactivex.SingleObserver; //導入依賴的package包/類
@Override
protected void subscribeActual(SingleObserver<? super T> s) {
    SingleObserver<? super T> observer;
    try {
        observer = ObjectHelper.requireNonNull(s, "Null Observer");
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        // can't call onError because no way to know if a Disposable has been set or not
        // can't call onSubscribe because the call might have set a Disposable already
        RxJavaPlugins.onError(e);

        NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
        npe.initCause(e);
        throw npe;
    }

    source.subscribe(new AttachSingleObserver<>(observer, this.compositeDisposable));
}
 
開發者ID:cp949,項目名稱:DisposableAttach,代碼行數:19,代碼來源:AttachDisposableSingle.java

示例12: getNews

import io.reactivex.SingleObserver; //導入依賴的package包/類
public static void getNews(SingleObserver<List<News.ContentBean>> observer)
{
    service.getNews()
           .subscribeOn(Schedulers.newThread())
           .flatMap(new Function<News, Observable<News.ContentBean>>()
           {
               @Override
               public Observable<News.ContentBean> apply(News news) throws Exception
               {
                   L.e();
                   return Observable.fromIterable(news.getT1348647853363());
               }
           })
           .toList()
           .observeOn(AndroidSchedulers.mainThread())
           .subscribe(observer);
}
 
開發者ID:Ayvytr,項目名稱:EasyAndroid,代碼行數:18,代碼來源:Network.java

示例13: subscribeActual

import io.reactivex.SingleObserver; //導入依賴的package包/類
@Override
protected void subscribeActual(@NonNull SingleObserver<? super T> observer) {
    boolean b;

    try {
        b = condition.getAsBoolean();
    } catch (Throwable ex) {
        EmptyDisposable.error(ex, observer);
        return;
    }

    if (b) {
        then.subscribe(observer);
    } else {
        orElse.subscribe(observer);
    }
}
 
開發者ID:fengzhizi715,項目名稱:RxConditions,代碼行數:18,代碼來源:SingleIfThen.java

示例14: getObserver

import io.reactivex.SingleObserver; //導入依賴的package包/類
private SingleObserver<Long> getObserver() {

        return new SingleObserver<Long>() {
            @Override
            public void onSubscribe(Disposable d) {
                Log.d(TAG, " onSubscribe : " + d.isDisposed());
            }

            @Override
            public void onSuccess(Long value) {
                textView.append(" onSuccess : value : " + value);
                textView.append(AppConstant.LINE_SEPARATOR);
                Log.d(TAG, " onSuccess : value : " + value);
            }

            @Override
            public void onError(Throwable e) {
                textView.append(" onError : " + e.getMessage());
                textView.append(AppConstant.LINE_SEPARATOR);
                Log.d(TAG, " onError : " + e.getMessage());
            }
        };
    }
 
開發者ID:changjiashuai,項目名稱:RxJava2-Android-Sample,代碼行數:24,代碼來源:FlowableExampleActivity.java

示例15: getData

import io.reactivex.SingleObserver; //導入依賴的package包/類
private void getData() {
    Observable.concat(memory, disk, network)
            .first("")
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new SingleObserver<String>() {
                @Override
                public void onSubscribe(Disposable d) {
                    // TODO: 2017/7/5
                }

                @Override
                public void onSuccess(String s) {
                    Log.d(TAG, "onSuccess: " + s);
                }

                @Override
                public void onError(Throwable e) {
                    // TODO: 2017/7/5  
                }
            });
}
 
開發者ID:changjiashuai,項目名稱:RxJava2-Android-Sample,代碼行數:23,代碼來源:SimpleExampleActivity.java


注:本文中的io.reactivex.SingleObserver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。