Search in sources :

Example 1 with Callback

use of retrofit.Callback in project glasquare by davidvavra.

the class VenueListActivity method searchVenues.

private void searchVenues(String ll) {
    Callback<ExploreVenues.ExploreVenuesResponse> callback = new Callback<ExploreVenues.ExploreVenuesResponse>() {

        @Override
        public void success(ExploreVenues.ExploreVenuesResponse exploreVenuesResponse, Response response) {
            if (exploreVenuesResponse.getVenues().size() == 0) {
                showError(R.string.no_venues_found);
            } else {
                showContent(new VenuesAdapter(exploreVenuesResponse.getVenues()), new CardSelectedListener() {

                    @Override
                    public void onCardSelected(Object item) {
                        mSelectedVenue = (ExploreVenues.Venue) item;
                        openOptionsMenu();
                    }
                });
            }
        }

        @Override
        public void failure(RetrofitError retrofitError) {
            showError(R.string.error_please_try_again);
            DebugLog.e(retrofitError);
        }
    };
    int type = getIntent().getIntExtra(EXTRA_TYPE, TYPE_EXPLORE);
    switch(type) {
        case TYPE_EXPLORE:
            Api.get().create(ExploreVenues.class).best(ll, callback);
            break;
        case TYPE_SEARCH:
            String query = getIntent().getStringExtra(EXTRA_QUERY);
            Api.get().create(ExploreVenues.class).search(ll, query, callback);
            break;
    }
}
Also used : Response(retrofit.client.Response) Callback(retrofit.Callback) VenuesAdapter(cz.destil.glasquare.adapter.VenuesAdapter) ExploreVenues(cz.destil.glasquare.api.ExploreVenues) RetrofitError(retrofit.RetrofitError)

Example 2 with Callback

use of retrofit.Callback in project nmid-headline by miao1007.

the class ImagesFeedAdapter method disPatchOnClick.

