package org.mazhuang.guanggoo.userprofile.replies;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import org.mazhuang.guanggoo.R;
import org.mazhuang.guanggoo.base.FragmentCallBack;
import org.mazhuang.guanggoo.data.entity.Node;
import org.mazhuang.guanggoo.data.entity.Reply;
import org.mazhuang.guanggoo.data.entity.Topic;
import org.sufficientlysecure.htmltextview.HtmlHttpImageGetter;
import org.sufficientlysecure.htmltextview.HtmlTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ReplyListAdapter extends RecyclerView.Adapter<ReplyListAdapter.ViewHolder> {

    private List<Reply> mData;
    private final FragmentCallBack mListener;

    public ReplyListAdapter(FragmentCallBack listener) {
        mListener = listener;
    }

    public void setData(List<Reply> data) {
        if (data == mData) {
            return;
        }

        mData = data;
        notifyDataSetChanged();
    }

    public void addData(List<Reply> data) {
        mData.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_reply_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        holder.mItem = mData.get(position);
        holder.mTitleTextView.setText(mData.get(position).getTopic().getTitle());
        holder.mContentTextView.setHtml(holder.mItem.getContent(), new HtmlHttpImageGetter(holder.mContentTextView));
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    public boolean isFilled() {
        return (mData != null && mData.size() > 0);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public final View mView;
        @BindView(R.id.title) TextView mTitleTextView;
        @BindView(R.id.content) HtmlTextView mContentTextView;
        public Reply mItem;

        public ViewHolder(View view) {
            super(view);
            mView = view;
            ButterKnife.bind(this, view);
        }

        @OnClick({R.id.title})
        public void onClick(View v) {
            if (mListener == null) {
                return;
            }

            switch (v.getId()) {
                case R.id.title:
                    mListener.openPage(mItem.getTopic().getUrl(), mItem.getTopic().getTitle());
                    break;
            }
        }
    }
}

@@ -211,83 +211,16 @@
 get.
-ImageView;%0Aimport android.widget.TextView;%0A%0Aimport com.bumptech.glide.Glide
+TextView
 ;%0A%0Ai
@@ -306,55 +306,8 @@
 ck;%0A
-import org.mazhuang.guanggoo.data.entity.Node;%0A
 impo
@@ -383,70 +383,15 @@
 goo.
-data.entity.Topic;%0Aimport org.sufficientlysecure.htmltextview.
+util.My
 Html
@@ -1585,32 +1585,179 @@
 ().getTitle());%0A
+        MyHtmlHttpImageGetter imageGetter = new MyHtmlHttpImageGetter(holder.mContentTextView);%0A        imageGetter.enableCompressImage(true, 30);%0A
         holder.m
@@ -1811,56 +1811,19 @@
 (), 
-new HtmlHttpImageGetter(holder.mContentTextView)
+imageGetter
 );%0A 

Fix emoji size in user reply list