package com.bonait.bnframework.modules.home.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

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

import com.bonait.bnframework.R;
import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE;
import com.bonait.bnframework.common.db.res.lcMode;
import com.bonait.bnframework.common.helper.I.MyClickListener;

import java.util.List;


public class gongxubuzhou_adapter extends ArrayAdapter<BPA_GOODSRECIPE> {
    /**
     * 内部点击事件
     */
    private MyClickListener mListener;
    private List<BPA_GOODSRECIPE> datas;

    private int selectedPosition = -1;// 选中的位置
    int resource1;
    public gongxubuzhou_adapter(@NonNull Context context, int resource, @NonNull List<BPA_GOODSRECIPE> objects, MyClickListener listener) {
        super(context, resource, objects);
        mListener = listener;
        datas=objects;
        this.resource1=resource;
    }

    public int getSelectedPosition()
    {
        return selectedPosition;
    }

    public void setSelectedPosition(int position) {
        selectedPosition = position;
    }
    //每个子项被滚动到屏幕内的时候会被调用
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        BPA_GOODSRECIPE lc = (BPA_GOODSRECIPE) getItem(position);//得到当前项选中item实例
        //为每一个子项加载设定的布局
        View view = LayoutInflater.from(getContext()).inflate(resource1, parent, false);
        //分别获取 image view 和 textview 的实例

        TextView text = view.findViewById(R.id.text);
        text.setText((position+1)+"、"+lc.processms);

        if (selectedPosition == position) {
            text.setSelected(true);
            text.setTextColor(Color.WHITE);
            text.setBackground(getContext().getResources().getDrawable(R.color.green_primary_dark));
        } else {
            text.setSelected(false);
            text.setTextColor(Color.BLACK);
            text.setBackground(getContext().getResources().getDrawable(R.color.white));

        }
        return view;
    }
}