package com.daya.live_teaching.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.daya.live_teaching.R;
import com.daya.live_teaching.model.WhiteBoard;

import java.util.List;


/**
 * 课堂资源列表适配
 */
public class WhiteBoardListAdapter extends BaseAdapter {

    private List<WhiteBoard> whiteBoardList;

    @Override
    public int getCount() {
        return whiteBoardList != null && whiteBoardList.size() > 0 ? whiteBoardList.size() : 0;
    }

    @Override
    public WhiteBoard getItem(int position) {
        return whiteBoardList.get(position);

    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, final ViewGroup parent) {
        final ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.class_item_white_board_list, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.resourceNameTv = convertView.findViewById(R.id.tv_name);
            viewHolder.resourcePreviewIv = convertView.findViewById(R.id.iv_preview);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        WhiteBoard item = getItem(position);
        viewHolder.resourceNameTv.setText(item.getName() + (position + 1));
        return convertView;
    }

    /**
     * 设置白板列表
     * @param list
     */
    public void setWhiteBoardList(List<WhiteBoard> list) {
        whiteBoardList = list;
        notifyDataSetChanged();
    }


    private class ViewHolder {
        TextView  resourceNameTv;
        ImageView resourcePreviewIv;
    }

}
