retrofit2.adapter.rxjava.Result Java Examples
The following examples show how to use
retrofit2.adapter.rxjava.Result.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RxJavaCallAdapterFactory.java From likequanmintv with Apache License 2.0 | 6 votes |
@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; }
Example #2
Source File: TrendingView.java From u2020 with Apache License 2.0 | 6 votes |
@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(); }
Example #3
Source File: MockGalleryService.java From u2020-mvp with Apache License 2.0 | 6 votes |
@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)))); }
Example #4
Source File: TrendingView.java From u2020 with Apache License 2.0 | 5 votes |
@Override public void call(Result<RepositoriesResponse> result) { if (result.isError()) { Timber.e(result.error(), "Failed to get trending repositories"); } else { Response<RepositoriesResponse> response = result.response(); Timber.e("Failed to get trending repositories. Server returned %d", response.code()); } swipeRefreshView.setRefreshing(false); animatorView.setDisplayedChildId(R.id.trending_error); }
Example #5
Source File: TrendingView.java From u2020 with Apache License 2.0 | 5 votes |
@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()); }
Example #6
Source File: RetroResults.java From okuki with Apache License 2.0 | 5 votes |
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); } } }; }
Example #7
Source File: Results.java From u2020-mvp with Apache License 2.0 | 4 votes |
public static Func1<Result<?>, Boolean> isSuccess() { return SUCCESS; }
Example #8
Source File: GithubService.java From u2020 with Apache License 2.0 | 4 votes |
@GET("search/repositories") // Observable<Result<RepositoriesResponse>> repositories( // @Query("q") SearchQuery query, // @Query("sort") Sort sort, // @Query("order") Order order);
Example #9
Source File: Results.java From u2020 with Apache License 2.0 | 4 votes |
public static Func1<Result<?>, Boolean> isSuccessful() { return SUCCESSFUL; }
Example #10
Source File: SearchResultToRepositoryList.java From u2020 with Apache License 2.0 | 4 votes |
@Override public List<Repository> call(Result<RepositoriesResponse> result) { RepositoriesResponse repositoriesResponse = result.response().body(); return repositoriesResponse.items == null // ? Collections.<Repository>emptyList() // : repositoriesResponse.items; }
Example #11
Source File: MockImageService.java From u2020-mvp with Apache License 2.0 | 4 votes |
@Override public Observable<Result<ImageResponse>> image(@Path("id") String id) { return Observable.just(Result.response(Response.success(serverDatabase.getImageForId(id)))); }
Example #12
Source File: ImageService.java From u2020-mvp with Apache License 2.0 | 4 votes |
@GET("image/{id}") Observable<Result<ImageResponse>> image(@Path("id") String id);
Example #13
Source File: GalleryService.java From u2020-mvp with Apache License 2.0 | 4 votes |
@GET("gallery/{section}/{sort}/{page}") Observable<Result<Gallery>> listGallery(@Path("section") Section section, @Path("sort") Sort sort, @Path("page") int page);
Example #14
Source File: GalleryToImageList.java From u2020-mvp with Apache License 2.0 | 4 votes |
@Override public List<Image> call(Result<Gallery> result) { return result.response().body().data; }
Example #15
Source File: ImageResponseToImage.java From u2020-mvp with Apache License 2.0 | 4 votes |
@Override public Image call(Result<ImageResponse> result) { return result.response().body().data; }
Example #16
Source File: GiphyApi.java From okuki with Apache License 2.0 | 4 votes |
@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);
Example #17
Source File: IcndbApi.java From okuki with Apache License 2.0 | 4 votes |
@GET("/jokes/random/{num}") Observable<Result<IcndbResult>> getRandomJokes(@Path("num") int numJokes);