package com.joker.fourfun.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableStringBuilder;
import android.text.style.AbsoluteSizeSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.joker.fourfun.R;
import com.joker.fourfun.model.Movie;
import com.joker.fourfun.utils.GlideUtil;
import com.joker.fourfun.utils.SystemUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static android.text.Spanned.SPAN_INCLUSIVE_INCLUSIVE;

/**
 * Created by joker on 2016/12/19.
 */
public class MovieAdapter extends RecyclerView.Adapter<MovieAdapter.MovieHolder> {
    private Context mContext;
    private List<Movie> list;

    public MovieAdapter(Context context, List<Movie> list) {
        this.mContext = context;
        this.list = list;
    }

    @Override
    public MovieHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MovieHolder(LayoutInflater.from(mContext).inflate(R.layout
                .fragment_media_movie_item, parent, false));
    }

    @Override
    public void onBindViewHolder(MovieHolder holder, int position) {
        String movieName = list.get(position).getMovieName();
        String briefIntro = list.get(position).getBriefIntro();

        String content = movieName + "\n\n"+ briefIntro;
        SpannableStringBuilder style = new SpannableStringBuilder(content);
        style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(20)), 0, movieName.length(),
                SPAN_INCLUSIVE_INCLUSIVE);
        style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(14)), movieName.length() + 2, content.length
                () - 1, SPAN_INCLUSIVE_INCLUSIVE);
        holder.mTvContent.setText(style);

        GlideUtil.setImage(mContext, list.get(position).getPic(), holder.mIvMovie);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class MovieHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_content)
        TextView mTvContent;
        @BindView(R.id.iv_movie)
        ImageView mIvMovie;

        public MovieHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
@@ -61,16 +61,59 @@
 ontext;%0A
+import android.support.v7.widget.CardView;%0A
 import a
@@ -883,16 +883,56 @@
 e%3E list;
+%0A    private OnClickedListener listener;
 %0A%0A    pu
@@ -1354,16 +1354,22 @@
  holder,
+ final
  int pos
@@ -1547,16 +1547,17 @@
 + %22%5Cn%5Cn%22
+ 
 + briefI
@@ -2061,82 +2061,545 @@
     
-%7D%0A%0A    @Override%0A    public int getItemCount() %7B%0A        return list.size(
+    holder.mCvMovie.setOnClickListener(new View.OnClickListener() %7B%0A            @Override%0A            public void onClick(View v) %7B%0A                if (listener != null) %7B%0A                    listener.click(list.get(position));%0A                %7D%0A            %7D%0A        %7D);%0A    %7D%0A%0A    @Override%0A    public int getItemCount() %7B%0A        return list.size();%0A    %7D%0A%0A    public void setOnClickListener(OnClickedListener listener) %7B%0A        this.listener = listener;%0A    %7D%0A%0A    public interface OnClickedListener %7B%0A        void click(Movie movie
 );%0A 
@@ -2791,16 +2791,76 @@
 IvMovie;
+%0A        @BindView(R.id.cv_movie)%0A        CardView mCvMovie;
 %0A%0A      

add click method