Search in sources :

Example 1 with Review

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;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Review(com.esoxjem.movieguide.Review)

Example 2 with Review

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);
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) Review(com.esoxjem.movieguide.Review)

Aggregations

Review (com.esoxjem.movieguide.Review)2 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1