Working on alter status from pcb when offline

parent 3b732ed6
...@@ -52,7 +52,7 @@ public abstract class Action { ...@@ -52,7 +52,7 @@ public abstract class Action {
jsonObject.put(param_id_sup,PCBcontext.getPcbdb().getCurrentUser().get_id_sup()); jsonObject.put(param_id_sup,PCBcontext.getPcbdb().getCurrentUser().get_id_sup());
//TODO Decidir qué almacenar con DEVICE //TODO Decidir qué almacenar con DEVICE
//if (PCBcontext.getDevice().getDeviceID()!=null) //if (PCBcontext.getDevice().getDeviceID()!=null)
jsonObject.put(param_id_dev, "-1"); //jsonObject.put(param_id_dev, PCBcontext.getDevice().getDeviceID());
return jsonObject; return jsonObject;
}catch(JSONException e) { }catch(JSONException e) {
......
...@@ -50,11 +50,17 @@ public class ActionLog implements iRestapiListener { ...@@ -50,11 +50,17 @@ public class ActionLog implements iRestapiListener {
if (!actions_buffer.isEmpty()) { if (!actions_buffer.isEmpty()) {
Hashtable<String, String> params=new Hashtable<>(1); Hashtable<String, String> params=new Hashtable<>(1);
String url="stu/actions_batch"; String url="stu/actions_batch";
String actions=""; JSONArray actions= new JSONArray();
for (JSONObject action: actions_buffer) for (JSONObject action: actions_buffer)
actions+=","+action.toString(); actions.put(action);
actions= "{actions: [" + actions.substring(1) + "]}"; //actions= "{actions: [" + actions.substring(1) + "]}";
params.put("json",actions); try {
params.put("json",new JSONObject().put("actions",actions).toString());
} catch (JSONException e) {
e.printStackTrace();
Log.e(this.getClass().getCanonicalName(), " Batch action error: " + e.getMessage());
}
Log.i(this.getClass().getCanonicalName()," Sending batch actions: "+url+": "+actions); Log.i(this.getClass().getCanonicalName()," Sending batch actions: "+url+": "+actions);
PCBcontext.getRestapiWrapper().ask(url, params, "post", true, this); PCBcontext.getRestapiWrapper().ask(url, params, "post", true, this);
} }
......
...@@ -266,7 +266,7 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -266,7 +266,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
ContentValues values = new ContentValues(1); ContentValues values = new ContentValues(1);
values.put("attributes",attrs); values.put("attributes",attrs);
int updates=db.update("collection",values, "id_stu=? AND id_picto=?", new String[] {Integer.toString(id_stu), Integer.toString(picto_id)}); int updates=db.update("collection",values, "id_stu=? AND id_picto=?", new String[] {Integer.toString(id_stu), Integer.toString(picto_id)});
Log.i(this.getClass().getCanonicalName(),"Modify "+updates+" Picto attributes: "+picto_id+" attributes="+attrs); Log.i(this.getClass().getCanonicalName(),"Modify "+updates+" picto, id. "+picto_id+" attributes="+attrs);
db.close(); db.close();
} }
......
...@@ -102,15 +102,19 @@ public class Picto extends Img { ...@@ -102,15 +102,19 @@ public class Picto extends Img {
} }
/** /**
* JSON attribute of the picto * JSON attrs of the picto except the param regarding is locally modified since this is not saved into the server
*
* *
*/ */
public String get_json_attr(String attr) { public String get_json_server_attrs() {
JSONObject json = null;
try { try {
return this.attributes.getString(attr); json = new JSONObject(this.attributes.toString());
} catch (JSONException e) { } catch (JSONException e) {
return null; e.printStackTrace();
} }
json.remove(JSON_ATTTRS.PCB_STATUS_MODIFICATION);
return json.toString();
} }
/** /**
* Set JSON attribute of the picto * Set JSON attribute of the picto
...@@ -318,6 +322,7 @@ public class Picto extends Img { ...@@ -318,6 +322,7 @@ public class Picto extends Img {
*/ */
public boolean alter_status() { public boolean alter_status() {
String status=is_enabled() ? JSON_ATTTR_STATUS_VALUES.DISABLED : JSON_ATTTR_STATUS_VALUES.ENABLED; String status=is_enabled() ? JSON_ATTTR_STATUS_VALUES.DISABLED : JSON_ATTTR_STATUS_VALUES.ENABLED;
Log.i(this.getClass().getCanonicalName(),"Picto id. "+get_id()+" status enabled/disabled modified to "+is_enabled());
try { try {
this.attributes.put(JSON_ATTTRS.STATUS, status); this.attributes.put(JSON_ATTTRS.STATUS, status);
status_modified(true); status_modified(true);
......
...@@ -106,8 +106,8 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -106,8 +106,8 @@ public class Vocabulary implements Iterable<Picto> {
for (Picto picto: this) { for (Picto picto: this) {
if (picto.status_modified()) { if (picto.status_modified()) {
new PictoUploader(picto).uploadState(); new PictoUploader(picto).uploadState();
Log.e(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto: " + Log.i(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto label: " +
picto.get_translation() + ":" + picto.get_id() + " Current status:" + picto.status_modified()); picto.get_translation() + ", id:" + picto.get_id() + " Current status:" + picto.status_modified());
} }
if (picto.get_id() < 0) if (picto.get_id() < 0)
try { try {
......
...@@ -180,7 +180,7 @@ public class PictoUploader { ...@@ -180,7 +180,7 @@ public class PictoUploader {
public void uploadState( ){ public void uploadState( ){
Hashtable<String, String> params = new Hashtable<String, String>(1); Hashtable<String, String> params = new Hashtable<String, String>(1);
params.put("attributes", picto.get_json_attrs()); params.put("attributes", picto.get_json_server_attrs());
params.put("id_stu", Integer.toString(PCBcontext.getPcbdb().getCurrentUser().get_id_stu())); params.put("id_stu", Integer.toString(PCBcontext.getPcbdb().getCurrentUser().get_id_stu()));
params.put("id_pic", Integer.toString(this.picto.get_id())); params.put("id_pic", Integer.toString(this.picto.get_id()));
......
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