package xyz.zimuju.reader.adapter;

import android.view.View;
import android.view.ViewGroup;

import xyz.zimuju.basekit.util.ScreenUtils;
import xyz.zimuju.reader.R;
import xyz.zimuju.reader.base.BaseRecyclerViewAdapter;
import xyz.zimuju.reader.base.BaseRecyclerViewHolder;
import xyz.zimuju.reader.databinding.ItemWelfareBinding;
import xyz.zimuju.reader.entity.common.GankBean;

/**
 * Created by cloud on 2016/12/1.
 */

public class WelfareAdapter extends BaseRecyclerViewAdapter<GankBean> {
    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(parent, R.layout.item_welfare);
    }


    private class ViewHolder extends BaseRecyclerViewHolder<GankBean, ItemWelfareBinding> {


        ViewHolder(ViewGroup viewGroup, int layoutId) {
            super(viewGroup, layoutId);
        }

        @Override
        public void onBindViewHolder(final GankBean resultsBean, final int position) {
            /**
             * 注意：DensityUtil.setViewMargin(itemView,true,5,3,5,0);
             * 如果这样使用，则每个item的左右边距是不一样的，
             * 这样item不能复用，所以下拉刷新成功后显示会闪一下
             * 换成每个item设置上下左右边距是一样的话，系统就会复用，就消除了图片不能复用 闪跳的情况
             */
            if (position % 2 == 0) {
                ScreenUtils.setViewMargin(itemView, false, 12, 6, 12, 0);
            } else {
                ScreenUtils.setViewMargin(itemView, false, 6, 12, 12, 0);
            }
            binding.setBean(resultsBean);
            // 仿抖动
            binding.executePendingBindings();
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (listener != null) {
                        listener.onClick(resultsBean, position);
                    }
                }
            });

//            binding.ivWelfare.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    ArrayList<String> imageuri = new ArrayList<String>();
//                    imageuri.add(resultsBean.getUrl());
//                    Bundle bundle = new Bundle();
//                    bundle.putInt("selet", 1);// 2,大图显示当前页数，1,头像，不显示页数
//                    bundle.putInt("code", 0);//第几张
//                    bundle.putStringArrayList("imageuri", imageuri);
//                    Intent intent = new Intent(v.getContext(), ViewBigImageActivity.class);
//                    intent.putExtras(bundle);
//                    v.getContext().startActivity(intent);
//                }
//            });
        }
    }
}
