use of com.esoxjem.movieguide.Review in project MovieGuide by esoxjem.
the class MovieDetailsParser method parseReviews.
public static List<Review> parseReviews(String body) throws JSONException {
ArrayList<Review> reviews = new ArrayList<>(4);
JSONObject response = new JSONObject(body);
if (!response.isNull(RESULTS)) {
JSONArray results = response.getJSONArray(RESULTS);
for (int i = 0; i < results.length(); i++) {
Review review = new Review();
JSONObject reviewJson = results.getJSONObject(i);
if (!reviewJson.isNull(ID)) {
review.setId(reviewJson.getString(ID));
}
if (!reviewJson.isNull(AUTHOR)) {
review.setAuthor(reviewJson.getString(AUTHOR));
}
if (!reviewJson.isNull(CONTENT)) {
review.setContent(reviewJson.getString(CONTENT));
}
if (!reviewJson.isNull(URL)) {
review.setUrl(reviewJson.getString(URL));
}
reviews.add(review);
}
}
return reviews;
}
use of com.esoxjem.movieguide.Review in project MovieGuide by esoxjem.
the class MovieDetailsFragment method showReviews.
@Override
public void showReviews(List<Review> reviews) {
if (reviews.isEmpty()) {
this.reviews.setVisibility(View.GONE);
reviewsContainer.setVisibility(View.GONE);
} else {
this.reviews.setVisibility(View.VISIBLE);
reviewsContainer.setVisibility(View.VISIBLE);
reviewsContainer.removeAllViews();
LayoutInflater inflater = getActivity().getLayoutInflater();
for (Review review : reviews) {
ViewGroup reviewContainer = (ViewGroup) inflater.inflate(R.layout.review, reviewsContainer, false);
TextView reviewAuthor = ButterKnife.findById(reviewContainer, R.id.review_author);
TextView reviewContent = ButterKnife.findById(reviewContainer, R.id.review_content);
reviewAuthor.setText(review.getAuthor());
reviewContent.setText(review.getContent());
reviewContent.setOnClickListener(this);
reviewsContainer.addView(reviewContainer);
}
}
}
Aggregations