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.TaskExplainInfo;

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

public class TaskExplainAdapter2 extends RecyclerView.Adapter<TaskExplainAdapter2.ViewHolder2> {
    private List<TaskExplainInfo.BodyBean.DataBean> explainList2 = new ArrayList<>();
    private Context context;

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

    public void setExplainList2(List<TaskExplainInfo.BodyBean.DataBean> explainList2) {
        if (explainList2!=null){
            this.explainList2.addAll(explainList2);
            notifyDataSetChanged();
        }
    }

    @NonNull
    @Override
    public ViewHolder2 onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        final View view = LayoutInflater.from(context).inflate(R.layout.task_explain2, parent, false);
        return new ViewHolder2(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder2 holder, int position) {
        holder.tvText.setText(explainList2.get(position).getTitle());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemClick2!=null){
                    mOnItemClick2.onClick2(position);
                }
            }
        });
    }

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

    class ViewHolder2 extends RecyclerView.ViewHolder {
        TextView tvText;

        public ViewHolder2(@NonNull View itemView) {
            super(itemView);
            tvText = itemView.findViewById(R.id.tv_task_explain2);
        }
    }

    public interface OnItemClick2 {
        void onClick2(int pos);
    }

    private TaskExplainAdapter2.OnItemClick2 mOnItemClick2;

    public void setOnItemClick(TaskExplainAdapter2.OnItemClick2 pOnItemClick2) {
        mOnItemClick2 = pOnItemClick2;
    }
}
