package com.wasu.cs.ui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.wasu.frescoimagefetchermodule.FrescoImageFetcherModule;
import com.wasu.widgets.adapter.BaseFocusRecyclerViewAdapter;
import com.wasu.widgets.adapter.BaseFocusRecyclerViewHolder;
import com.wasu.widgets.focuswidget.FocusRecyclerView;

import cn.com.wasu.main.R;

/**
 * Created by chenliang on 2016/10/26.
 * 详情页右边推荐位
 */

public class DetailRecommendAdapter extends BaseFocusRecyclerViewAdapter<DetailRecommendAdapter.listEntey> {

    private final int RECOMMEND_MAXNUM = 10; // 最大的item个数
    private Context context;



    public DetailRecommendAdapter(FocusRecyclerView recyclerView, Context context) {
        super(recyclerView);
        this.context = context;
    }


    /**
     * 创建item view
     *
     * @param parent
     * @param viewType
     * @return
     */
    @Override
    protected BaseFocusRecyclerViewHolder createItem(ViewGroup parent, int viewType) {
        View view  = LayoutInflater.from(context).inflate(R.layout.item_recommend, null);
        MyViewHolder viewHolder = new MyViewHolder(view, getItemParent(), getItemListener());
        return viewHolder;
    }

    @Override
    protected void bindData(BaseFocusRecyclerViewHolder holder, int position) {

        ImageView img = ((MyViewHolder)holder).pic;

        if (getItemData(position) == null) {
            img.setImageResource(R.drawable.default_wasu_bg);
        } else {
            FrescoImageFetcherModule.getInstance().attachImage(
                    getItemData(position).getPicUrl(), img);
            ((MyViewHolder)holder).name.setText(getItemData(position).getName());
        }
    }

    public class MyViewHolder extends BaseFocusRecyclerViewHolder{
        View view;
        SimpleDraweeView pic;
        TextView name;

        /**
         * 创建FocusRecyclerView的itemView
         *
         * @param itemView          item View
         * @param focusRecyclerView item parent ViewGroup(Parent must instanceof FocusRecyclerView)
         * @param mOnItemListener   item click、longClick、focusChange listener
         */
        public MyViewHolder(View itemView, FocusRecyclerView focusRecyclerView, OnItemListener mOnItemListener) {
            super(itemView, focusRecyclerView, mOnItemListener);
            view = itemView;
            pic = (SimpleDraweeView) itemView.findViewById(R.id.ivPic);
            name = (TextView) itemView.findViewById(R.id.name);
        }

        @Override
        protected View getView() {
            return view;
        }
    }




    // recycleview
    public static class listEntey{
        String picUrl;
        String name;

        public listEntey(String picUrl, String name){
            this.picUrl = picUrl;
            this.name = name;
        }

        public String getPicUrl() {
            return picUrl;
        }

        public void setPicUrl(String picUrl) {
            this.picUrl = picUrl;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}


