Pictogram 1.6, beta 8, issue #454 closed

parent ef942e65
......@@ -388,8 +388,12 @@ public class Picto extends Img {
return legend.equalsIgnoreCase("null") ? JSON_ATTTR_LEGEND_VALUES.NONE : legend;
}
public void set_legend(String legend) throws JSONException {
this.attributes.put(JSON_ATTTRS.LEGEND,legend);
public void set_legend(String legend) {
try {
this.attributes.put(JSON_ATTTRS.LEGEND,legend);
} catch (JSONException e) {
Log.e(LOG_TAG,"Invalid JSON legend:"+this.attributes);
}
}
/**
......
......@@ -18,6 +18,7 @@ import com.yottacode.tools.GUITools;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
......@@ -69,11 +70,17 @@ public class Vocabulary implements Iterable<Picto> {
removePicto(picto_grid,picto_id);
break;
}
case update_allpictos:
try {
Log.i(LOG_TAG, "Vocabulary action listened (vocabulary model, all pictos): " + action);
modifyLegendPictos(args.getJSONObject("attributes").getString("legend"));
} catch (JSONException e) {
Log.e(LOG_TAG,"Error updating all pictos:"+e.getMessage());
}
case update:{
Log.i(LOG_TAG, "Vocabulary action listened (vocabulary model): " + action);
try {
modifyAttsPicto(picto_grid, picto_id, args.getJSONObject("attributes"), id_child_grid);
modifyAttsPicto(picto_grid, picto_id, args.getJSONObject("attributes"), id_child_grid);
} catch (JSONException e) {
e.printStackTrace();
Log.e(LOG_TAG,"Error updating picto:"+e.getMessage());
......@@ -110,6 +117,16 @@ public class Vocabulary implements Iterable<Picto> {
addActionTalkListener(action_listener);
}
private void modifyLegendPictos(String legend) {
Enumeration<LinkedList<Picto>> scenes=this.pictos.elements();
while (scenes.hasMoreElements()) {
LinkedList<Picto> scene=scenes.nextElement();
for (Picto picto:scene)
picto.set_legend(legend);
}
}
public void addActionTalkListener(ActionTalk.iActionListener listener) {
if (actionTalk==null) actionTalk=new ActionTalk(PCBcontext.getRoom(), listener);
else actionTalk.addListener(listener);
......@@ -200,9 +217,6 @@ public class Vocabulary implements Iterable<Picto> {
if (legal_delete) {//puede ocurrir que se intente borrar un pictograma dos veces
pictos.get(new Integer(pic_grid)).remove(index);
PCBcontext.getPcbdb().deletePicto(pic_grid, pic_id);
for (Picto p2:pictos.get(new Integer(pic_grid))) {
Log.e(LOG_TAG,"COJONES VOCABULA_>"+p2.get_translation());
}
}
}
......@@ -232,8 +246,8 @@ public class Vocabulary implements Iterable<Picto> {
Picto picto = this.pictos.get(pic_grid).get(index);
String old_legend=picto.get_legend();
picto.set_json_attr(attrs);
if (!old_legend.equals(picto.get_legend())) //puede ocurrir que se cambie la leyenda de TODOS los pictos
this.synchronize();
// if (!old_legend.equals(picto.get_legend())) //puede ocurrir que se cambie la leyenda de TODOS los pictos
// this.synchronize();
PCBcontext.getPcbdb().modifyPicto(pic_grid, pic_id, attrs.toString());
if (picto.get_child_grid()!=id_child_grid)
PCBcontext.getNetService().restart_app(false);
......
......@@ -30,6 +30,7 @@ public class VocabularyTalk implements Emitter.Listener {
@Override
public void call(Object... args) {
final String param_action="action";
final String param_all_pictos="all_pictos";
final String param_attributes="attributes";
final String param_picto="picto";
final String param_stu_picto="stu_picto";
......@@ -54,11 +55,13 @@ public class VocabularyTalk implements Emitter.Listener {
int id_child_grid=stu_picto.optInt(param_id_child_grid, Picto.NO_CHILD_GRID);
PCBcontext.getNetService().nextSynchro(new Date().getTime() + PCBcontext.getNetService().getSynchroTimingLength() * 2); //nos saltamos una sincronización para evitar que llegue antes que los websockets
iVocabularyListener.action saction=attributes.optBoolean(param_all_pictos,false)
? iVocabularyListener.action.update_allpictos
: action.equals(action_update) ? iVocabularyListener.action.update
: action.equals(action_add) ? iVocabularyListener.action.add
: iVocabularyListener.action.delete;
for (iVocabularyListener listener : this.listeners)
listener.change(action.equals(action_update) ? iVocabularyListener.action.update
: action.equals(action_add) ? iVocabularyListener.action.add
: iVocabularyListener.action.delete
, attributes.getInt(param_grid_id), picto_id, id_child_grid, stu_picto);
listener.change(saction, attributes.getInt(param_grid_id), picto_id, id_child_grid, stu_picto);
} catch (JSONException e) {
Log.e(LOG_TAG, "Error receiving new picto: "+e.getClass().getCanonicalName() + "--" + e);
......@@ -72,7 +75,7 @@ public class VocabularyTalk implements Emitter.Listener {
* @version 1.0
*/
public interface iVocabularyListener {
enum action {delete,add, update}
enum action {delete,add, update,update_allpictos}
void change(action action, int picto_cat, int picto_id, int id_child_grid, JSONObject args);
}
}
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