package com.stu.assistant.adapter;

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

import com.stu.assistant.R;
import com.stu.assistant.bean.TaskBean;

import java.util.ArrayList;

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

public class TaskAllListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    ArrayList<TaskBean> list1 = new ArrayList<>();
    Context mContext;
    private String userLevel;
    private int itemType;

    public TaskAllListAdapter(Context mContext, ArrayList<TaskBean> list1) {
        this.mContext = mContext;
        this.list1 = list1;
    }


    public void setList(ArrayList<TaskBean> list1) {
        this.list1 = list1;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemViewHodler sectionViewHodler = null;
        sectionViewHodler = new ItemViewHodler(LayoutInflater.from(mContext).inflate(R.layout.table_all_list_item_layout, parent, false), viewType);
        return sectionViewHodler;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        ItemViewHodler itemViewHodler = (ItemViewHodler) holder;
        itemViewHodler.nameTv.setText("课程名称:" + list1.get(position).getTableNameMsg() + "\n截止时间:" + list1.get(position).getTime());
        setOnItem(itemViewHodler.nameTv, position, list1.get(position));
    }

    private void setOnItem(TextView time1Tv, int position, TaskBean TaskBean) {
        time1Tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listeners.itemBean(position, TaskBean);
            }
        });
    }

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

    public class ItemViewHodler extends RecyclerView.ViewHolder {

        public TextView nameTv;
        public int viewType;

        public ItemViewHodler(@NonNull View itemView, int viewType) {
            super(itemView);
            this.viewType = viewType;
            nameTv = itemView.findViewById(R.id.name_tv);
        }

        public int getViewType() {
            return viewType;
        }
    }

    public interface OnItemClickListeners {
        void itemBean(int pos, TaskBean TaskBean);
    }

    public OnItemClickListeners listeners;

    public void setOnItemClickListeners(OnItemClickListeners listener) {
        this.listeners = listener;
    }
}
