package com.hi.music.player.adapter;

import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.hi.music.player.MusicApplication;
import com.hi.music.player.R;
import com.hi.music.player.databinding.ItemCategoryBinding;
import com.hi.music.player.helper.CommonUtils;
import com.hi.music.player.helper.MyValue;
import com.hi.music.player.javabean.response.child.ResponseCategory;

public class AdapterCategory extends BaseAdapter<ResponseCategory, ItemCategoryBinding>{

    @Override
    protected ItemCategoryBinding getViewBinding(ViewGroup parent) {
        return ItemCategoryBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
    }

    @Override
    public void onBindViewHolder(@NonNull  RecyclerView.ViewHolder holder, int position) {

        int itemViewType = getItemViewType(position);
        if (itemViewType == TYPE_ITEM) {
            VHolder<ItemCategoryBinding> itemHolder = (VHolder<ItemCategoryBinding>) holder;
            ItemCategoryBinding vb = itemHolder.getVb();
            ResponseCategory responseCategory = data.get(position);
            String pageType = responseCategory.getPageType();
            Glide.with(MusicApplication.myApplication)
                    .asDrawable()
                    .load(responseCategory.getCovert())
                    .placeholder(R.mipmap.im_placeholder)
                    .into(vb.header);
            vb.tvTitle.setText(responseCategory.getTwoTitle());
            vb.tvSubtitle.setText(responseCategory.getTwoSubtitle());
            CommonUtils.LogMsg("title="+responseCategory.getTwoTitle()+"----------pageType="+pageType
            +"---browserId="+responseCategory.getBrowseId()+"---videoId="+responseCategory.getVideoId()+"---playListId="+responseCategory.getPlayListId());
            if(pageType == null){
                return;
            }
//            if(pageType.equals(MyValue.PAGE_TYPE_MV)||pageType.equals(MyValue.PAGE_TYPE_MV_LIST)){
//                ViewGroup.LayoutParams layoutParams = vb.header.getLayoutParams();
//                layoutParams.width = CommonUtils.dpToPx(280);
//                vb.header.setLayoutParams(layoutParams);
//                vb.header.setBackgroundResource(R.drawable.bg_black_13);
//
//            }else {
//                ViewGroup.LayoutParams layoutParams = vb.header.getLayoutParams();
//                layoutParams.width = CommonUtils.dpToPx(170);
//                vb.header.setLayoutParams(layoutParams);
//                vb.header.setBackground(null);
//            }


            vb.header.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (homeItemClickListener != null) {
                        homeItemClickListener.onClickItemCategory(responseCategory);
                    }
                }
            });
        }
    }
}
