package com.tenlionsoft.baselib.core.widget.views;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.tenlionsoft.baselib.R;
import com.tenlionsoft.baselib.core.beans.UserLoginBean;
import com.tenlionsoft.baselib.core.retrofit_net.BaseUrlApi;
import com.tenlionsoft.baselib.core.widget.base.BaseRecyclerAdapter;

import java.util.List;

/**
 * 功能按钮Adapter
 */
public class BaseFunctionAdapter extends BaseRecyclerAdapter<UserLoginBean.UseAppList, BaseFunctionHolder> {
    public BaseFunctionAdapter(Context ctx, List<UserLoginBean.UseAppList> list) {
        super(ctx, list);
    }

    @Override
    public BaseFunctionHolder createHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(mContext).inflate(R.layout.item_base_function, parent, false);
        return new BaseFunctionHolder(itemView);
    }

    @Override
    public void bindHolder(BaseFunctionHolder holder, int i) {
        if (!TextUtils.isEmpty(mData.get(i).getAppPhotoPath())) {
            Glide.with(mContext)
                    .load(BaseUrlApi.BASE_URL + mData.get(i).getAppPhotoPath())
                    .apply(new RequestOptions()
                            .error(R.drawable.ic_party)
                            .placeholder(R.drawable.ic_party)
                            .override(130)
                            .fitCenter())
                    .into(holder.mIvButton);
        } else {
            holder.mIvButton.setImageResource(R.drawable.ic_supervision_big);
        }
        holder.mTvName.setText(mData.get(i).getName());
        if (TextUtils.isEmpty(mData.get(i).getBgColor())) {
            holder.mRlContent.setBackgroundResource(R.drawable.shape_main_btn_party);
        } else {
            try {
                holder.mRlContent.setBackgroundColor(Color.parseColor(mData.get(i).getBgColor()));
            } catch (Exception e) {

            }
        }
    }
}
