Commit e5859603 by Arturo Montejo Ráez

Merge branch 'develop' of http://scm.ujaen.es/softuno/pictogram into develop

parents 80347944 38b0b019
...@@ -368,8 +368,8 @@ public class Picto extends Img { ...@@ -368,8 +368,8 @@ public class Picto extends Img {
/** /**
* when the status is locally modified, it is required to remove when it is uploaded since it is no longer a local modification * when the status is locally modified, it is required to remove when it is uploaded since it is no longer a local modification
*/ */
public void set_local_status(boolean modified) { public void set_local_status(boolean local) {
if (modified) if (local)
try { try {
this.attributes.put(JSON_ATTTRS.PCB_STATUS_MODIFICATION, true); this.attributes.put(JSON_ATTTRS.PCB_STATUS_MODIFICATION, true);
PCBcontext.getPcbdb().modifyPicto(this.get_id(), this.get_json_attrs()); PCBcontext.getPcbdb().modifyPicto(this.get_id(), this.get_json_attrs());
...@@ -383,4 +383,4 @@ public class Picto extends Img { ...@@ -383,4 +383,4 @@ public class Picto extends Img {
PCBcontext.getPcbdb().modifyPicto(this.get_id(), this.get_json_attrs()); PCBcontext.getPcbdb().modifyPicto(this.get_id(), this.get_json_attrs());
} }
} }
} }
\ No newline at end of file
...@@ -120,6 +120,8 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -120,6 +120,8 @@ public class Vocabulary implements Iterable<Picto> {
} }
if (picto.get_id() < 0) //id<0 iif it is a local id if (picto.get_id() < 0) //id<0 iif it is a local id
try { try {
Log.i(this.getClass().getCanonicalName(), "Picto added while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_id() + " Local status?" + picto.local_status());
new PictoUploader(picto).upload(); new PictoUploader(picto).upload();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -130,15 +130,16 @@ public class NetService implements Runnable { ...@@ -130,15 +130,16 @@ public class NetService implements Runnable {
if (!updated) { if (!updated) {
updated = true; updated = true;
// Comprobar si hay usuario offline, para hacer login transparente if (PCBcontext.is_user_logged()) //si el usuario aun no hizo login, en realidad no es necesario hacer nada
if (PCBcontext.is_user_offline()){ // Comprobar si hay usuario offline, para hacer login transparente
login(); if (PCBcontext.is_user_offline()){
} else if (PCBcontext.is_user_online()){ login();
Log.i(this.getClass().getName(), "PCB reconnect"); } else if (PCBcontext.is_user_online()){
PCBcontext.getRoom().reconnect(); Log.i(this.getClass().getName(), "PCB reconnect");
PCBcontext.getVocabulary().synchronize(); PCBcontext.getRoom().reconnect();
PCBcontext.getActionLog().batch(); PCBcontext.getVocabulary().synchronize();
} PCBcontext.getActionLog().batch();
}
} }
Log.i(this.getClass().getName(), "PCB status checked. Updated? " + updated); Log.i(this.getClass().getName(), "PCB status checked. Updated? " + updated);
notifyStatus(); notifyStatus();
......
...@@ -169,8 +169,10 @@ public class PictoUploader { ...@@ -169,8 +169,10 @@ public class PictoUploader {
* *
**/ **/
public void upload() throws IOException { public void upload() throws IOException {
int local_img_id = this.picto.get_id();
int img_id = uploadImg(this.picto); int img_id = uploadImg(this.picto);
if (img_id > 0) { if (img_id > 0) {
PCBcontext.getPcbdb().deletePicto(local_img_id);
uploadAttributes(img_id); uploadAttributes(img_id);
uploadTranslation(img_id); uploadTranslation(img_id);
PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.ADD, PictoUploader.this.picto)); PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.ADD, PictoUploader.this.picto));
......
...@@ -28,23 +28,7 @@ public final class PCBcontext { ...@@ -28,23 +28,7 @@ public final class PCBcontext {
private static ActionLog actionLog; private static ActionLog actionLog;
private static boolean init=false; private static boolean init=false;
protected PCBcontext() {
// Initialize internal objects. This initialization is run only the first time
// when it's called PCBcontext.getInstance(); even between activities.
}
private static class Holder {
static final PCBcontext INSTANCE = new PCBcontext();
}
// Method to call outside when using this class --> PCBcontext pcb = PCBcontext.getInstance();
public static PCBcontext getInstance() {
return Holder.INSTANCE;
}
// ---------------------------------------------------------------------------------------------
// Rest of class methods
//
/** /**
* Init method for passing params to the singleton * Init method for passing params to the singleton
...@@ -88,6 +72,14 @@ public final class PCBcontext { ...@@ -88,6 +72,14 @@ public final class PCBcontext {
/** /**
* *
* @return true if a given user has been logged into the system (the login window was successfully filled)
*/
public static boolean is_user_logged() {
return (init && pcbdb!=null);
}
/**
*
*/ */
public static void unset_user() { public static void unset_user() {
pcbdb = null; pcbdb = null;
......
...@@ -196,7 +196,7 @@ END ...@@ -196,7 +196,7 @@ END
CREATE TRIGGER trg_insert_users_detail CREATE TRIGGER trg_insert_users_detail
INSTEAD OF INSERT ON users_detail INSTEAD OF INSERT ON users_detail
FOR EACH ROW FOR EACH ROW
WHEN NEW.pwd_stu IS NOT NULL WHEN NEW.pwd_stu IS NOT NULL
BEGIN BEGIN
INSERT OR REPLACE INTO student VALUES (NEW.id_stu, NEW.nickname_stu, NEW.pwd_stu, NEW.name_stu, NEW.surname_stu, NEW.url_img_stu, NEW.gender_stu, NEW.lang_stu, NEW.attributes_stu); INSERT OR REPLACE INTO student VALUES (NEW.id_stu, NEW.nickname_stu, NEW.pwd_stu, NEW.name_stu, NEW.surname_stu, NEW.url_img_stu, NEW.gender_stu, NEW.lang_stu, NEW.attributes_stu);
INSERT OR REPLACE INTO supervisor VALUES (NEW.id_sup, NEW.email_sup, NEW.pwd_sup, NEW.name_sup, NEW.surname_sup, NEW.url_img_sup, NEW.gender_sup, NEW.lang_sup, NEW.tts_engine_sup); INSERT OR REPLACE INTO supervisor VALUES (NEW.id_sup, NEW.email_sup, NEW.pwd_sup, NEW.name_sup, NEW.surname_sup, NEW.url_img_sup, NEW.gender_sup, NEW.lang_sup, NEW.tts_engine_sup);
...@@ -204,7 +204,7 @@ BEGIN ...@@ -204,7 +204,7 @@ BEGIN
END END
;-- ;--
CREATE TRIGGER trg_insert_users_detail_knonwstudent CREATE TRIGGER trg_insert_users_detail_as_sup
INSTEAD OF INSERT ON users_detail INSTEAD OF INSERT ON users_detail
FOR EACH ROW FOR EACH ROW
WHEN NEW.pwd_stu IS NULL WHEN NEW.pwd_stu IS NULL
......
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