Empty categories bug fixed.

parent e707b27c
......@@ -124,12 +124,9 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
private int find_picto_index(int pic_cat, int pic_id) {
LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat);
int index=-1;
Log.d("Vocabulary BORRA 2.1",pic_cat+" "+pic_id);
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;
}
/**
......@@ -138,8 +135,11 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
*/
public void removePicto(int pic_cat, int pic_id){
LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat);
pictos_cat.remove(find_picto_index(pic_cat, pic_id));
PCBcontext.getPcbdb().deletePicto(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);
}
}
/**
......@@ -150,10 +150,12 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
*/
public void modifyAttsPicto(int pic_cat, int pic_id, JSONObject attrs) {
Log.d("Vocabulary MOD BORRA 2",pic_cat+"---"+pic_id);
Picto picto=this.pictos.get(pic_cat).get(find_picto_index(pic_cat, pic_id));
picto.set_json_attr(attrs);
PCBcontext.getPcbdb().modifyPicto(pic_id, attrs.toString());
int index=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);
PCBcontext.getPcbdb().modifyPicto(pic_id, attrs.toString());
}
}
/**
......@@ -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) {
switch (action) {
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);
break;
}
case update:{
Log.d("Vocabulary.java", "Update cat" + picto_cat + ". icto_id: " + picto_id);
modifyAttsPicto(picto_cat, picto_id, args);
break;
}
case add:{
Log.d("Vocabulary.java", "Entra en el case add. Picto_id: " + picto_id);
try{
String text= args.getJSONObject("expression").getString("text");
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