// Path: app/src/main/java/com/calgen/prodek/fadflicks/Adapter/ReviewAdapter.java
// public class ReviewAdapter extends ArrayAdapter<Review> {
//     private Context context;
//     private List<Review> reviewList;
//     private boolean glimpse;
// 
//     public ReviewAdapter(Context context, ArrayList<Review> reviewList, boolean glimpse) {
//         super(context, 0, reviewList);
//         this.context = context;
//         this.reviewList = reviewList;
//         this.glimpse = glimpse;
//     }
// 
//     @Override
//     public int getCount() {
//         int size = reviewList.size();
//         int reviewLimit = 3;
//         if (glimpse)
//             return (size > 2) ? reviewLimit : size;
//         else
//             return size;
//     }
// 
//     @NonNull
//     @Override
//     public View getView(int position, View convertView, @NonNull ViewGroup parent) {
// 
//         Review review = reviewList.get(position);
//         ViewHolder viewHolder;
// 
//         if (convertView == null) {
//             LayoutInflater layoutInflater = LayoutInflater.from(context);
//             convertView = layoutInflater.inflate(R.layout.list_item_review, parent, false);
//             viewHolder = new ViewHolder(convertView);
// 
//             convertView.setTag(viewHolder);
//         } else {
//             viewHolder = (ViewHolder) convertView.getTag();
//         }
// 
//         if (glimpse) {
//             viewHolder.reviewText.setMaxLines(3);
//             viewHolder.reviewText.setEllipsize(TextUtils.TruncateAt.END);
//             viewHolder.listItemLayout.setEnabled(false);
//             viewHolder.listItemLayout.setLongClickable(false);
//         }
// 
//         viewHolder.author.setText(review.getAuthor());
//         viewHolder.reviewText.setText(review.getContent());
//         viewHolder.author.setTag(position);
//         viewHolder.reviewText.setTag(position);
//         return convertView;
//     }
// 
//     class ViewHolder {
// 
//         //@formatter:off
//         @BindView(R.id.review_author) public TextView author;
//         @BindView(R.id.review_text) public TextView reviewText;
//         @BindView(R.id.list_item_layout) public LinearLayout listItemLayout;
//         //@formatter:on
// 
//         ViewHolder(View view) {
//             ButterKnife.bind(this, view);
//         }
//     }
// }


import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ListView;
import com.calgen.prodek.fadflicks.adapter.ReviewAdapter;
    public static void setListViewHeightBasedOnChildren(ListView listView) {
        ReviewAdapter listAdapter = (ReviewAdapter) listView.getAdapter();
        if (listAdapter == null) {
            return;
        }

        int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();

        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listView);
            if (listItem instanceof ViewGroup) {
                listItem.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            }
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }
        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(params);
    }

    /**
     * @param context {@link Context} needed to fetch resources
     * @return height of status bar of current device
     */
    public static int getStatusBarHeight(Context context) {
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            return context.getResources().getDimensionPixelSize(resourceId);
        }
// Path: app/src/main/java/com/calgen/prodek/fadflicks/Adapter/ReviewAdapter.java
// public class ReviewAdapter extends ArrayAdapter<Review> {
//     private Context context;
//     private List<Review> reviewList;
//     private boolean glimpse;
// 
//     public ReviewAdapter(Context context, ArrayList<Review> reviewList, boolean glimpse) {
//         super(context, 0, reviewList);
//         this.context = context;
//         this.reviewList = reviewList;
//         this.glimpse = glimpse;
//     }
// 
//     @Override
//     public int getCount() {
//         int size = reviewList.size();
//         int reviewLimit = 3;
//         if (glimpse)
//             return (size > 2) ? reviewLimit : size;
//         else
//             return size;
//     }
// 
//     @NonNull
//     @Override
//     public View getView(int position, View convertView, @NonNull ViewGroup parent) {
// 
//         Review review = reviewList.get(position);
//         ViewHolder viewHolder;
// 
//         if (convertView == null) {
//             LayoutInflater layoutInflater = LayoutInflater.from(context);
//             convertView = layoutInflater.inflate(R.layout.list_item_review, parent, false);
//             viewHolder = new ViewHolder(convertView);
// 
//             convertView.setTag(viewHolder);
//         } else {
//             viewHolder = (ViewHolder) convertView.getTag();
//         }
// 
//         if (glimpse) {
//             viewHolder.reviewText.setMaxLines(3);
//             viewHolder.reviewText.setEllipsize(TextUtils.TruncateAt.END);
//             viewHolder.listItemLayout.setEnabled(false);
//             viewHolder.listItemLayout.setLongClickable(false);
//         }
// 
//         viewHolder.author.setText(review.getAuthor());
//         viewHolder.reviewText.setText(review.getContent());
//         viewHolder.author.setTag(position);
//         viewHolder.reviewText.setTag(position);
//         return convertView;
//     }
// 
//     class ViewHolder {
// 
//         //@formatter:off
//         @BindView(R.id.review_author) public TextView author;
//         @BindView(R.id.review_text) public TextView reviewText;
//         @BindView(R.id.list_item_layout) public LinearLayout listItemLayout;
//         //@formatter:on
// 
//         ViewHolder(View view) {
//             ButterKnife.bind(this, view);
//         }
//     }
// }


// Path: app/src/main/java/com/calgen/prodek/fadflicks/utils/UI.java
import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ListView;
import com.calgen.prodek.fadflicks.adapter.ReviewAdapter;

    public static void setListViewHeightBasedOnChildren(ListView listView) {
        ReviewAdapter listAdapter = (ReviewAdapter) listView.getAdapter();
        if (listAdapter == null) {
            return;
        }

        int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();

        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listView);
            if (listItem instanceof ViewGroup) {
                listItem.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            }
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }
        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(params);
    }

    /**
     * @param context {@link Context} needed to fetch resources
     * @return height of status bar of current device
     */
    public static int getStatusBarHeight(Context context) {
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            return context.getResources().getDimensionPixelSize(resourceId);
        }
        return 0;