From 3797d0d5cd790d1358a73287a490c2664878c015 Mon Sep 17 00:00:00 2001 From: misaochan Date: Wed, 23 Dec 2015 17:58:04 +1300 Subject: [PATCH] Added Category model and extracted categories --- .../free/nrw/commons/upload/MwVolleyApi.java | 70 ++++++++----------- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/commons/src/main/java/fr/free/nrw/commons/upload/MwVolleyApi.java b/commons/src/main/java/fr/free/nrw/commons/upload/MwVolleyApi.java index 416ad08ab..b835ce1ee 100644 --- a/commons/src/main/java/fr/free/nrw/commons/upload/MwVolleyApi.java +++ b/commons/src/main/java/fr/free/nrw/commons/upload/MwVolleyApi.java @@ -14,16 +14,15 @@ import com.android.volley.toolbox.JsonRequest; import com.android.volley.toolbox.Volley; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Collection; public class MwVolleyApi { private static RequestQueue REQUEST_QUEUE; - private static final Gson GSON = new Gson(); + private static final Gson GSON = new GsonBuilder().create(); private Context context; public MwVolleyApi(Context context) { @@ -110,14 +109,12 @@ public class MwVolleyApi { @Override public String toString() { - StringBuilder builder = new StringBuilder("pages="); + StringBuilder builder = new StringBuilder("pages=" + "\n"); for (Page page : pages) { builder.append(page.toString()); builder.append("\n"); - //page.extractCategories(); } builder.replace(builder.length() - 1, builder.length(), ""); - return builder.toString(); } } @@ -126,44 +123,39 @@ public class MwVolleyApi { private int pageid; private int ns; private String title; - //private ArrayList categories; - //private Category category; - - /* - public boolean categoryExists() { - if (categories != null) { - return true; - } - else { - return false; - } - } - - public void extractCategories() { - if (categoryExists()==true) { - Log.d("Cat", "categories exist"); - for (Object categoryobj : categories) { - Log.d("Cat", categoryobj.getClass().getName()); - } - } - else { - Log.d("Cat", "categories don't exist"); - } - }*/ - + private Category[] categories; + private Category category; @Override public String toString() { - //if (categoryExists()==true) { - return "pageid=" + pageid + " ns=" + ns + " title=" + title + " categories=";// + category.toString(); - //} - //else { - // return "pageid=" + pageid + " ns=" + ns + " title=" + title; - // } - } + StringBuilder builder = new StringBuilder("PAGEID=" + pageid + " ns=" + ns + " title=" + title + "\n" + " CATEGORIES= "); + if (categories != null) { + for (Category category : categories) { + builder.append(category.toString()); + builder.append("\n"); + } + } + else { + builder.append("no categories exist"); + builder.append("\n"); + } + builder.replace(builder.length() - 1, builder.length(), ""); + return builder.toString(); + } } -} + private static class Category { + private int ns; + private String title; + + @Override + public String toString() { + return " ns=" + ns + " title=" + title; + } + } + } + +