package com.sipai.jspatrol.Patrol;

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

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sipai.jspatrol.Bean.FileForDL;
import com.sipai.jspatrol.R;

import java.util.List;

/**
 * created by lvliming on 2019/12/28
 */
public class FileForDLAdapter extends RecyclerView.Adapter<FileForDLAdapter.ViewHolder> {
    private Context context;
    private List<FileForDL> list;
    private onRcViewItemClick mOnRvItemClick;

    public FileForDLAdapter(Context context, List<FileForDL> list, onRcViewItemClick mOnRvItemClick) {
        this.context = context;
        this.list = list;
        this.mOnRvItemClick = mOnRvItemClick;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_file_for_dl,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        FileForDL item = list.get(position);
        holder.tv_name.setText(item.getName());
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        View tview;
        TextView tv_name;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tview = itemView;
            tv_name = itemView.findViewById(R.id.moudle_item_file_for_dl_tv_name);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            if (mOnRvItemClick!=null){
                mOnRvItemClick.onItemClick(view,getAdapterPosition());
            }
        }
    }

    public interface onRcViewItemClick{
        void onItemClick(View v, int position);
    }
}
