Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.moyoweb.winescanner;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import android.app.Application;
- import android.content.Context;
- import android.os.Parcel;
- import android.os.Parcelable;
- public class Wine implements Parcelable {
- private String barcode;
- private String barcodeType;
- private String name;
- private int year;
- private String country;
- private String taste;
- private String color;
- private String description;
- private boolean sparkling;
- private boolean biologic;
- private int wineImage;
- private static Context context;
- public Wine() {
- }
- public Wine(String barcode, String barcodeType, String name, int year,
- String country, String taste, String color, String description,
- Boolean sparkling, Boolean biologic) {
- this.barcode = barcode;
- this.barcodeType = barcodeType;
- this.name = name;
- this.year = year;
- this.country = country;
- this.taste = taste;
- this.color = color;
- this.description = description;
- this.sparkling = sparkling;
- this.biologic = biologic;
- Wine.context = context.getApplicationContext();
- }
- public static ArrayList<Wine> fromJSON(ArrayList<Wine> wineListFromWSRArrayList) {
- return wineListFromWSRArrayList;
- }
- public static Wine fromJSON(JSONObject jObject) {
- Wine wine = new Wine();
- JSONObject jOb = jObject;
- try {
- wine.setBarcode(jOb.getString("barcode"));
- //wine.setBarcodeType(jOb.getString("barcodeType"));
- wine.setName(jOb.getString("name"));
- wine.setYear(jOb.getInt("year"));
- wine.setCountry(jOb.getString("country"));
- wine.setTaste(jOb.getString("taste"));
- wine.setColor(jOb.getString("color"));
- //wine.setDescription(jOb.getString("description"));
- //wine.setSparkling(parseToBool(jOb.getInt("sparkling")));
- //wine.setBiologic(parseToBool(jOb.getInt("biologic")));
- wine.setWineImage(0);//wanneer er een link is kunnen we deze gebruiken.
- return wine;
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return wine;
- }
- public static List<Wine> fromJSONURL(JSONArray jsonAr) {
- List<Wine> wines = new ArrayList<Wine>();
- for (int i = 0; i < jsonAr.length(); i++) {
- try {
- Wine wine = new Wine();
- JSONObject jWine = jsonAr.getJSONObject(i);
- JSONArray jsarDescription = jWine.getJSONArray("descriptions");
- wine.setBarcode(jWine.getString("uuid"));//testdoeleindes, dit is uniq id van de wijnen!
- //wine.setBarcodeType(jWine.getString("barcodeType"));
- wine.setName(jWine.getString("title"));
- wine.setCountry(jWine.getString("country"));
- //wine.setBiologic(parseToBool(jWine.getInt("biologic")));
- wine.setColor(jWine.getString("color"));
- String descriptions="";
- int j =0;
- Random randDescript = new Random();
- j = randDescript.nextInt(jsarDescription.length());
- //dante here is the error
- JSONObject obDesc = jsarDescription.getJSONObject(j);
- descriptions = descriptions + context.getResources().getString(com.moyoweb.winescanner.R.string.this_is_what_from_description)
- +obDesc.getJSONObject("store").getString("title")+ ""
- + context.getResources().getString(com.moyoweb.winescanner.R.string.write_about_wine_from_description)
- +obDesc.getString("description");
- wine.setDescription(descriptions);//aanpassen zodat we alle descriptions krijgen.
- //wine.setSparkling(parseToBool(jWine.getInt("sparkling")));
- wine.setTaste(jWine.getString("taste"));
- if(!jWine.getString("year").equalsIgnoreCase("")){
- wine.setYear(Integer.parseInt(jWine.getString("year")));
- }
- if(!jWine.has("image")){
- wine.setWineImage(com.moyoweb.winescanner.R.drawable.image_not_available);//wanneer er een link is kunnen we deze gebruiken.
- }else if(!jWine.getString("image").equalsIgnoreCase("")){
- wine.setWineImage(com.moyoweb.winescanner.R.drawable.image_not_available);//wanneer er een link is kunnen we deze gebruiken.
- }else{
- wine.setWineImage(com.moyoweb.winescanner.R.drawable.marques_de_arienzo_crianza_rode_spanje);//nep, kijken hoe we deze opvangen
- }
- wines.add(wine);
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return wines;
- }
- public static Boolean parseToBool(int int1) {
- if (int1 == 1) {
- return true;
- } else if (int1 == 0) {
- return false;
- }
- return null;
- }
- private static int BoolparseToInt(Boolean bool) {
- if (bool) {
- return 1;
- } else if (!bool) {
- return 0;
- }
- return -1;
- }
- public Boolean getBiologic() {
- return biologic;
- }
- public Boolean getSparkling() {
- return sparkling;
- }
- public String getDescription() {
- return description;
- }
- public String getColor() {
- return color;
- }
- public String getTaste() {
- return taste;
- }
- public String getCountry() {
- return country;
- }
- public int getYear() {
- return year;
- }
- public String getName() {
- return name;
- }
- public String getBarcodeType() {
- return barcodeType;
- }
- public String getBarcode() {
- return barcode;
- }
- public int getWineImage() {
- return wineImage;
- }
- public void setWineImage(int imageNotAvailable) {
- this.wineImage = imageNotAvailable;
- }
- public void setBiologic(Boolean biologic) {
- this.biologic = biologic;
- }
- public void setSparkling(Boolean sparkling) {
- this.sparkling = sparkling;
- }
- public void setDescription(String description) {
- this.description = description;
- }
- public void setColor(String color) {
- this.color = color;
- }
- public void setTaste(String taste) {
- this.taste = taste;
- }
- public void setCountry(String country) {
- this.country = country;
- }
- public void setYear(int year) {
- this.year = year;
- }
- public void setName(String name) {
- this.name = name;
- }
- public void setBarcodeType(String barcodeType) {
- this.barcodeType = barcodeType;
- }
- public void setBarcode(String barcode) {
- this.barcode = barcode;
- }
- // // Parcelling part
- private Wine(Parcel in) {
- this.barcode = in.readString();
- this.barcodeType = in.readString();
- this.name = in.readString();
- this.year = in.readInt();
- this.country = in.readString();
- this.taste = in.readString();
- this.color =in.readString();
- this.description = in.readString();
- this.sparkling = parseToBool(in.readInt());
- this.biologic = parseToBool(in.readInt());
- }
- @Override
- public int describeContents() {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(barcode);
- dest.writeString(barcodeType);
- dest.writeString(name);
- dest.writeInt(year);
- dest.writeString(country);
- dest.writeString(taste);
- dest.writeString(color);
- dest.writeString(description);
- dest.writeInt(BoolparseToInt(sparkling));
- dest.writeInt(BoolparseToInt(biologic));
- }
- public static final Parcelable.Creator<Wine> CREATOR = new Parcelable.Creator<Wine>() {
- @Override
- public Wine createFromParcel(Parcel source) {
- return new Wine(source);
- }
- @Override
- public Wine[] newArray(int size) {
- return new Wine[size];
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment