package com.cooleshow.student.adapter;

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

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.student.R;
import com.cooleshow.student.bean.AppHomeBean;
import com.cooleshow.student.bean.HomeHotNewsBean;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;

/**
 * 创建日期：2022/5/27 10:37
 *
 * @author Ryan
 * 类说明：
 */
public class HomeHotNewsAdapter extends BaseQuickAdapter<HomeHotNewsBean.RowsBean, BaseViewHolder> implements LoadMoreModule {

    public HomeHotNewsAdapter() {
        super(R.layout.item_home_hot_news);
    }


    @Override
    protected void convert(BaseViewHolder helper, HomeHotNewsBean.RowsBean item) {
        ImageView im_pic = helper.getView(R.id.im_pic);
        GlideUtils.INSTANCE.loadImage(getContext(), item.coverImage, im_pic);
        //名称
        TextView tv_content = helper.getView(R.id.tv_content);
        tv_content.setText(item.title);
        //日期
        TextView tv_date = helper.getView(R.id.tv_date);
        tv_date.setText(item.createTime);
        //描述
        helper.setText(R.id.tv_des, item.content);
        int position = helper.getLayoutPosition();
        View lineView = helper.getView(R.id.view_line);
        lineView.setVisibility(position == 0 ? View.GONE : View.VISIBLE);
        ConstraintLayout cs_root = helper.getView(R.id.cs_root);
        int size = getData().size();
        if(size == 1){
            cs_root.setBackgroundResource(com.cooleshow.base.R.drawable.bg_white_10dp);
        }else{
            if(position == 0){
                cs_root.setBackgroundResource(com.cooleshow.base.R.drawable.bg_white_top_10dp);
            }else if(position == size-1){
                cs_root.setBackgroundResource(com.cooleshow.base.R.drawable.bg_white_bottom_10dp);
            }else{
                cs_root.setBackgroundColor(getContext().getResources().getColor(R.color.white));
            }
        }
    }

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