Log.i(LOG_TAG,"Pictogram "+prev_picto.get_translation()+":"+prev_picto.get_id()+" to be replaced by "+newPicto.get_translation()+":"+newPicto.get_id());
Log.i(LOG_TAG,"Pictogram "+prev_picto.get_translation()+":"+prev_picto.get_id()+" to be replaced by "+newPicto.get_translation()+":"+newPicto.get_id());
...
@@ -129,20 +132,24 @@ public class Vocabulary implements Iterable<Picto> {
...
@@ -129,20 +132,24 @@ public class Vocabulary implements Iterable<Picto> {
* The only issue is: what happens whether the upload fails? --> The image will be lost.
* The only issue is: what happens whether the upload fails? --> The image will be lost.
* TODO: keep record of failed uploaded images to re-include as local pictos
* TODO: keep record of failed uploaded images to re-include as local pictos
*/
*/
privatevoidsynchronize_upload(){
privatebooleansynchronize_upload(){
booleanupload_pending=false;
try{
try{
PCBcontext.getPcbdb().getStudentVocabulary(this);
if(this.pictos.isEmpty())
PCBcontext.getPcbdb().getStudentVocabulary(this);
}catch(JSONExceptione){
}catch(JSONExceptione){
Log.e(this.getClass().getName()," Picto json error from local storage: "+e.getMessage());
Log.e(this.getClass().getName()," Picto json error from local storage: "+e.getMessage());
}
}
for(Pictopicto:this){
for(Pictopicto:this){
if(picto.local_status()){
if(picto.local_status()){
upload_pending=true;
newPictoUploader(picto).uploadState();
newPictoUploader(picto).uploadState();
Log.i(this.getClass().getCanonicalName(),"Picto status modified while offline. Picto translation: '"+
Log.i(this.getClass().getCanonicalName(),"Picto status modified while offline. Picto translation: '"+
picto.get_translation()+"', id:"+picto.get_id()+" Local status?"+picto.local_status());
picto.get_translation()+"', id:"+picto.get_id()+" Local status?"+picto.local_status());
}
}
if(picto.is_local())
if(picto.is_local())
try{
try{
upload_pending=true;
Log.i(this.getClass().getCanonicalName(),"Picto added while offline. Picto translation: '"+
Log.i(this.getClass().getCanonicalName(),"Picto added while offline. Picto translation: '"+
picto.get_translation()+"', id:"+picto.get_id()+" Local status?"+picto.local_status());
picto.get_translation()+"', id:"+picto.get_id()+" Local status?"+picto.local_status());
newPictoUploader(picto).upload();
newPictoUploader(picto).upload();
...
@@ -152,6 +159,7 @@ public class Vocabulary implements Iterable<Picto> {
...
@@ -152,6 +159,7 @@ public class Vocabulary implements Iterable<Picto> {
}
}
}
}
returnupload_pending;
}
}
/**
/**
* the vocabulary is (i) updated to and (ii) downloaded from the server.
* the vocabulary is (i) updated to and (ii) downloaded from the server.
...
@@ -159,65 +167,67 @@ public class Vocabulary implements Iterable<Picto> {
...
@@ -159,65 +167,67 @@ public class Vocabulary implements Iterable<Picto> {
Pictoprev_picto=find_picto(cat,coord_x,coord_y);//¿estamos reemplazanddo un picto que ya existe?
Pictoprev_picto=PCBcontext.getPcbdb().getCurrentUser().has_categories()?find_picto(cat,coord_x,coord_y):find_picto(coord_x,coord_y);//¿estamos reemplazanddo un picto que ya existe?
if(prev_picto!=null){//El picto ya existe
if(prev_picto!=null){//El picto ya existe
removePicto(prev_picto.get_category(),prev_picto.get_id());//borramos el picto local actual
removePicto(prev_picto.get_category(),prev_picto.get_id());//borramos el picto local actual
PCBcontext.getNetService().nextSynchro(newDate().getTime()+PCBcontext.getNetService().getSynchroTimingLength()*2);//nos saltamos una sincronización para evitar que llegue antes que los websockets
Log.i(LOG_TAG,"Received message '"+action+
Log.i(LOG_TAG,"Received message '"+action+
"' for picto "+picto_id+" (cat "+picto_cat+", picto: "+picto_stupicto);
"' for picto "+picto_id+" (cat "+picto_cat+", picto: "+picto_stupicto);
sql="SELECT `picto_exp`.`id`, `picto_exp`.`id_pic`, `picto_exp`.`lang`, `picto_exp`.`text`, `picto`.`id`, `picto`.`uri`, `picto`.`id_src`, `picto`.`id_owner`, `picto`.`id_cat` FROM `picto_exp` INNER JOIN `picto` ON `picto_exp`.`id_pic` = `picto`.`id` WHERE `picto_exp`.`lang`=? AND `picto_exp`.`text` LIKE ? AND (`picto`.`id_owner` IS NULL OR `picto`.`id_owner`=?) AND `picto`.`id_src`=? AND `picto`.`id_cat` IN (?);";
sql="SELECT `picto_exp`.`id`, `picto_exp`.`id_pic`, `picto_exp`.`lang`, `picto_exp`.`text`, `picto`.`id`, `picto`.`uri`, `picto`.`id_src`, `picto`.`id_owner`, `picto`.`id_cat` FROM `picto_exp` INNER JOIN `picto` ON `picto_exp`.`id_pic` = `picto`.`id` WHERE `picto_exp`.`lang`=? AND `picto_exp`.`text` LIKE ? AND (`picto`.`id_owner` IS NULL OR `picto`.`id_owner`=?) AND `picto`.`id_src`=? AND `picto`.`id_cat` IN (?);";
sql="SELECT `picto_exp`.`id`, `picto_exp`.`id_pic`, `picto_exp`.`lang`, `picto_exp`.`text`, `picto`.`id`, `picto`.`uri`, `picto`.`id_src`, `picto`.`id_owner`, `picto`.`id_cat` FROM `picto_exp` INNER JOIN `picto` ON `picto_exp`.`id_pic` = `picto`.`id` WHERE `picto_exp`.`lang`=? AND `picto_exp`.`text` LIKE ? AND (`picto`.`id_owner` IS NULL OR `picto`.`id_owner`=?) AND `picto`.`id_src`=?;";
sql="SELECT `picto_exp`.`id`, `picto_exp`.`id_pic`, `picto_exp`.`lang`, `picto_exp`.`text`, `picto`.`id`, `picto`.`uri`, `picto`.`id_src`, `picto`.`id_owner`, `picto`.`id_cat` FROM `picto_exp` INNER JOIN `picto` ON `picto_exp`.`id_pic` = `picto`.`id` WHERE `picto_exp`.`lang`=? AND `picto_exp`.`text` LIKE ? AND (`picto`.`id_owner` IS NULL OR `picto`.`id_owner`=?) AND `picto`.`id_src`=?;";