package com.example.bpa.view.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;

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

import com.example.bpa.R;
import com.example.bpa.helper.FlashHelper;
import com.example.bpa.view.control.MainMeunAdapter;
import com.example.bpa.view.inteface.MyClickListener;
import com.example.bpa.view.mode.MenuMode;
import com.example.bpa.view.mode.lcMode;

import java.util.List;


public class lc_item_adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>  {

    private final LayoutInflater mLayoutInflater;
    private Context context;
    private List<lcMode> list;

    public lc_item_adapter(Context context, List<lcMode> list) {
        this.context = context;
        this.list = list;
        mLayoutInflater = LayoutInflater.from(context);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = mLayoutInflater.inflate(R.layout.lc_item, parent, false);
        return new MyLCViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        try {
            if (holder instanceof MyLCViewHolder) {
                MyLCViewHolder myViewHolder = (MyLCViewHolder) holder;
                myViewHolder.materialName.setText(list.get(position).materialName);
                myViewHolder.silosmargin.setText(list.get(position).silosmargin);
                myViewHolder.num.setText(Integer.toString(list.get(position).num) );
                myViewHolder.id = list.get(position).id;
                myViewHolder.MaterialName = list.get(position).materialName;
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class MyLCViewHolder extends RecyclerView.ViewHolder {
        /**
         * 料仓名称
         */
        public TextView materialName;
        /**、
         * 料仓仓号
         */
        public TextView num;
        /**
         * 料仓余量
         */
        public TextView silosmargin;
        /**
         * 预警标识
         */
        public RelativeLayout image_yj;
        /**
         * 告警标识
         */
        public RelativeLayout image_gj;
        /**
         * 物料ID
         */
        public String id;
        /**
         * 物料名称
         */
        public String MaterialName;
        public MyLCViewHolder(View view) {
            super(view);
            materialName  = (TextView) view.findViewById(R.id.lc_item_materialName);
            num = (TextView) view.findViewById(R.id.lc_item_num);
            silosmargin = (TextView) view.findViewById(R.id.lc_item_silosmargin);
            image_yj = (RelativeLayout) view.findViewById(R.id.image_yj);
            image_gj = (RelativeLayout) view.findViewById(R.id.image_gj);
            FlashHelper.getInstance().startFlick(image_yj);
            FlashHelper.getInstance().startFlick(image_gj);
        }
        public  int getNum()
        {
            try   {
                return Integer.parseInt(num.getText().toString());
            } catch (Exception e) {
                e.printStackTrace();
                return 0;
            }
        }

        public void startFlick()
        {
            FlashHelper.getInstance().startFlick(image_yj);
            FlashHelper.getInstance().startFlick(image_gj);
        }
        public void stopFlick()
        {
            FlashHelper.getInstance().stopFlick(image_yj);
            FlashHelper.getInstance().stopFlick(image_gj);
        }

    }

}