package com.example.ismailamrani.comptable.models;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Ismail Amrani on 23/03/2016.
 */
public class Product {

    int ID;
    String Libelle;
    Double PrixHT;
    Double PrixTTC;
    String CodeBarre;
    String Photo;
    int Qte;
    int Locale_ID;
    String url;

    /**
     * Overloaded constructor.
     * Creates a new Product model based on the passed-in JSON object
     *
     * @param object to be parsed.
     */
    public Product(JSONObject object) throws JSONException {
        this(
                object.getInt("idp"),
                object.getString("libelle"),
                object.getDouble("PrixHT"),
                object.getDouble("PrixTTC"),
                object.getString("codeBar"),
                object.getString("photo"),
                object.getInt("qte"),
                object.getInt("local"),
                ""
        );
    }

    public Product(int ID, String libelle, Double prixHT, Double prixTTC,
                   String codeBarre, String photo, int qte, int locale_ID, String url) {
        this.ID = ID;
        Libelle = libelle;
        PrixHT = prixHT;
        PrixTTC = prixTTC;
        CodeBarre = codeBarre;
        Photo = photo;
        Qte = qte;
        Locale_ID = locale_ID;
        this.url = url;
    }

    public Product() {

    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getID() {
        return ID;
    }

    public void setID(int ID) {
        this.ID = ID;
    }

    public String getLibelle() {
        return Libelle;
    }

    public void setLibelle(String libelle) {
        Libelle = libelle;
    }

    public Double getPrixHT() {
        return PrixHT;
    }

    public void setPrixHT(Double prixHT) {
        PrixHT = prixHT;
    }

    public Double getPrixTTC() {
        return PrixTTC;
    }

    public void setPrixTTC(Double prixTTC) {
        PrixTTC = prixTTC;
    }

    public String getCodeBarre() {
        return CodeBarre;
    }

    public void setCodeBarre(String codeBarre) {
        CodeBarre = codeBarre;
    }

    public String getPhoto() {
        return Photo;
    }

    public void setPhoto(String photo) {
        Photo = photo;
    }

    public int getQte() {
        return Qte;
    }

    public void setQte(int qte) {
        Qte = qte;
    }

    public int getLocale_ID() {
        return Locale_ID;
    }

    public void setLocale_ID(int locale_ID) {
        Locale_ID = locale_ID;
    }
}

@@ -45,16 +45,43 @@
 odels;%0A%0A
+import org.json.JSONArray;%0A
 import o
@@ -132,16 +132,68 @@
 bject;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 /**%0A * C
@@ -1449,17 +1449,541 @@
 duct() %7B
-%0A
+%7D%0A%0A    /**%0A     * @param array of products in JSON format%0A     * @return list of parsed products%0A     */%0A    public List%3CProduct%3E parseProducts(JSONArray array) %7B%0A        List%3CProduct%3E products = new ArrayList%3C%3E();%0A%0A        for (int i = 0; i %3C array.length(); i++) %7B%0A            try %7B%0A                JSONObject product = array.getJSONObject(i);%0A                products.add(new Product(product));%0A%0A            %7D catch (JSONException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D%0A%0A        return products;
 %0A    %7D%0A%0A

add a method to parse a JSONArray of products into a List object.