Error en Vocabulary en la función synchronize cuando descargo la escena activa

parent 153e6af3
......@@ -172,8 +172,10 @@ public class Vocabulary implements Iterable<Picto> {
// and (ii) downloading
if (!upload_pending) {
final String picto_str = "/pictos";
//final String picto_str = "/pictos";
final String picto_str = "/activeScene";
String operation = PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu() + picto_str;
Log.i("TAG_PRUEBAS","Ruta: "+operation);
PCBcontext.getRestapiWrapper().ask(operation, new RestapiWrapper.iRestapiListener() {
@Override
public void preExecute() {
......@@ -182,24 +184,32 @@ public class Vocabulary implements Iterable<Picto> {
@Override
public void result(JSONArray result) {
}
@Override
public void result(JSONObject result) {
if (result != null) {
final String jpicto = "picto";
Log.i("TAG_PRUEBAS",result.toString());
/* final String jpicto = "picto";
final String jid = "id";
final String juri = "uri";
final String jattributes = "attributes";
final String jattributes = "attributes";*/
Picto[] pictos = new Picto[result.length()];
JSONObject picto, attributes;
JSONObject stupicto = null;
try {
for (int i = 0; i < result.length(); i++) {
stupicto = result.getJSONObject(i);
picto = stupicto.getJSONObject(jpicto);
attributes = stupicto.getJSONObject(jattributes);
attributes.put(Picto.JSON_ATTTRS.STUPICTO_ID, stupicto.get(jid));
pictos[i] = new Picto(picto.getInt(jid),
picto.getString(juri),
JSONArray stu_pictos = result.getJSONArray("pictos"); //Obtengo el JSONArray de los pictos
Log.i("TAG_PRUEBAS",stu_pictos.toString());
Picto[] pictos = new Picto[stu_pictos.length()];
for (int i = 0; i < stu_pictos.length(); i++) {
stupicto = stu_pictos.getJSONObject(i);
picto = stupicto.getJSONObject("picto");
attributes = stupicto.getJSONObject("attributes");
attributes.put(Picto.JSON_ATTTRS.STUPICTO_ID, stupicto.getInt("id"));
pictos[i] = new Picto(stupicto.getInt("id"),
picto.getString("uri"),
attributes);
}
synchronizeImgs(pictos);
......@@ -215,12 +225,14 @@ public class Vocabulary implements Iterable<Picto> {
Log.e(this.getClass().getName(), " Picto JSON error from server: " + stupicto.toString());
this.error(new RestapiWrapper.HTTPException("JSON Error:" + e.getMessage(), -1));
}
}else{
Log.i("TAG_PRUEBAS","result null");
}
}
@Override
/*@Override
public void result(JSONObject result) {
}
}*/
@Override
public void error(RestapiWrapper.HTTPException e) {
......@@ -245,13 +257,15 @@ public class Vocabulary implements Iterable<Picto> {
this.pictos.clear();
for (Picto updated_picto: updated_collection) {
LinkedList<Picto> pictos_cat;
Log.i("TAG_PRUEBAS","ID: "+updated_picto.get_id());
Picto picto = new Picto(updated_picto.get_id(),
updated_picto.get_url(),
updated_picto.get_translation(),
updated_picto.get_json_attrs());
if (pictos.containsKey(picto.get_category()))
if (pictos.containsKey(picto.get_category())) {
pictos_cat = pictos.get(picto.get_category());
else {
Log.i("TAG_PRUEBAS","Tiene categoria: "+pictos_cat);
}else {
pictos_cat = new LinkedList<>();
pictos.put(new Integer(picto.get_category()),pictos_cat);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment