package com.navinfo.outdoor.adapter;

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.navinfo.outdoor.R;
import com.navinfo.outdoor.bean.EventPrefectureBean;
import com.navinfo.outdoor.bean.TaskPrefectureBean;

import java.util.ArrayList;
import java.util.List;

public class EventPrefectureAdapter extends RecyclerView.Adapter<EventPrefectureAdapter.ViewHolder> {
        private List<TaskPrefectureBean.BodyBean.ListBean> dataBeans=new ArrayList<>();
    private Context context;

    public EventPrefectureAdapter(Context context) {
        this.context = context;
    }

    public void setDataBeans(List<TaskPrefectureBean.BodyBean.ListBean> dataBeans) {
        this.dataBeans.addAll(dataBeans);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View mView = LayoutInflater.from(context).inflate(R.layout.event_prefecture_item, parent, false);
        return new ViewHolder(mView);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        TaskPrefectureBean.BodyBean.ListBean listBean = dataBeans.get(position);
        holder.tvTitle.setText(listBean.getTitle());
        holder.tvDest.setText(listBean.getSubtitle());
        holder.tvTime.setText(listBean.getCreatetime());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickItem!=null){
                    clickItem.item(listBean.getId());
                }
            }
        });
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvTitle;
        TextView tvDest;
        TextView tvTime;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvTitle=itemView.findViewById(R.id.tv_title);
            tvDest=itemView.findViewById(R.id.tv_dest);
            tvTime=itemView.findViewById(R.id.tv_time);
        }
    }
    clickItem clickItem;

    public void setClickItem(EventPrefectureAdapter.clickItem clickItem) {
        this.clickItem = clickItem;
    }

    public interface clickItem{
        void item(int aInt);
    }
}
