<commit_before>package de.fau.cs.mad.fablab.android.cart;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
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.Spinner;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import de.fau.cs.mad.fablab.android.R;
import de.fau.cs.mad.fablab.rest.core.CartEntry;

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ProductViewHolder> {

    public static class ProductViewHolder extends RecyclerView.ViewHolder {
        private TextView cart_product_name;
        private ImageView cart_product_photo;
        private TextView cart_product_price;
        private Spinner cart_product_quantity_spinner;
        private TextView cart_product_quantity;


        ProductViewHolder(View itemView) {
            super(itemView);

            this.cart_product_quantity = (TextView) itemView.findViewById(R.id.cart_product_quantity);
            this.cart_product_quantity_spinner = (Spinner) itemView.findViewById(R.id.cart_product_quantity_spinner);
            this.cart_product_name = (TextView) itemView.findViewById(R.id.cart_product_name);
            this.cart_product_photo = (ImageView) itemView.findViewById(R.id.cart_product_photo);
            this.cart_product_price = (TextView) itemView.findViewById(R.id.cart_product_price);
        }
    }

    private List<CartEntry> products;
    private Context context;


    public RecyclerViewAdapter(Context context ,List<CartEntry> products) {
        this.context = context;
        this.products = products;
    }


    public void addProduct(CartEntry product) {
        for(int i = 0; i< products.size(); i++){
            if(products.get(i).getProductId() == product.getProductId()){
                products.get(i).setAmount(products.get(i).getAmount() + 1);
                notifyItemChanged(i);
                return;
            }
        }
        products.add(product);
        notifyItemInserted(getItemCount()-1);
    }

    public void clear() {
        products.clear();
        notifyDataSetChanged();
    }

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

    @Override
    public ProductViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cart_entry, viewGroup, false);
        ProductViewHolder pvh = new ProductViewHolder(v);

        return pvh;
    }

    @Override
    public void onBindViewHolder(final ProductViewHolder productViewHolder, final int i) {
        productViewHolder.cart_product_name.setText(products.get(i).getName());
        productViewHolder.cart_product_price.setText(String.valueOf(products.get(i).getPrice()) +
                Html.fromHtml(productViewHolder.itemView.getResources().getString(R.string.non_breaking_space)) +
                Html.fromHtml(productViewHolder.itemView.getResources().getString(R.string.currency)));
        productViewHolder.cart_product_photo.setImageResource(R.drawable.no_image_avl);

        // Set quantity text
        productViewHolder.cart_product_quantity.setText(
                productViewHolder.itemView.getResources().getString(R.string.cart_product_quantity) +
                Html.fromHtml(productViewHolder.itemView.getResources().getString(R.string.non_breaking_space)) +
                Html.fromHtml(productViewHolder.itemView.getResources().getString(R.string.italic_start)) +
                products.get(i).getUnit() +<commit_msg>fixed double price representation of product price<commit_after>package de.fau.cs.mad.fablab.android.cart;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
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.Spinner;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import de.fau.cs.mad.fablab.android.R;
import de.fau.cs.mad.fablab.rest.core.CartEntry;

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ProductViewHolder> {

    public static class ProductViewHolder extends RecyclerView.ViewHolder {
        private TextView cart_product_name;
        private ImageView cart_product_photo;
        private TextView cart_product_price;
        private Spinner cart_product_quantity_spinner;
        private TextView cart_product_quantity;


        ProductViewHolder(View itemView) {
            super(itemView);

            this.cart_product_quantity = (TextView) itemView.findViewById(R.id.cart_product_quantity);
            this.cart_product_quantity_spinner = (Spinner) itemView.findViewById(R.id.cart_product_quantity_spinner);
            this.cart_product_name = (TextView) itemView.findViewById(R.id.cart_product_name);
            this.cart_product_photo = (ImageView) itemView.findViewById(R.id.cart_product_photo);
            this.cart_product_price = (TextView) itemView.findViewById(R.id.cart_product_price);
        }
    }

    private List<CartEntry> products;
    private Context context;


    public RecyclerViewAdapter(Context context ,List<CartEntry> products) {
        this.context = context;
        this.products = products;
    }


    public void addProduct(CartEntry product) {
        for(int i = 0; i< products.size(); i++){
            if(products.get(i).getProductId() == product.getProductId()){
                products.get(i).setAmount(products.get(i).getAmount() + 1);
                notifyItemChanged(i);
                return;
            }
        }
        products.add(product);
        notifyItemInserted(getItemCount()-1);
    }

    public void clear() {
        products.clear();
        notifyDataSetChanged();
    }

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

    @Override
    public ProductViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cart_entry, viewGroup, false);
        ProductViewHolder pvh = new ProductViewHolder(v);

        return pvh;
    }

    @Override
    public void onBindViewHolder(final ProductViewHolder productViewHolder, final int i) {
        productViewHolder.cart_product_name.setText(products.get(i).getName());
        String formated_price = String.format("%.2f", products.get(i).getPrice());
        productViewHolder.cart_product_price.setText(formated_price +
                Html.fromHtml(productViewHolder.itemView.getResources().getString(R.string.non_breaking_space)) +
                Html.fromHtml(productViewHolder.itemView.getResources().getString(R.string.currency)));
        productViewHolder.cart_product_photo.setImageResource(R.drawable.no_image_avl);

        // Set quantity text
        productViewHolder.cart_product_quantity.setText(
                productViewHolder.itemView.getResources().getString(R.string.cart_product_quantity) +
                Html.fromHtml(productViewHolder.itemView.getResources().getString(R.string.non_breaking_space)) +
                Html.fromHtml(productViewHolder.itemView.getResources().getString(R.string.italic_start)) +
                products.get(i).getUnit() +
{'fraction_non_alphanumeric': 0.09860084477296727, 'fraction_numerical': 0.001187961985216473, 'mean_word_length': 3.3671469740634006, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5398468', 'n_tokens_mistral': 2189, 'n_tokens_neox': 2074, 'n_words': 330}