package com.ihaoin.hooloo.device.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.component.SettingsQueue;
import com.ihaoin.hooloo.device.data.vo.Recommend;
import com.ihaoin.hooloo.device.data.ScrollBean;
import com.ihaoin.hooloo.device.util.Utils;

public class RecommendAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHolder> {
    private Context mContext;

    public RecommendAdapter(Context context, int layoutResId, int sectionHeadResId) {
        super(layoutResId, sectionHeadResId, null);
        this.mContext = context;
    }

    @Override
    protected void convertHead(BaseViewHolder helper, ScrollBean item) {
        View layoutItem = helper.getView(R.id.layout_item);
        View logo = helper.getView(R.id.logo);
        SettingsQueue settingsQueue = new SettingsQueue(mContext, logo, layoutItem);
    }

    @Override
    protected void convert(BaseViewHolder helper, ScrollBean item) {
        ScrollBean.ScrollItemBean t = item.t;
        Recommend recommend = (Recommend) t.getObject();
        helper.setText(R.id.txt_name, recommend.getGoodsName());
        helper.setText(R.id.txt_intro, recommend.getDesc());
        ImageView imgRecommend = helper.getView(R.id.img_recommend);

        RoundedCorners roundedCorners = new RoundedCorners(5);
        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
        Glide.with(mContext).load(recommend.getPic()).apply(options).into(imgRecommend);

        View layoutItem = helper.getView(R.id.layout_item);
        layoutItem.setOnClickListener(v -> Utils.showGoodsDetail(mContext, recommend.getGoods()));
    }

}
