package com.cpm.lorealbaautomation.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
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 com.cpm.lorealbaautomation.R;
import com.cpm.lorealbaautomation.gsonGetterSetter.MasterNonStockReason;
import java.util.ArrayList;
import java.util.List;


public class ReasonSpinnerAdapter extends ArrayAdapter<MasterNonStockReason> {
    List<MasterNonStockReason> list;
    Context context;
    int resourceId;

    public ReasonSpinnerAdapter(Context context, int resourceId, ArrayList<MasterNonStockReason> list) {
        super(context, resourceId, list);
        this.context = context;
        this.list = list;
        this.resourceId = resourceId;
    }

    @SuppressLint("ViewHolder")
    @NonNull
    @Override
    public View getView(int position, View convertView, @NonNull ViewGroup parent) {
        View view = convertView;
        LayoutInflater inflater = (LayoutInflater.from(context));
        view = inflater.inflate(resourceId, parent, false);
        MasterNonStockReason cm = null;
        if (position < list.size()) cm = list.get(position);
        TextView txt_spinner = (TextView) view.findViewById(R.id.txt_sp_text);
        if (cm != null && cm.getReason() != null) {
            txt_spinner.setText(cm.getReason());
        }

        return view;
    }

    @Override
    public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) {
        View view = convertView;
        LayoutInflater inflater = (LayoutInflater.from(context));
        view = inflater.inflate(resourceId, parent, false);
        MasterNonStockReason cm = null;
        if (position < list.size()) cm = list.get(position);
        TextView txt_spinner = (TextView) view.findViewById(R.id.txt_sp_text);
        if (cm != null && cm.getReason() != null) {
            txt_spinner.setText(cm.getReason());
        }
        return view;
    }
}
