package w.soulofpluto.posstock;

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.recyclerview.widget.RecyclerView;
import java.util.ArrayList;

/*
 Create by Ramesh Babu
 
 */
public class CreateSaleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context context;
    private ArrayList<Model> List;

    public CreateSaleAdapter(Context context, ArrayList<Model> list){
        this.context   = context;
        this.List = list;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i){
        LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
        View listItem = layoutInflater.inflate(R.layout.custom_list_item, viewGroup, false);
        CreateSaleAdapter.ViewHolder viewHolder = new CreateSaleAdapter.ViewHolder(listItem);
        return viewHolder;
    }
    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, final int position){
        final Model model = List.get(position);
        ((ViewHolder)viewHolder).Id.setText(model.getDelivery_slip_id());
        ((ViewHolder)viewHolder).remove.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                List.remove(position);
                notifyDataSetChanged();
                ((CreateSaleBill)context).SetData(model.getDelivery_slip_id());
            }
        });
    }
    @Override
    public int getItemCount(){
        return List.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView Id;
        private ImageView remove;
        public ViewHolder(View itemView){
            super(itemView);
            this.Id      = itemView.findViewById(R.id.Id);
            this.remove  = itemView.findViewById(R.id.remove);
        }
    }
}

