package com.beanpodtech.allinone.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.beanpodtech.allinone.R;
import com.beanpodtech.allinone.bean.SelectSubjectBean;

import java.util.List;

public class SubjectAdapter extends RecyclerView.Adapter {
    private List<SelectSubjectBean.ListBean.SubjectListBean> list;
    private Context mContext;
    private LayoutInflater inflate;

    public SubjectAdapter(List<SelectSubjectBean.ListBean.SubjectListBean> list, Context mContext) {
        this.list = list;
        this.mContext = mContext;
        inflate = LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = inflate.inflate(R.layout.item_selectsubject, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
//        ((ViewHolder) holder).class_name.setText(list.get(position).getSubjectName());
//        if (list.get(position).getSubjectTitle() != null && !TextUtils.isEmpty(list.get(position).getSubjectTitle())) {
//            ((ViewHolder) holder).tv_title.setVisibility(View.GONE);
//            ((ViewHolder) holder).tv_title.setText(list.get(position).getSubjectTitle());
//        } else {
//            ((ViewHolder) holder).tv_title.setVisibility(View.GONE);
//        }
//        ((ViewHolder) holder).id_num.setText("语文");
//        holder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(v.getContext(), PlayvideoActivity.class);
//                Bundle bundle = new Bundle();
//                bundle.putCharSequence("name", list.get(position).getSubjectName());
//                intent.putExtras(bundle);
//                v.getContext().startActivity(intent);
//
//            }
//        });
    }

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

    //内部类，绑定控件
    class ViewHolder extends RecyclerView.ViewHolder {
        TextView className, idNum, tvTitle;

        public ViewHolder(View itemView) {
            super(itemView);
            className = (TextView) itemView.findViewById(R.id.class_name);
            idNum = (TextView) itemView.findViewById(R.id.id_num);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
        }
    }
}
