当前位置: 首页>>代码示例>>Java>>正文


Java SingleSource类代码示例

本文整理汇总了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);
                        }
                    });
        }
    };
}
 
开发者ID:florent37,项目名称:AndroidMVPresenter,代码行数:18,代码来源:AbstractPresenter.java

示例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);
                    }
                }
            });
}
 
开发者ID:afiqiqmal,项目名称:My-Android-Base-Code,代码行数:27,代码来源:LocationRepository.java

示例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;
      }
    }
  };
}
 
开发者ID:xiaodongw,项目名称:grpc-rx,代码行数:22,代码来源:ClientCallsRx.java

示例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);
                }
            };
        }
    });
}
 
开发者ID:jamieadkins95,项目名称:Roach,代码行数:21,代码来源:Deck.java

示例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();
}
 
开发者ID:jbmlaird,项目名称:DiscogsBrowser,代码行数:17,代码来源:ArtistReleasesTransformer.java

示例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());
    }
  };
}
 
开发者ID:dbof10,项目名称:redux-observable,代码行数:10,代码来源:SchedulerSingleTransformer.java

示例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);
        }
    });
}
 
开发者ID:stuxo,项目名称:REDAndroid,代码行数:15,代码来源:DataManager.java

示例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;
}
 
开发者ID:WaylonBrown,项目名称:LifecycleAwareRx,代码行数:18,代码来源:LifecycleTransformer.java

示例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();
                            }
                        });
    }
 
开发者ID:pranayairan,项目名称:YelpQL,代码行数:35,代码来源:SearchActivity.java

示例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();
                            }
                        });
    }
 
开发者ID:pranayairan,项目名称:YelpQL,代码行数:28,代码来源:BusinessDetailsActivity.java

示例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());
        }
    };
}
 
开发者ID:anad7,项目名称:CleanArchitecture,代码行数:10,代码来源:RxUtils.java

示例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);
        }
    });
}
 
开发者ID:yongjhih,项目名称:rxtasks,代码行数:17,代码来源:RxTask.java

示例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);
                }
            });
}
 
开发者ID:hypeapps,项目名称:black-mirror,代码行数:17,代码来源:LocationDataSource.java

示例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));
    }
  });
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:8,代码来源:SingleTransformerOfClazz.java

示例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));
    }
  });
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:8,代码来源:SingleTransformerOfGenericTypeIndicator.java


注:本文中的io.reactivex.SingleSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。