本文整理汇总了Java中io.reactivex.SingleSource类的典型用法代码示例。如果您正苦于以下问题:Java SingleSource类的具体用法?Java SingleSource怎么用?Java SingleSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SingleSource类属于io.reactivex包,在下文中一共展示了SingleSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: composeSingle
import io.reactivex.SingleSource; //导入依赖的package包/类
public <R> SingleTransformer<? super R, ? extends R> composeSingle() {
return new SingleTransformer<R, R>() {
@Override
public SingleSource<R> apply(@NonNull Single<R> upstream) {
return upstream
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retryWhen(new RetryWithDelay(maxRetry, todoBeforeRetry).forSingle)
.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(@NonNull Disposable disposable) throws Exception {
AbstractPresenter.this.addDisposable(disposable);
}
});
}
};
}
示例2: getLocation
import io.reactivex.SingleSource; //导入依赖的package包/类
private Single<Location> getLocation(LocationRequest request) {
if (!shouldRequestNewLocation()) {
return Single.just(mLastLocation);
}
return mFusedLocation.getLocation(request)
.doOnSuccess(new Consumer<Location>() {
@Override
public void accept(Location location) throws Exception {
setLocationCache(location);
}
})
.timeout(LOCATION_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS)
.onErrorResumeNext(new Function<Throwable, SingleSource<? extends Location>>() {
@Override
public SingleSource<? extends Location> apply(Throwable e) throws Exception {
if (e instanceof TimeoutException && mLastLocation == null) {
return Single.error(new LocationTimeoutException());
} else if (mLastLocation == null) {
return Single.error(e);
} else {
return Single.just(mLastLocation);
}
}
});
}
示例3: SingleResponseReceiver
import io.reactivex.SingleSource; //导入依赖的package包/类
public SingleResponseReceiver(ClientCall<?, RespT> call) {
this.call = call;
this.source = new SingleSource<RespT>() {
@Override
public void subscribe(SingleObserver<? super RespT> observer) {
responseObserver = observer;
// todo which disposable should be used here
observer.onSubscribe(Disposables.disposed());
// start call until response gets subscribed
startCall();
if (error != null) {
responseObserver.onError(error);
error = null;
}
}
};
}
示例4: getCardCount
import io.reactivex.SingleSource; //导入依赖的package包/类
@Exclude
private Single<Integer> getCardCount(final String type) {
return Single.defer(new Callable<SingleSource<? extends Integer>>() {
@Override
public SingleSource<? extends Integer> call() throws Exception {
return new Single<Integer>() {
@Override
protected void subscribeActual(SingleObserver<? super Integer> observer) {
int count = 0;
for (String cardId : cardCount.keySet()) {
if (getCards().get(cardId).getType().equals(type)) {
count += cardCount.get(cardId);
}
}
observer.onSuccess(count);
}
};
}
});
}
示例5: apply
import io.reactivex.SingleSource; //导入依赖的package包/类
/**
* Applies the filtered text to the artist releases.
*
* @param upstream {@link Single} containing {@link ArtistRelease}s.
* @return Filtered {@link Single} containing {@link ArtistRelease}s.
*/
@Override
public SingleSource<List<ArtistRelease>> apply(@NonNull Single<List<ArtistRelease>> upstream)
{
return upstream.flattenAsObservable(releases ->
releases)
.filter(artistRelease ->
(artistRelease.getTitle().toLowerCase().contains(filterText)) ||
(artistRelease.getYear().toLowerCase().contains(filterText)))
.toList();
}
示例6: transformer
import io.reactivex.SingleSource; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override public <T> SingleTransformer<T, T> transformer() {
return (SingleTransformer<T, T>) new SingleTransformer() {
@Override public SingleSource apply(Single upstream) {
return upstream.subscribeOn(Schedulers.trampoline())
.observeOn(Schedulers.trampoline());
}
};
}
示例7: getCategories
import io.reactivex.SingleSource; //导入依赖的package包/类
public Single<List<Object>> getCategories() {
return mApiService.forumCategories().flatMap(new Function<ForumCategory, SingleSource<? extends List<Object>>>() {
@Override public SingleSource<? extends List<Object>> apply(ForumCategory forumCategory) {
ArrayList<Object> items = new ArrayList<>();
for (ForumCategory.Categories categories : forumCategory.response.categories) {
items.add(categories.categoryName);
for (ForumCategory.Forums forum : categories.forums) {
items.add(forum);
}
}
return Single.just(items);
}
});
}
示例8: apply
import io.reactivex.SingleSource; //导入依赖的package包/类
/**
* NOTE: This throws a NoSuchElementException if the item is filtered out since a Single can't be empty, so the
* onError is called after onDestroy() when using Single().
*
* @param upstream
* @return
*/
@Override
public SingleSource<T> apply(Single<T> upstream) {
Single<T> transformedStream = upstream
.cache() // Cache to replay emitted values to late subscriber
.filter(filterIfDestroyedPredicate) // Filter to stop emitting items once LifecycleOwner is destroyed
.toSingle();
setReactiveType((R)transformedStream);
return transformedStream;
}
示例9: loadData
import io.reactivex.SingleSource; //导入依赖的package包/类
private void loadData(final String searchTerm, final Location location, final int offsetValue) {
progressbar.setVisibility(View.VISIBLE);
// get the authentication token and find results
AuthenticationTokenUtil.fetchAndUpdateAuthenticationToken(this)
.flatMap(new Function<String, SingleSource<List<Business>>>() {
@Override
public SingleSource<List<Business>> apply(@NonNull String authenticationToken) throws Exception {
return SearchAPI.searchYelp(authenticationToken, searchTerm, location.getLatitude(), location.getLongitude(), offsetValue);
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<List<Business>>() {
@Override
public void accept(@NonNull List<Business> businessList) throws Exception {
progressbar.setVisibility(View.GONE);
if (offsetValue == 0) {
searchAdapter = new SearchAdapter(businessList, SearchActivity.this, SearchActivity.this);
rvNearbyRestaurant.setAdapter(searchAdapter);
} else {
searchAdapter.addBusinessList(businessList);
searchAdapter.notifyDataSetChanged();
}
}
},
new Consumer<Throwable>() {
@Override
public void accept(@NonNull Throwable throwable) throws Exception {
progressbar.setVisibility(View.GONE);
Toast.makeText(SearchActivity.this, "Error " + throwable.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
示例10: loadRestaurantData
import io.reactivex.SingleSource; //导入依赖的package包/类
private void loadRestaurantData(final String businessID, final double latitude, final double longitude) {
progressbar.setVisibility(View.VISIBLE);
AuthenticationTokenUtil.fetchAndUpdateAuthenticationToken(this)
.flatMap(new Function<String, SingleSource<Business>>() {
@Override
public SingleSource<Business> apply(@io.reactivex.annotations.NonNull String authToken) throws Exception {
return BusinessDetailsAPI.getBusinessDetails(authToken, businessID, latitude, longitude);
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Business>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Business business) throws Exception {
progressbar.setVisibility(View.GONE);
bindData(business);
}
}
, new Consumer<Throwable>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Throwable throwable) throws Exception {
progressbar.setVisibility(View.GONE);
Toast.makeText(BusinessDetailsActivity.this, throwable.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
示例11: applyCommonSchedulersSingle
import io.reactivex.SingleSource; //导入依赖的package包/类
public static <T> SingleTransformer<T, T> applyCommonSchedulersSingle() {
return new SingleTransformer<T, T>() {
@Override
public SingleSource<T> apply(@NonNull Single<T> upstream) {
return upstream.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
};
}
示例12: single
import io.reactivex.SingleSource; //导入依赖的package包/类
/**
* @param callable
* @param <R>
* @return
*/
@CheckReturnValue
@NonNull
public static <R> Single<R> single(@NonNull final Callable<Task<R>> callable) {
return Single.fromCallable(callable).flatMap(new Function<Task<R>,
SingleSource<? extends R>>() {
@Override
public SingleSource<? extends R> apply(Task<R> task) throws Exception {
return single(task);
}
});
}
示例13: getTimeZoneByLocationName
import io.reactivex.SingleSource; //导入依赖的package包/类
/**
* Zwraca strefę czasową na podstawie podanej lokalizacji.
@param location Lokalizacja - miasto, kraj, wieś.
*/
@Override
public Single<TimeZone> getTimeZoneByLocationName(String location) {
return googleGeoApi.getCoordForLocation(location, GOOGLE_GEO_API_KEY)
.flatMap(new Function<CoordResponse, SingleSource<? extends TimeZone>>() {
@Override
public SingleSource<? extends TimeZone> apply(@NonNull CoordResponse coordResponse) throws Exception {
String lat = coordResponse.results.get(0).geometry.location.lat.toString();
String lng = coordResponse.results.get(0).geometry.location.lng.toString();
return timeZoneDbApi.getTimeZone(lat, lng, TIME_ZONE_DB_API_KEY);
}
});
}
示例14: apply
import io.reactivex.SingleSource; //导入依赖的package包/类
@Override public SingleSource<Optional<T>> apply(Single<DataSnapshot> upstream) {
return upstream.map(new Function<DataSnapshot, Optional<T>>() {
@Override public Optional<T> apply(DataSnapshot dataSnapshot) throws Exception {
return Optional.of(dataSnapshot.getValue(clazz));
}
});
}
示例15: apply
import io.reactivex.SingleSource; //导入依赖的package包/类
@Override public SingleSource<Optional<T>> apply(Single<DataSnapshot> upstream) {
return upstream.map(new Function<DataSnapshot, Optional<T>>() {
@Override public Optional<T> apply(DataSnapshot dataSnapshot) throws Exception {
return Optional.of(dataSnapshot.getValue(typeIndicator));
}
});
}