package com.zztrapp.zztrapp.ui.currency.adapter;


import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

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

import com.zztrapp.zztrapp.bean.WdPageListBean;
import com.zztrapp.zztrapp.databinding.ItemRvFaLvFaGuiFileBinding;

import java.util.List;

/**
 * Describe 法律法规File  Adapter
 * Created by Bby on 2022/6/23
 * Email bby0856@163.com
 */

public class FaLvFaGuiFileAdapter extends RecyclerView.Adapter<FaLvFaGuiFileAdapter.ItemHolder> {

    private Context mContext;
    private OnItemClickListener onItemClickListener;
    private List<WdPageListBean.RecordsBean> list;

    public interface OnItemClickListener {
        void onItemClick(String filePath, String fileName, String fileType);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public FaLvFaGuiFileAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(List<WdPageListBean.RecordsBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemRvFaLvFaGuiFileBinding binding = ItemRvFaLvFaGuiFileBinding.inflate(LayoutInflater.from(mContext), parent, false);
        return new ItemHolder(binding);
    }

    @Override
    public void onBindViewHolder(ItemHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.bindings.name.setText(list.get(position).getName());
        holder.bindings.time1.setText("创建时间：" + list.get(position).getUploadTime());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(list.get(position).getFilePath(), list.get(position).getName(), list.get(position).getExtension());
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list != null ? list.size() : 0;
    }

    static class ItemHolder extends RecyclerView.ViewHolder {
        private ItemRvFaLvFaGuiFileBinding bindings;

        public ItemHolder(ItemRvFaLvFaGuiFileBinding binding) {
            super(binding.getRoot());
            bindings = binding;
        }
    }
}