package com.lcp.arecyclerview.adapter;

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

import androidx.recyclerview.widget.RecyclerView;

import com.lcp.arecyclerview.R;
import com.lcp.arecyclerview.widget.ARecyclerBaseAdapter;

import java.util.List;

/**
 * Created by Aislli on 2015/12/29.
 */
public class RcGridFallAdapter extends ARecyclerBaseAdapter<RcGridFallAdapter.MyViewHolder, String> {

    public RcGridFallAdapter(Context mContext, List<String> mList) {
        super(mContext, mList);
    }

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

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        holder.idNum.setText(mList.get(position));
        ViewGroup.LayoutParams layoutParams = holder.idNum.getLayoutParams();
        layoutParams.height = (int) (100 + Math.random() * 400);
        holder.idNum.setLayoutParams(layoutParams);
        if (null != onItemClickListener) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(holder.itemView, holder.getLayoutPosition());
                }
            });
        }
        if (null != onItemLongClickListener) {
            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    onItemLongClickListener.onItemLongClick(holder.itemView, holder.getLayoutPosition());
                    return true;
                }
            });
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView idNum;
        View itemView;

        public MyViewHolder(View view) {
            super(view);
            itemView = view;
            idNum = (TextView) view.findViewById(R.id.id_num);
        }
    }

}
