本文整理汇总了Java中retrofit2.adapter.rxjava.Result类的典型用法代码示例。如果您正苦于以下问题:Java Result类的具体用法?Java Result怎么用?Java Result使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Result类属于retrofit2.adapter.rxjava包,在下文中一共展示了Result类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: adapt
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@Override public <R> Observable<retrofit2.adapter.rxjava.Result<R>> adapt(Call<R> call) {
Observable<retrofit2.adapter.rxjava.Result<R>> observable = Observable.create(new CallOnSubscribe<>(call)) //
.map(new Func1<Response<R>, retrofit2.adapter.rxjava.Result<R>>() {
@Override public retrofit2.adapter.rxjava.Result<R> call(Response<R> response) {
return retrofit2.adapter.rxjava.Result.response(response);
}
}).onErrorReturn(new Func1<Throwable, retrofit2.adapter.rxjava.Result<R>>() {
@Override public retrofit2.adapter.rxjava.Result<R> call(Throwable throwable) {
return Result.error(throwable);
}
});
if (scheduler != null) {
return observable.subscribeOn(scheduler);
}
return observable;
}
示例2: onCreate
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@Override public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRepositories = new ArrayList<>();
timespanSubject = PublishSubject.create();
Injector.obtain(getContext()).inject(this);
timespanAdapter = new TrendingTimespanAdapter(
new ContextThemeWrapper(getContext(), R.style.Theme_U2020_TrendingTimespan));
repositoryAdapter = new RepositoryAdapter(mRepositories);
repositoryAdapter.setRepositoryClickListener(repository -> {
startActivity(mIntentFactory.createUrlIntent(repository.html_url));
});
Observable<Result<RepositoriesResponse>> result = timespanSubject //
.debounce(300, TimeUnit.MILLISECONDS) //
.flatMap(trendingSearch) //
.observeOn(mainThread()) //
.share();
subscriptions.add(result //
.filter(Results.isSuccess()) //
.map(SearchResultToRepositoryList.instance()) //
.subscribe(repositories -> {
if (page == FRIST_PAGE) mRepositories.clear();
mRepositories.addAll(repositories);
if (binding.trendingListView.getAdapter() == null) {
binding.trendingListView.setAdapter(repositoryAdapter);
}
repositoryAdapter.notifyDataSetChanged();
}));
subscriptions.add(result //
.filter(Funcs.not(Results.isSuccess())) //
.subscribe(trendingError));
}
示例3: listGallery
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@Override
public Observable<Result<Gallery>> listGallery(Section section, Sort sort, int page) {
// Fetch desired section.
List<Image> images = serverDatabase.getImagesForSection(section);
if (images == null) {
return Observable.just(Result.response(Response.success(BAD_REQUEST)));
}
// Figure out proper list subset.
int pageStart = (page - 1) * PAGE_SIZE;
if (pageStart >= images.size() || pageStart < 0) {
return Observable.just(Result.response(Response.success(BAD_REQUEST)));
}
int pageEnd = Math.min(pageStart + PAGE_SIZE, images.size());
// Sort and trim images.
SortUtil.sort(images, sort);
images = images.subList(pageStart, pageEnd);
return Observable.just(Result.response(Response.success(new Gallery(200, true, images))));
}
示例4: onAttachedToWindow
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@Override protected void onAttachedToWindow() {
super.onAttachedToWindow();
Observable<Result<RepositoriesResponse>> result = timespanSubject //
.flatMap(trendingSearch) //
.observeOn(AndroidSchedulers.mainThread()) //
.share();
subscriptions.add(result //
.filter(Results.isSuccessful()) //
.map(SearchResultToRepositoryList.instance()) //
.subscribe(trendingAdapter));
subscriptions.add(result //
.filter(Funcs.not(Results.isSuccessful())) //
.subscribe(trendingError));
// Load the default selection.
onRefresh();
}
示例5: nullResponseThrows
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@Test public void nullResponseThrows() {
try {
Result.response(null);
fail();
} catch (NullPointerException e) {
assertThat(e).hasMessage("response == null");
}
}
示例6: nullErrorThrows
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@Test public void nullErrorThrows() {
try {
Result.error(null);
fail();
} catch (NullPointerException e) {
assertThat(e).hasMessage("error == null");
}
}
示例7: handleResult
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
public static <T> Func1<Result<T>, Observable<T>> handleResult() {
return result -> {
if(result.isError()){
return Observable.error(result.error());
} else {
try {
return Observable.just(result.response().body());
} catch (Throwable t){
Timber.e(t, "Error handling result");
return Observable.error(t);
}
}
};
}
示例8: oAuthToken
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@FormUrlEncoded
@POST("oauth2/token")
Observable<Result<ApiOAuthToken>> oAuthToken(@Field("client_id") String clientId,
@Field("client_secret") String clientSecret,
@Field("code") String code,
@Field("grant_type") String grantType,
@Field("redirect_uri") String redirectUri
);
示例9: withMapper
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@Override
public Observable.Transformer<Result<F>, Response<T>> withMapper(Func1<F, T> mapper, Class<F> itemClass) {
return observable -> observable
.compose(observableCache.on(itemClass))
.map(result -> {
if (!result.isError() && result.response().isSuccessful()) {
return Response.success(mapper.call(result.response().body()));
}
return Response.<T>error();
})
.compose(applyAndroidSchedulers())
.compose(onErrorToErrorResponse());
}
示例10: cachedItems
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
private Observable<Result<T>> cachedItems(Class<T> itemClass) {
return defer(() -> {
String item = mondoPreferences.getStringPreference(getPreferenceKey(itemClass));
if (StringUtils.isNotEmptyNorNull(item)) {
try {
T t = gson.fromJson(item, itemClass);
return just(response(success(t)));
} catch (Exception e) {
Logger.error("ObservableCache", "Error reading cached item", e);
}
}
return empty();
});
}
示例11: usesCache
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@Test
public void usesCache() {
observableCache.emitsSuccessfulResultFor(Integer.class, 1);
Observable.<Result<Integer>>empty()
.compose(call.withMapper(Object::toString, Integer.class))
.subscribe(subscriber);
subscriber.assertFinishedWithItems(sameBeanAs(Response.success("1")));
}
示例12: isExecutedAsynchronously
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@Test
public void isExecutedAsynchronously() {
Semaphore semaphore = new Semaphore(0);
subscribeTo(Observable.<Result<Integer>>create(
subscriber -> {
semaphore.acquireUninterruptibly();
}));
semaphore.release();
}
示例13: getOrCreateSubjectFor
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@NonNull
private ReplaySubject<Result<T>> getOrCreateSubjectFor(Class<T> itemClass) {
if (subjects.get(itemClass) != null) {
return subjects.get(itemClass);
}
ReplaySubject<Result<T>> subject = ReplaySubject.create();
subjects.put(itemClass, subject);
return subject;
}
示例14: oAuthToken
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@Override
public Observable<Result<ApiOAuthToken>> oAuthToken(@Field("client_id") String clientId,
@Field("client_secret") String clientSecret,
@Field("code") String code,
@Field("grant_type") String grantType,
@Field("redirect_uri") String redirectUri) {
return oAuthSubjects.get(keyFor(clientId, clientSecret, code, grantType, redirectUri));
}
示例15: call
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@Override
public Observable<Result<RepositoriesResponse>> call(TrendingTimespan trendingTimespan) {
SearchQuery trendingQuery = new SearchQuery.Builder() //
.createdSince(trendingTimespan.createdSince()) //
.build();
return githubService.repositories(trendingQuery, Sort.STARS, Order.DESC, page)
.subscribeOn(Schedulers.io());
}