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

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

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

import com.zztrapp.zztrapp.databinding.ItemRvIndexChildChildBinding;

import java.util.List;

/**
 * Describe FlexBoxItemAdapter
 * Created by Bby on 2022/6/22
 * Email bby0856@163.com
 */

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

    private Context mContext;
    private OnItemClickListener onItemClickListener;
    private List<String> list;

    public interface OnItemClickListener {
        void onEnterClick(int type);
    }

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


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

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

    @NonNull
    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemRvIndexChildChildBinding binding = ItemRvIndexChildChildBinding.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));
    }

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

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

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