package com.cooleshow.teacher.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

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

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.BaseLoadMoreModule;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cooleshow.base.utils.GlideUtils;
import com.cooleshow.teacher.R;
import com.cooleshow.teacher.bean.HomeworkListBean;
import com.cooleshow.teacher.bean.MusicSheetListBean;

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

/**
 * 创建日期：2022/5/23 11:13
 *
 * @author Ryan
 * 类说明：
 */
public class HomeworkAdapter extends BaseQuickAdapter<HomeworkListBean.RowsBean, BaseViewHolder> implements LoadMoreModule {

    public HomeworkAdapter(List<HomeworkListBean.RowsBean> data) {
        super(R.layout.layout_item_homework, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, HomeworkListBean.RowsBean item) {
        TextView tv_date=helper.getView(R.id.tv_date);
        TextView tv_state=helper.getView(R.id.tv_state);
        ImageView im_header=helper.getView(R.id.im_header);
        TextView tv_name=helper.getView(R.id.tv_name);
        RecyclerView rv_mark=helper.getView(R.id.rv_mark);
        GlideUtils.INSTANCE.loadImage(getContext(), item.teacherAvatar, im_header, R.drawable.icon_teacher_default_head);
        tv_name.setText(item.teacherName);
        if (!TextUtils.isEmpty(item.subjectName)) {
            rv_mark.setVisibility(View.VISIBLE);
            List<String> markList = new ArrayList<>();
            if (item.subjectName.contains(",")) {
                String[] split = item.subjectName.split(",");
                for (String s : split) {
                    markList.add(s);
                }
            } else {
                markList.add(item.subjectName);
            }
            LinearLayoutManager manager = new LinearLayoutManager(getContext());
            manager.setOrientation(LinearLayoutManager.HORIZONTAL);
            rv_mark.setLayoutManager(manager);
            ItemMarkAdapter itemMarkAdapter = new ItemMarkAdapter(markList);
            rv_mark.setAdapter(itemMarkAdapter);
        } else {
            rv_mark.setVisibility(View.GONE);
        }
        tv_date.setText(item.classDate);

    }

    @NonNull
    @Override
    public BaseLoadMoreModule addLoadMoreModule(@NonNull BaseQuickAdapter<?, ?> baseQuickAdapter) {
        return new BaseLoadMoreModule(baseQuickAdapter);
    }

}
