package com.tencent.qcloud.tuikit.tuichat.widget;

import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.tencent.qcloud.tuicore.util.ScreenUtil;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.zxhl.cms.net.model.chat.ChatGiftListBackEntity;

import java.util.List;

/**
 * @Description: java类作用描述
 * @Author: lidandan
 * @CreateDate: 2021/12/25 6:04 下午
 */
public class ConversionChatGiftAdapter extends BaseQuickAdapter<ChatGiftListBackEntity.ChatGiftListEntity, BaseViewHolder> {

    public ConversionChatGiftAdapter(@Nullable List<ChatGiftListBackEntity.ChatGiftListEntity> data) {
        super(R.layout.adapter_conversion_chat_gift, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, ChatGiftListBackEntity.ChatGiftListEntity item) {
        LinearLayout itemLayout = holder.getView(R.id.conversion_chat_item_layout);
        AppCompatImageView chatGiftIconIV = holder.getView(R.id.chat_gift_icon_iv);
        ((AppCompatTextView) holder.getView(R.id.chat_gift_title_tv)).setText(item.title);
        ((AppCompatTextView) holder.getView(R.id.chat_gift_price_tv)).setText(item.priceStr);
        RequestOptions options = new RequestOptions();
        options.diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(getContext()).load(item.img).apply(options).into(chatGiftIconIV);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) itemLayout.getLayoutParams();
        int spaceWidth = ScreenUtil.getScreenWidth(getContext()) - ScreenUtil.dip2px(15f) * 2;
        layoutParams.width = spaceWidth / 4;
        itemLayout.setLayoutParams(layoutParams);
    }
}
