Added Category model and extracted categories

This commit is contained in:
misaochan 2015-12-23 17:58:04 +13:00
parent 9a1d10fe8f
commit 3797d0d5cd

View file

@ -14,16 +14,15 @@ import com.android.volley.toolbox.JsonRequest;
import com.android.volley.toolbox.Volley; import com.android.volley.toolbox.Volley;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
public class MwVolleyApi { public class MwVolleyApi {
private static RequestQueue REQUEST_QUEUE; private static RequestQueue REQUEST_QUEUE;
private static final Gson GSON = new Gson(); private static final Gson GSON = new GsonBuilder().create();
private Context context; private Context context;
public MwVolleyApi(Context context) { public MwVolleyApi(Context context) {
@ -110,14 +109,12 @@ public class MwVolleyApi {
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder("pages="); StringBuilder builder = new StringBuilder("pages=" + "\n");
for (Page page : pages) { for (Page page : pages) {
builder.append(page.toString()); builder.append(page.toString());
builder.append("\n"); builder.append("\n");
//page.extractCategories();
} }
builder.replace(builder.length() - 1, builder.length(), ""); builder.replace(builder.length() - 1, builder.length(), "");
return builder.toString(); return builder.toString();
} }
} }
@ -126,44 +123,39 @@ public class MwVolleyApi {
private int pageid; private int pageid;
private int ns; private int ns;
private String title; private String title;
//private ArrayList<Object> categories; private Category[] categories;
//private Category category; 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");
}
}*/
@Override @Override
public String toString() { public String toString() {
//if (categoryExists()==true) { StringBuilder builder = new StringBuilder("PAGEID=" + pageid + " ns=" + ns + " title=" + title + "\n" + " CATEGORIES= ");
return "pageid=" + pageid + " ns=" + ns + " title=" + title + " categories=";// + category.toString(); if (categories != null) {
//} for (Category category : categories) {
//else { builder.append(category.toString());
// return "pageid=" + pageid + " ns=" + ns + " title=" + title; 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;
}
}
}