package com.ycgis.macall.personalcenter.v.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.rs.macall.androidx.basemodel.base.BaseRecyclerAdapter;
import com.rs.macall.androidx.basemodel.base.BaseViewBindActivity;
import com.ycgis.macall.personalcenter.R;
import com.ycgis.macall.personalcenter.databinding.ItemHomeAppBinding;
import com.ycgis.macall.personalcenter.m.adapterbean.MyItem;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * created by:   Macall
 * create time:  2022/11/10 10:32
 * copyright:    @ruansee.com
 * Describe:
 */
public class MyItemAdapter extends BaseRecyclerAdapter<MyItem<BaseViewBindActivity>,BaseRecyclerAdapter.ViewHolder> {

    public MyItemAdapter(Context context, List<MyItem<BaseViewBindActivity>> dataList) {
        super(context, dataList);
    }

    @Override
    public int getItemViewType(int position) {
        return getDataItem(position).getBaseType();
    }

    @NonNull
    @NotNull
    @Override
    public BaseRecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        if (viewType == 1){
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_app, parent, false);
            ItemHomeAppBinding bind = ItemHomeAppBinding.bind(view);
            return new ViewBindingHolder<>(bind);
//                    SimpleViewHolder(view).findViewById(R.id.home_app_logo).findViewById(R.id.home_app_name);
        }
        if (viewType == 5){
            return  new ViewHolder(bindView(parent,R.layout.item_dev_12));
        }
        return new SimpleViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_my_opertion,parent,false))
                .findViewById(R.id.tv_title).findViewById(R.id.iv_icon);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull BaseRecyclerAdapter.ViewHolder viewHolder, int position) {
        MyItem<BaseViewBindActivity> dataItem = getDataItem(position);
        if (viewHolder instanceof ViewBindingHolder){
            ViewBindingHolder<ItemHomeAppBinding> holder = ( ViewBindingHolder<ItemHomeAppBinding>)viewHolder;
            holder.viewBind.homeAppName.setText(dataItem.getTitle());
            holder.viewBind.homeAppLogo.setImageDrawable(ContextCompat.getDrawable(context,dataItem.getIcon()));
        }
        if (viewHolder instanceof BaseRecyclerAdapter.SimpleViewHolder){
            SimpleViewHolder holder = (SimpleViewHolder)viewHolder;
            TextView tv_title = holder.getView(R.id.tv_title, TextView.class);
            ImageView iv_icon = holder.getView(R.id.iv_icon, ImageView.class);
            tv_title.setText(dataItem.getTitle());
            iv_icon.setImageDrawable(ContextCompat.getDrawable(context,dataItem.getIcon()));
        }

    }
}
