Empty categories bug fixed.

parent e707b27c
...@@ -124,12 +124,9 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular ...@@ -124,12 +124,9 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
private int find_picto_index(int pic_cat, int pic_id) { private int find_picto_index(int pic_cat, int pic_id) {
LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat); LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat);
int index=-1; int index=-1;
Log.d("Vocabulary BORRA 2.1",pic_cat+" "+pic_id);
for (int i=0; i<pictos_cat.size() && index==-1; i++) { for (int i=0; i<pictos_cat.size() && index==-1; i++) {
Log.d("Vocabulary BORRA 2.15",i+":"+pictos_cat.get(i).get_id());
if (pictos_cat.get(i).get_id()==pic_id) index=i; if (pictos_cat.get(i).get_id()==pic_id) index=i;
} }
Log.d("Vocabulary BORRA 2.2",pic_cat+" "+pic_id+" "+index);
return index; return index;
} }
/** /**
...@@ -138,9 +135,12 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular ...@@ -138,9 +135,12 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
*/ */
public void removePicto(int pic_cat, int pic_id){ public void removePicto(int pic_cat, int pic_id){
LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat); LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat);
pictos_cat.remove(find_picto_index(pic_cat, pic_id)); int index = find_picto_index(pic_cat, pic_id);
if (index>0) { //puede ocurrir que se intente borrar un pictograma dos veces
pictos_cat.remove();
PCBcontext.getPcbdb().deletePicto(pic_id); PCBcontext.getPcbdb().deletePicto(pic_id);
} }
}
/** /**
* It modifies de given pic from the user collection * It modifies de given pic from the user collection
...@@ -150,11 +150,13 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular ...@@ -150,11 +150,13 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
*/ */
public void modifyAttsPicto(int pic_cat, int pic_id, JSONObject attrs) { public void modifyAttsPicto(int pic_cat, int pic_id, JSONObject attrs) {
Log.d("Vocabulary MOD BORRA 2",pic_cat+"---"+pic_id); int index=find_picto_index(pic_cat, pic_id);
Picto picto=this.pictos.get(pic_cat).get(find_picto_index(pic_cat, pic_id)); if (index>0) { //puede ocurrir que se intente modificar un pictograma que fue borrado
Picto picto = this.pictos.get(pic_cat).get(index);
picto.set_json_attr(attrs); picto.set_json_attr(attrs);
PCBcontext.getPcbdb().modifyPicto(pic_id, attrs.toString()); PCBcontext.getPcbdb().modifyPicto(pic_id, attrs.toString());
} }
}
/** /**
* It loads into the vocabulary a given picto which was stored in the local db. * It loads into the vocabulary a given picto which was stored in the local db.
...@@ -292,20 +294,15 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular ...@@ -292,20 +294,15 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
public void change(action action, int picto_cat, int picto_id, JSONObject args) { public void change(action action, int picto_cat, int picto_id, JSONObject args) {
switch (action) { switch (action) {
case delete: { case delete: {
Log.d("Vocabulary.java", "Entra en el case delete. Picto cat: " + picto_cat + " y picto_id: " + picto_id);
removePicto(picto_cat, picto_id); removePicto(picto_cat, picto_id);
break; break;
} }
case update:{ case update:{
Log.d("Vocabulary.java", "Update cat" + picto_cat + ". icto_id: " + picto_id);
modifyAttsPicto(picto_cat, picto_id, args); modifyAttsPicto(picto_cat, picto_id, args);
break; break;
} }
case add:{ case add:{
Log.d("Vocabulary.java", "Entra en el case add. Picto_id: " + picto_id);
try{ try{
String text= args.getJSONObject("expression").getString("text"); String text= args.getJSONObject("expression").getString("text");
String uri=args.getJSONObject("picto").getString("uri"); String uri=args.getJSONObject("picto").getString("uri");
......
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