package com.wasu.cs.adapter;

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.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 ChildrenDetailRecommendAdapter extends BaseFocusRecyclerViewAdapter<ChildrenDetailRecommendAdapter.listEntey> {

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



    public ChildrenDetailRecommendAdapter(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_children_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, (int) context.getResources().getDimension(R.dimen.d_7dp));
            ((MyViewHolder)holder).name.setText(getItemData(position).getName());
        }
    }

    public class MyViewHolder extends BaseFocusRecyclerViewHolder {
        View view;
        ImageView 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 = (ImageView) 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;
        }
    }
}