private void disPatchOnClick(final StreamViewHolder viewHolder, final int position, final ImageInfo imageInfo) {
    viewHolder.mBtn_like.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            RetrofitUtils.getCachedAdapter(HeadlineService.END_POINT).create(ImageService.class).likeImage(knoImageList.get(position).getIdmember(), imageInfo.isHaveClickLike() ? 0 : 1).enqueue(new Callback<ImageLikeResult>() {

                @Override
                public void onResponse(Response<ImageLikeResult> response) {
                    if (response.body().status == 1) {
                        RetrofitUtils.disMsg(v.getContext(), !imageInfo.isHaveClickLike() ? "Success!" : "取消成功");
                        int currentLike = imageInfo.getCount_like() + (imageInfo.isHaveClickLike() ? (0) : (1));
                        viewHolder.likesCount.setText(currentLike + "人 觉得赞");
                        updateHeartButton(viewHolder, true, !imageInfo.isHaveClickLike());
                        imageInfo.setIsLike(!imageInfo.isHaveClickLike());
                    }
                }

                @Override
                public void onFailure(Throwable t) {
                }
            });
        }
    });
    viewHolder.mIv_stream_previous.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(v.getContext(), PhotoViewActivity.class);
            intent.putExtra(PhotoViewActivity.IMAGE_SIEZ_FULL, imageInfo.getImageurl());
            intent.putExtra(PhotoViewActivity.IMAGE_SIEZ_PREVIOUS, imageInfo.getPrevirousurl());
            v.getContext().startActivity(intent);
        }
    });
}
Also used : Response(retrofit.Response) PhotoViewActivity(cn.edu.cqupt.nmid.headline.ui.activity.PhotoViewActivity) Callback(retrofit.Callback) Intent(android.content.Intent) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) View(android.view.View) CardView(android.support.v7.widget.CardView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ImageService(cn.edu.cqupt.nmid.headline.support.repository.image.ImageService)

Example 3 with Callback

use of retrofit.Callback in project glasquare by davidvavra.

the class CheckInSearchActivity method loadData.

@Override
protected void loadData() {
    showProgress(R.string.loading);
    LocationUtils.getRecentLocation(new LocationUtils.LocationListener() {

        @Override
        public void onLocationAcquired(Location location) {
            String ll = LocationUtils.getLatLon(location);
            Api.get().create(SearchVenues.class).searchForCheckIn(ll, new Callback<SearchVenues.SearchResponse>() {

                @Override
                public void success(SearchVenues.SearchResponse venuesResponse, Response response) {
                    showContent(new CheckInSearchAdapter(venuesResponse.getVenues()), new CardSelectedListener() {

                        @Override
                        public void onCardSelected(Object item) {
                            SearchVenues.Venue venue = (SearchVenues.Venue) item;
                            CheckInActivity.call(CheckInSearchActivity.this, venue.id, venue.name);
                        }
                    });
                }

                @Override
                public void failure(RetrofitError retrofitError) {
                    showError(R.string.error_please_try_again);
                }
            });
        }

        @Override
        public void onLocationFailed() {
            showError(R.string.no_location);
        }
    });
}
Also used : LocationUtils(cz.destil.glasquare.util.LocationUtils) SearchVenues(cz.destil.glasquare.api.SearchVenues) Response(retrofit.client.Response) CheckInSearchAdapter(cz.destil.glasquare.adapter.CheckInSearchAdapter) Callback(retrofit.Callback) Location(android.location.Location) RetrofitError(retrofit.RetrofitError)

Example 4 with Callback

use of retrofit.Callback in project retrofit-examples by kdubb1337.

the class AsynchronousClient method main.

public static void main(String[] args) {
    // Build the Retrofit REST adaptor pointing to the URL specified
    // with a ThrottlingInterceptor allowing only 1 request per second
    RestAdapter restAdapter = new RestAdapter.Builder().setRequestInterceptor(new ThrottlingInterceptor(1000L)).setServer(API_URL).build();
    // Create an instance of our InterestingApi interface.
    InterestingApi synchronousApi = restAdapter.create(InterestingApi.class);
    // Create an instance of our AsynchronousApi interface.
    AsynchronousApi asyncApi = restAdapter.create(AsynchronousApi.class);
    for (int i = 0; i < 10; i++) LOG.info("synchronousApi " + synchronousApi.getWithPath(Integer.toString(i)));
    for (int i = 0; i < 10; i++) asyncApi.getWithPath(Integer.toString(i), new Callback<String>() {

        @Override
        public void success(String t, Response response) {
            LOG.info("asynchronousApi (" + t + ")");
        }

        @Override
        public void failure(RetrofitError error) {
            LOG.info("Epic fail!");
        }
    });
}
Also used : Response(retrofit.client.Response) Callback(retrofit.Callback) AsynchronousApi(com.kdubb.retrofitexamples.api.AsynchronousApi) RestAdapter(retrofit.RestAdapter) InterestingApi(com.kdubb.retrofitexamples.api.InterestingApi) RetrofitError(retrofit.RetrofitError)

Aggregations

Callback (retrofit.Callback)4 RetrofitError (retrofit.RetrofitError)3 Response (retrofit.client.Response)3 Intent (android.content.Intent)1 Location (android.location.Location)1 CardView (android.support.v7.widget.CardView)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 ImageService (cn.edu.cqupt.nmid.headline.support.repository.image.ImageService)1 PhotoViewActivity (cn.edu.cqupt.nmid.headline.ui.activity.PhotoViewActivity)1 AsynchronousApi (com.kdubb.retrofitexamples.api.AsynchronousApi)1 InterestingApi (com.kdubb.retrofitexamples.api.InterestingApi)1 CheckInSearchAdapter (cz.destil.glasquare.adapter.CheckInSearchAdapter)1 VenuesAdapter (cz.destil.glasquare.adapter.VenuesAdapter)1 ExploreVenues (cz.destil.glasquare.api.ExploreVenues)1 SearchVenues (cz.destil.glasquare.api.SearchVenues)1 LocationUtils (cz.destil.glasquare.util.LocationUtils)1