// Path: app/src/main/java/com/hexforhn/hex/adapter/helper/CommentListManager.java
// public class CommentListManager {
//     private final List<CommentViewModel> mComments;
// 
//     public CommentListManager(List<CommentViewModel> comments) {
//         mComments = comments;
//     }
// 
//     public List<CommentViewModel> getVisibleComments() {
//         List<CommentViewModel> comments = new ArrayList<>();
//         int commentCount = mComments.size();
// 
//         for (int i = 0; i < commentCount; i++) {
//             CommentViewModel comment = mComments.get(i);
// 
//             if (comment.isVisible()) {
//                 comments.add(comment);
//             }
//         }
// 
//         return comments;
//     }
// 
//     public void toggleCommentAtPosition(int position) {
//         CommentViewModel commentToToggle = getVisibleComments().get(position);
//         int commentCount = mComments.size();
// 
//         commentToToggle.toggleCollapsed();
// 
//         int toggledCommentDepth = commentToToggle.getDepth();
//         boolean collapsedState = commentToToggle.isCollapsed();
// 
//         position = mComments.indexOf(commentToToggle);
// 
//         for (int i = position + 1; i < commentCount; i++) {
//             CommentViewModel comment = mComments.get(i);
// 
//             if (comment.getDepth() > toggledCommentDepth) {
//                 comment.setVisible(!collapsedState);
//                 comment.setCollapsed(collapsedState);
//             } else {
//                 break;
//             }
//         }
//     }
// 
// }
// 
// Path: app/src/main/java/com/hexforhn/hex/adapter/helper/TextHelper.java
// public class TextHelper {
// 
//     public static CharSequence removeTrailingNewlinesFromText(CharSequence text) {
//         if (text == null || text.length() < 1) {
//             return "";
//         }
// 
//         if (text.charAt(text.length() - 1) == "\n".charAt(0)) {
//             return removeTrailingNewlinesFromText(text.subSequence(0, text.length() - 1));
//         }
// 
//         return text;
//     }
// }
// 
// Path: app/src/main/java/com/hexforhn/hex/listener/ClickListener.java
// public interface ClickListener {
// 
//     /**
//      * Called when the view is clicked.
//      *
//      * @param v view that is clicked
//      * @param position of the clicked item
//      * @param isLongClick true if long click, false otherwise
//      */
//     void onClick(View v, int position, boolean isLongClick);
// }
// 
// Path: app/src/main/java/com/hexforhn/hex/viewmodel/CommentViewModel.java
// public class CommentViewModel {
// 
//     private final int mCommentCount;
//     private final String mText;
//     private final String mUser;
//     private final int mDepth;
//     private final Date mDate;
//     private Boolean mCollapsed;
//     private boolean mVisible;
// 
//     public CommentViewModel(String user, String text, int depth, int commentCount, Date date) {
//         this.mUser = user;
//         this.mText = text;
//         this.mDepth = depth;
//         this.mCommentCount = commentCount;
//         this.mDate = date;
//         this.mVisible = true;
//         this.mCollapsed = false;
//     }
// 
//     public String getText() {
//         return this.mText;
//     }
// 
//     public String getUser() {
//         return this.mUser;
//     }
// 
//     public int getDepth() {
//         return this.mDepth;
//     }
// 
//     public int getCommentCount() {
//         return this.mCommentCount;
//     }
// 
//     public String getRelativeTime() {
//         return DateUtils.getRelativeTimeSpanString(mDate.getTime(), System.currentTimeMillis(), 0)
//                 .toString();
//     }
// 
//     public boolean isVisible() {
//         return this.mVisible;
//     }
// 
//     public boolean isCollapsed() {
//         return this.mCollapsed;
//     }
// 
//     public void setVisible(boolean visible) {
//         this.mVisible = visible;
//     }
// 
//     public void toggleCollapsed() {
//         this.mCollapsed = !this.mCollapsed;
//     }
// 
//     public void setCollapsed(boolean collapsed) {
//         this.mCollapsed = collapsed;
//     }
// 
// }


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.hexforhn.hex.R;
import com.hexforhn.hex.adapter.helper.CommentListManager;
import com.hexforhn.hex.adapter.helper.TextHelper;
import com.hexforhn.hex.listener.ClickListener;
import com.hexforhn.hex.viewmodel.CommentViewModel;
import java.util.List;
package com.hexforhn.hex.adapter;




public class CommentListAdapter extends RecyclerView.Adapter<ViewHolder> implements ClickListener {

    private final static int INDENT_SIZE = 5;
    private final Context mContext;
    private final CommentListManager mCommentListManager;

    public CommentListAdapter(Context context, List<CommentViewModel> comments) {
        mContext = context;
        mCommentListManager = new CommentListManager(comments);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LinearLayout view = (LinearLayout) LayoutInflater.from(parent.getContext()).inflate(
                R.layout.comment, parent, false);

        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.setClickListener(this);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        CommentViewModel comment = mCommentListManager.getVisibleComments().get(position);
        renderCommentIntoView(comment, holder.mView);
    }

