Working on alter status from pcb when offline

parent 3b732ed6
......@@ -52,7 +52,7 @@ public abstract class Action {
jsonObject.put(param_id_sup,PCBcontext.getPcbdb().getCurrentUser().get_id_sup());
//TODO Decidir qué almacenar con DEVICE
//if (PCBcontext.getDevice().getDeviceID()!=null)
jsonObject.put(param_id_dev, "-1");
//jsonObject.put(param_id_dev, PCBcontext.getDevice().getDeviceID());
return jsonObject;
}catch(JSONException e) {
......
......@@ -50,11 +50,17 @@ public class ActionLog implements iRestapiListener {
if (!actions_buffer.isEmpty()) {
Hashtable<String, String> params=new Hashtable<>(1);
String url="stu/actions_batch";
String actions="";
JSONArray actions= new JSONArray();
for (JSONObject action: actions_buffer)
actions+=","+action.toString();
actions= "{actions: [" + actions.substring(1) + "]}";
params.put("json",actions);
actions.put(action);
//actions= "{actions: [" + actions.substring(1) + "]}";
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);
PCBcontext.getRestapiWrapper().ask(url, params, "post", true, this);
}
......
......@@ -266,7 +266,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
ContentValues values = new ContentValues(1);
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)});
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();
}
......
......@@ -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 {
return this.attributes.getString(attr);
json = new JSONObject(this.attributes.toString());
} catch (JSONException e) {
return null;
e.printStackTrace();
}
json.remove(JSON_ATTTRS.PCB_STATUS_MODIFICATION);
return json.toString();
}
/**
* Set JSON attribute of the picto
......@@ -318,6 +322,7 @@ public class Picto extends Img {
*/
public boolean alter_status() {
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 {
this.attributes.put(JSON_ATTTRS.STATUS, status);
status_modified(true);
......
......@@ -106,8 +106,8 @@ public class Vocabulary implements Iterable<Picto> {
for (Picto picto: this) {
if (picto.status_modified()) {
new PictoUploader(picto).uploadState();
Log.e(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto: " +
picto.get_translation() + ":" + picto.get_id() + " Current status:" + picto.status_modified());
Log.i(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto label: " +
picto.get_translation() + ", id:" + picto.get_id() + " Current status:" + picto.status_modified());
}
if (picto.get_id() < 0)
try {
......
......@@ -180,7 +180,7 @@ public class PictoUploader {
public void uploadState( ){
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_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