Search in sources :

Example 1 with RetrofitError

use of retrofit.RetrofitError in project glasquare by davidvavra.

the class CheckInActivity method addPhoto.

private void addPhoto() {
    String checkInId = mCheckInResponse.getCheckInId();
    TypedFile typedFile = new TypedFile("image/jpeg", mPhoto);
    Api.get().create(Photos.class).add(checkInId, typedFile, new Callback<Photos.PhotoAddResponse>() {

        @Override
        public void success(Photos.PhotoAddResponse photoAddResponse, Response response) {
            showCheckInComplete();
        }

        @Override
        public void failure(RetrofitError retrofitError) {
            showCheckInComplete();
        }
    });
}
Also used : Photos(cz.destil.glasquare.api.Photos) Response(retrofit.client.Response) TypedFile(retrofit.mime.TypedFile) RetrofitError(retrofit.RetrofitError)

Example 2 with RetrofitError

use of retrofit.RetrofitError 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 3 with RetrofitError

use of retrofit.RetrofitError in project cw-omnibus by commonsguy.

the class QuestionsFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setLayoutManager(new LinearLayoutManager(getActivity()));
    so.questions("android", new Callback<SOQuestions>() {

        @Override
        public void success(SOQuestions results, Response response) {
            for (Item item : results.items) {
                Question question = new Question(item);
                questions.add(question);
                questionMap.put(question.id, question);
            }
            setAdapter(new QuestionsAdapter(questions));
        }

        @Override
        public void failure(RetrofitError error) {
            onError(error);
        }
    });
}
Also used : Response(retrofit.client.Response) MenuItem(android.view.MenuItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RetrofitError(retrofit.RetrofitError)

Example 4 with RetrofitError

use of retrofit.RetrofitError in project glasquare by davidvavra.

the class CheckInActivity method checkIn.

private void checkIn() {
    final String venueId = getIntent().getStringExtra(EXTRA_VENUE_ID);
    final Location location = LocationUtils.getLastLocation();
    final String ll = LocationUtils.getLatLon(location);
    int accuracy = (int) location.getAccuracy();
    int altitude = (int) location.getAltitude();
    showProgress(R.string.checking_in);
    showCheckInInfo();
    String broadcast = getBroadcast();
    Api.get().create(CheckIns.class).add(venueId, ll, mShout, broadcast, accuracy, altitude, new Callback<CheckIns.CheckInResponse>() {

        @Override
        public void success(final CheckIns.CheckInResponse checkInResponse, Response response) {
            mCheckInResponse = checkInResponse;
            if (mAddingPhoto) {
                ImageUtils.processPictureWhenReady(CheckInActivity.this, mPhoto, new ImageUtils.OnPictureReadyListener() {

                    @Override
                    public void onPictureReady() {
                        new BaseAsyncTask() {

                            @Override
                            public void inBackground() {
                                ImageUtils.resize(mPhoto);
                            }

                            @Override
                            public void postExecute() {
                                addPhoto();
                            }
                        }.start();
                    }
                });
            } else {
                showCheckInComplete();
            }
        }

        @Override
        public void failure(RetrofitError retrofitError) {
            if (!Auth.handle(CheckInActivity.this, retrofitError)) {
                showError(R.string.error_please_try_again);
            }
        }
    });
}
Also used : Response(retrofit.client.Response) CheckIns(cz.destil.glasquare.api.CheckIns) BaseAsyncTask(cz.destil.glasquare.util.BaseAsyncTask) Location(android.location.Location) RetrofitError(retrofit.RetrofitError)

Example 5 with RetrofitError

use of retrofit.RetrofitError 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)

Aggregations

RetrofitError (retrofit.RetrofitError)8 Response (retrofit.client.Response)7 Callback (retrofit.Callback)3 Location (android.location.Location)2 RestAdapter (retrofit.RestAdapter)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 MenuItem (android.view.MenuItem)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 CheckIns (cz.destil.glasquare.api.CheckIns)1 ExploreVenues (cz.destil.glasquare.api.ExploreVenues)1 Photos (cz.destil.glasquare.api.Photos)1 SearchVenues (cz.destil.glasquare.api.SearchVenues)1 BaseAsyncTask (cz.destil.glasquare.util.BaseAsyncTask)1 LocationUtils (cz.destil.glasquare.util.LocationUtils)1 Random (java.util.Random)1 Test (org.junit.Test)1 TypedFile (retrofit.mime.TypedFile)1