package com.cooleshow.teacher.adapter;

import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.cooleshow.base.utils.ScreenUtils;
import com.cooleshow.teacher.R;
import com.cooleshow.teacher.bean.HomeHotMusicSheetBean;
import com.cooleshow.teacher.bean.HomeHotMusicSheetItemBean;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cooleshow.teacher.widgets.HomeHotMusicSheetItemView;

import androidx.annotation.NonNull;

/**
 * Author by pq, Date on 2022/8/8.
 */
public class HomeHotMusicSheetAdapter extends BaseQuickAdapter<HomeHotMusicSheetItemBean, BaseViewHolder> {
    private int maxWidth = 0;

    public HomeHotMusicSheetAdapter() {
        super(R.layout.item_home_hot_music_sheet_layout);
        int screenWidth = ScreenUtils.getScreenWidth();
        maxWidth = (int) (screenWidth * 0.83);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, HomeHotMusicSheetItemBean homeHotMusicSheetItemBean) {
        LinearLayout ll_container = holder.getView(R.id.ll_container);
        ViewGroup.LayoutParams layoutParams = ll_container.getLayoutParams();
        layoutParams.width = maxWidth;
        ll_container.setLayoutParams(layoutParams);
        ll_container.removeAllViews();
        if (homeHotMusicSheetItemBean.sheetBeans != null && homeHotMusicSheetItemBean.sheetBeans.size() > 0) {
            for (int i = 0; i < homeHotMusicSheetItemBean.sheetBeans.size(); i++) {
                HomeHotMusicSheetBean.RowsBean homeHotMusicSheetBean = homeHotMusicSheetItemBean.sheetBeans.get(i);
                HomeHotMusicSheetItemView hotMusicSheetItemView = new HomeHotMusicSheetItemView(getContext());
                hotMusicSheetItemView.setData(homeHotMusicSheetBean);
                if (i != homeHotMusicSheetItemBean.sheetBeans.size() - 1) {
                    hotMusicSheetItemView.setDividingLineIsShow(true);
                } else {
                    hotMusicSheetItemView.setDividingLineIsShow(false);
                }
                ll_container.addView(hotMusicSheetItemView);
            }
        }
    }
}
