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;
}
}
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);
}
});
}
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);
}
});
}
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!");
}
});
}
Aggregations