本文整理匯總了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());
}
};
}
示例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());
}
};
}
示例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());
}
};
}
示例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();
}
示例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);
}
示例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);
}
};
}
示例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);
}
示例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();
}
});
}
示例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);
}
};
}
示例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());
}
});
}
示例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));
}
示例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);
}
示例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);
}
}
示例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());
}
};
}
示例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
}
});
}