本文整理汇总了Java中retrofit2.adapter.rxjava.Result类的典型用法代码示例。如果您正苦于以下问题:Java Result类的具体用法?Java Result怎么用?Java Result使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Result类属于retrofit2.adapter.rxjava包,在下文中一共展示了Result类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:a371166028,项目名称:likequanmintv,代码行数:17,代码来源:RxJavaCallAdapterFactory.java
示例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));
}
开发者ID:donglua,项目名称:GitHubClient,代码行数:37,代码来源:TrendingFragment.java
示例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))));
}
开发者ID:LiveTyping,项目名称:u2020-mvp,代码行数:22,代码来源:MockGalleryService.java
示例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();
}
开发者ID:JakeWharton,项目名称:u2020,代码行数:19,代码来源:TrendingView.java
示例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");
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:ResultTest.java
示例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");
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:ResultTest.java
示例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);
}
}
};
}
开发者ID:wongcain,项目名称:okuki,代码行数:15,代码来源:RetroResults.java
示例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
);
开发者ID:savvasdalkitsis,项目名称:Mondo,代码行数:9,代码来源:MondoApi.java
示例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());
}
开发者ID:savvasdalkitsis,项目名称:Mondo,代码行数:14,代码来源:NoOnErrorCachedNetworkCall.java
示例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();
});
}
开发者ID:savvasdalkitsis,项目名称:Mondo,代码行数:15,代码来源:PreferencesObservableCache.java
示例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")));
}
开发者ID:savvasdalkitsis,项目名称:Mondo,代码行数:12,代码来源:NoOnErrorCachedNetworkCallCacheTest.java
示例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();
}
开发者ID:savvasdalkitsis,项目名称:Mondo,代码行数:11,代码来源:NoOnErrorCachedNetworkCallTest.java
示例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;
}
开发者ID:savvasdalkitsis,项目名称:Mondo,代码行数:10,代码来源:FakeObservableCache.java
示例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));
}
开发者ID:savvasdalkitsis,项目名称:Mondo,代码行数:9,代码来源:FakeMondoApi.java
示例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());
}
开发者ID:donglua,项目名称:GitHubClient,代码行数:9,代码来源:TrendingFragment.java
示例16: onCreate
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_repo_detail);
Injector.obtain(this).inject(this);
String url = getIntent().getData().toString();
Observable<Result<Repository>> result =
mGithubService.repository(url) //
.subscribeOn(Schedulers.io()) //
.observeOn(mainThread()) //
.share();
subscriptions.add( //
result.filter(Results.isSuccess()) //
.map(Result::response) //
.map(Response::body) //
.subscribe(repository -> mBinding.setRepo(repository)));
subscriptions.add(
result.filter(Funcs.not(Results.isSuccess())) //
.map(Result::error) //
.subscribe(throwable -> //
Timber.d(throwable, "repo err"))
);
}
开发者ID:donglua,项目名称:GitHubClient,代码行数:29,代码来源:RepoDetailActivity.java
示例17: 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)
.subscribeOn(Schedulers.io());
}
开发者ID:JakeWharton,项目名称:u2020,代码行数:9,代码来源:TrendingView.java
示例18: getRandomJokes
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@GET("/jokes/random/{num}")
Observable<Result<IcndbResult>> getRandomJokes(@Path("num") int numJokes);
开发者ID:wongcain,项目名称:okuki,代码行数:3,代码来源:IcndbApi.java
示例19: search
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@GET("/v1/gifs/search?api_key=" + PUBLIC_API_KEY)
Observable<Result<SearchResult>> search(@Query("q") String query, @Query("limit") int limit, @Query("offset") int offset);
开发者ID:wongcain,项目名称:okuki,代码行数:3,代码来源:GiphyApi.java
示例20: getBalance
import retrofit2.adapter.rxjava.Result; //导入依赖的package包/类
@GET("balance")
Observable<Result<ApiBalance>> getBalance();
开发者ID:savvasdalkitsis,项目名称:Mondo,代码行数:3,代码来源:MondoApi.java
注:本文中的retrofit2.adapter.rxjava.Result类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论