-
-
Save anonymous/8b5fdc0a986c6deeca21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void fetchLatestPost(final View rootView) | |
{ | |
final RecyclerView personList = (RecyclerView) rootView.findViewById(R.id.personRecycleView); | |
personList.setLayoutManager(new LinearLayoutManager(rootView.getContext())); | |
final List<Post> data = new ArrayList<>(); | |
// data.add(new Post("http://www.androidhive.info/wp-content/uploads/2015/02/android-paypal-integration-php-mysql.jpg", "android")); | |
RestAdapter restAdapter = new RestAdapter.Builder() | |
.setEndpoint(END_POINT) | |
.build(); | |
PostAPI api = restAdapter.create(PostAPI.class); | |
api.getPosts(new Callback<List<Post>>() { | |
@Override | |
public void success(List<Post> posts, Response response) { | |
for (int i = 0; i < posts.size(); i++) { | |
String image; | |
Log.d("POST_SLUG", response.getUrl().toString()); | |
try { | |
Log.d("LOG_author", posts.get(i).author.toString()); | |
Log.d("featured_image", posts.get(i).featured_image.toString()); | |
image = posts.get(i).featured_image.toString(); | |
}catch (Exception e) | |
{ | |
image = "http://cdn01.zoomit.ir/2016/2/de4d1588-df5c-409a-aedc-6ee80f332085.jpg"; | |
Log.d("myerror", e.toString()); | |
} | |
data.add(new Post(image, posts.get(i).title)); | |
Log.d("SIZE_POST", String.valueOf(data.size())); | |
} | |
personList.setAdapter(new PostAdapter(rootView.getContext(), data)); | |
} | |
@Override | |
public void failure (RetrofitError error){ | |
Log.d("END_POINT", END_POINT); | |
Log.d("myapi", error.toString()); | |
} | |
} | |
); | |
Log.d("SIZE_POST", String.valueOf(data.size())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment