issue #484 closed. Working on bug #476

parent 94053c8f
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" /> <excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content> </content>
<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" /> <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>
\ No newline at end of file
...@@ -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
...@@ -115,11 +115,13 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -115,11 +115,13 @@ public class Vocabulary implements Iterable<Picto> {
for (Picto picto: this) { for (Picto picto: this) {
if (picto.local_status()) { if (picto.local_status()) {
new PictoUploader(picto).uploadState(); new PictoUploader(picto).uploadState();
Log.i(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto translation: '" + Log.i(this.getClass().getCanonicalName(), "server BORRA 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.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(), "server BORRA Picto status modified 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;
......
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