package w.soulofpluto.posstock;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;

/*
 Create by Ramesh Babu
 */

public class RackWiseAdapter extends RecyclerView.Adapter<RackWiseAdapter.ViewHolder>{
    private Context context;
    private ArrayList<RackWise> arrayList;

    public RackWiseAdapter(Context context, ArrayList<RackWise> storesArrayList){
        this.context       = context;
        this.arrayList     = storesArrayList;
    }

    @NonNull
    @Override
    public RackWiseAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        View listItem = layoutInflater.inflate(R.layout.rackwise_item, parent, false);
        RackWiseAdapter.ViewHolder viewHolder = new RackWiseAdapter.ViewHolder(listItem);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RackWiseAdapter.ViewHolder holder, final int position){
        final RackWise items = arrayList.get(position);
        if(items.getId().equalsIgnoreCase("null")){
           holder.rack_id.setText("");
        }else{
           holder.rack_id.setText(Html.fromHtml(Constants.Id + items.getId()));
        }
        holder.rack_userid.setText(Html.fromHtml(Constants.User+items.getScanned_by()));
        holder.rack_from.setText(Html.fromHtml(Constants.From+items.getScanning_start_at()));
        holder.rack_to.setText(Html.fromHtml(Constants.To+items.getScanning_end_at()));
        holder.rack_qty.setText(String.valueOf(items.getQty()));
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder{
        public TextView rack_id,rack_qty,rack_userid,rack_from,rack_to;
        public ViewHolder(View itemView){
            super(itemView);
            rack_id         = itemView.findViewById(R.id.rack_id);
            rack_qty        = itemView.findViewById(R.id.rack_qty);
            rack_userid     = itemView.findViewById(R.id.rack_userid);
            rack_from       = itemView.findViewById(R.id.rack_from);
            rack_to         = itemView.findViewById(R.id.rack_to);
        }
    }
}

