package com.wisewoods.eduandroid.ui.adapter;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.luck.picture.lib.decoration.GridSpacingItemDecoration;
import com.luck.picture.lib.tools.ScreenUtils;
import com.wisewoods.base.base.BaseAdapter;
import com.wisewoods.base.base.BaseVH;
import com.wisewoods.base.bean.RoomInfo;
import com.wisewoods.eduandroid.R;
import com.wisewoods.eduandroid.ui.adapter.photo.FullyGridLayoutManager;

import org.jetbrains.annotations.NotNull;

public class RoomAdapter extends BaseAdapter<RoomInfo.ListBean> {
    public RoomAdapter() {
        super(R.layout.item_recycler_room);
    }

    @Override
    protected void convert(@NotNull BaseVH baseVH, RoomInfo.ListBean listBean) {
        baseVH.setText(R.id.tv_name, listBean.classroomName)
                .setText(R.id.tv_seat_num, listBean.seatNumber + "")
                .setGone(R.id.tv_empty, listBean.scheduleCount != 0);
        RecyclerView rvSub = baseVH.getView(R.id.rv_sub);
        if (rvSub.getLayoutManager() == null) {
            FullyGridLayoutManager manager = new FullyGridLayoutManager(getContext(),
                    2, GridLayoutManager.VERTICAL, false);
            rvSub.setLayoutManager(manager);
        }
        if (rvSub.getItemDecorationCount() == 0) {
            rvSub.addItemDecoration(new GridSpacingItemDecoration(2,
                    ScreenUtils.dip2px(getContext(), 8), false));
        }
        if (rvSub.getAdapter() == null) {
            RoomSubAdapter adapter = new RoomSubAdapter();
            rvSub.setAdapter(adapter);
        }

        ((RoomSubAdapter) rvSub.getAdapter()).setNewInstance(listBean.scheduleList);
    }
}