    @Override
    public int getItemCount() {
// Path: app/src/main/java/com/hexforhn/hex/adapter/helper/CommentListManager.java
// public class CommentListManager {
//     private final List<CommentViewModel> mComments;
// 
//     public CommentListManager(List<CommentViewModel> comments) {
//         mComments = comments;
//     }
// 
//     public List<CommentViewModel> getVisibleComments() {
//         List<CommentViewModel> comments = new ArrayList<>();
//         int commentCount = mComments.size();
// 
//         for (int i = 0; i < commentCount; i++) {
//             CommentViewModel comment = mComments.get(i);
// 
//             if (comment.isVisible()) {
//                 comments.add(comment);
//             }
//         }
// 
//         return comments;
//     }
// 
//     public void toggleCommentAtPosition(int position) {
//         CommentViewModel commentToToggle = getVisibleComments().get(position);
//         int commentCount = mComments.size();
// 
//         commentToToggle.toggleCollapsed();
// 
//         int toggledCommentDepth = commentToToggle.getDepth();
//         boolean collapsedState = commentToToggle.isCollapsed();
// 
//         position = mComments.indexOf(commentToToggle);
// 
//         for (int i = position + 1; i < commentCount; i++) {
//             CommentViewModel comment = mComments.get(i);
// 
//             if (comment.getDepth() > toggledCommentDepth) {
//                 comment.setVisible(!collapsedState);
//                 comment.setCollapsed(collapsedState);
//             } else {
//                 break;
//             }
//         }
//     }
// 
// }
// 
// Path: app/src/main/java/com/hexforhn/hex/adapter/helper/TextHelper.java
// public class TextHelper {
// 
//     public static CharSequence removeTrailingNewlinesFromText(CharSequence text) {
//         if (text == null || text.length() < 1) {
//             return "";
//         }
// 
//         if (text.charAt(text.length() - 1) == "\n".charAt(0)) {
//             return removeTrailingNewlinesFromText(text.subSequence(0, text.length() - 1));
//         }
// 
//         return text;
//     }
// }
// 
// Path: app/src/main/java/com/hexforhn/hex/listener/ClickListener.java
// public interface ClickListener {
// 
//     /**
//      * Called when the view is clicked.
//      *
//      * @param v view that is clicked
//      * @param position of the clicked item
//      * @param isLongClick true if long click, false otherwise
//      */
//     void onClick(View v, int position, boolean isLongClick);
// }
// 
// Path: app/src/main/java/com/hexforhn/hex/viewmodel/CommentViewModel.java
// public class CommentViewModel {
// 
//     private final int mCommentCount;
//     private final String mText;
//     private final String mUser;
//     private final int mDepth;
//     private final Date mDate;
//     private Boolean mCollapsed;
//     private boolean mVisible;
// 
//     public CommentViewModel(String user, String text, int depth, int commentCount, Date date) {
//         this.mUser = user;
//         this.mText = text;
//         this.mDepth = depth;
//         this.mCommentCount = commentCount;
//         this.mDate = date;
//         this.mVisible = true;
//         this.mCollapsed = false;
//     }
// 
//     public String getText() {
//         return this.mText;
//     }
// 
//     public String getUser() {
//         return this.mUser;
//     }
// 
//     public int getDepth() {
//         return this.mDepth;
//     }
// 
//     public int getCommentCount() {
//         return this.mCommentCount;
//     }
// 
//     public String getRelativeTime() {
//         return DateUtils.getRelativeTimeSpanString(mDate.getTime(), System.currentTimeMillis(), 0)
//                 .toString();
//     }
// 
//     public boolean isVisible() {
//         return this.mVisible;
//     }
// 
//     public boolean isCollapsed() {
//         return this.mCollapsed;
//     }
// 
//     public void setVisible(boolean visible) {
//         this.mVisible = visible;
//     }
// 
//     public void toggleCollapsed() {
//         this.mCollapsed = !this.mCollapsed;
//     }
// 
//     public void setCollapsed(boolean collapsed) {
//         this.mCollapsed = collapsed;
//     }
// 
// }


// Path: app/src/main/java/com/hexforhn/hex/adapter/CommentListAdapter.java
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.hexforhn.hex.R;
import com.hexforhn.hex.adapter.helper.CommentListManager;
import com.hexforhn.hex.adapter.helper.TextHelper;
import com.hexforhn.hex.listener.ClickListener;
import com.hexforhn.hex.viewmodel.CommentViewModel;
import java.util.List;

package com.hexforhn.hex.adapter;




public class CommentListAdapter extends RecyclerView.Adapter<ViewHolder> implements ClickListener {

    private final static int INDENT_SIZE = 5;
    private final Context mContext;
    private final CommentListManager mCommentListManager;

    public CommentListAdapter(Context context, List<CommentViewModel> comments) {
        mContext = context;
        mCommentListManager = new CommentListManager(comments);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LinearLayout view = (LinearLayout) LayoutInflater.from(parent.getContext()).inflate(
                R.layout.comment, parent, false);

        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.setClickListener(this);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        CommentViewModel comment = mCommentListManager.getVisibleComments().get(position);
        renderCommentIntoView(comment, holder.mView);
    }

    @Override
    public int getItemCount() {
        return mCommentListManager.getVisibleComments().size();