package com.prankapp.fartsounds.airhorn.adapterdfds;

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

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

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.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.prankapp.fartsounds.airhorn.R;
import com.prankapp.fartsounds.airhorn.model.PrankListModel;

import java.util.List;

public class PrankDetailsListAdapter extends BaseQuickAdapter<PrankListModel.ListBean, BaseViewHolder> {
    public PrankDetailsListAdapter(int layoutResId, @Nullable List<PrankListModel.ListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, PrankListModel.ListBean item) {
        ImageView image = helper.getView(R.id.iv_item);
        RequestOptions options = new RequestOptions()
                .bitmapTransform(new RoundedCorners(dip2px(mContext, 100)));
        Glide.with(mContext)
                .load(item.getPreUrl())
                .apply(options)
                .into(image);

    }

    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }


    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

}
