Editar picto de escena desde PCB funcionando con los websockets

parent 46eab3b8
......@@ -40,7 +40,7 @@ public abstract class Action {
public JSONObject get_json() {
final String param_id_stu="id_stu";
final String param_id_sup="id_sup";
final String param_id_dev="id_dev";
final String param_id_scene="id_scene";
final String param_timestamp="timestamp";
final Date currentTime = new Date();
SimpleDateFormat datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
......@@ -49,8 +49,10 @@ public abstract class Action {
.put(param_id_stu, PCBcontext.getPcbdb().getCurrentUser().get_id_stu())
.put(param_timestamp, datetime.format(currentTime));
Log.d("TIMESTAMP-----------> ", datetime.format(currentTime));
if (PCBcontext.getPcbdb().getCurrentUser().has_supervisor())
jsonObject.put(param_id_sup,PCBcontext.getPcbdb().getCurrentUser().get_id_sup());
if (PCBcontext.getPcbdb().getCurrentUser().has_supervisor()) {
jsonObject.put(param_id_sup, PCBcontext.getPcbdb().getCurrentUser().get_id_sup());
jsonObject.put(param_id_scene, PCBcontext.getPcbdb().getCurrentUser().get_active_scene());
}
//TODO Decidir qué almacenar con DEVICE
//if (PCBcontext.getDevice().getDeviceID()!=null)
//jsonObject.put(param_id_dev, PCBcontext.getDevice().getDeviceID());
......
......@@ -301,31 +301,33 @@ public class Device extends SQLiteOpenHelper {
}
public void insertUser(User user) {
Log.e(LOG_TAG,"LLAMA A INSERT USER");
SQLiteDatabase db = this.getWritableDatabase();
db.beginTransaction();
db.execSQL("INSERT INTO users_detail values (" +
user.get_id_stu() + ", " +
"'" + user.get_nickname_stu() + "', " +
(user.get_pwd_stu()==null || user.get_pwd_stu().length()==0 ? "NULL" : "'"+user.get_pwd_stu()+"'") + ", "+
"'" + user.get_name_stu() + "', " +
"'" + user.get_surname_stu() + "', "
+ user.get_active_scene() + ", " +
"'" + user.get_url_img_stu() + "', " +
"'" + user.get_gender_stu() + "', " +
"'" + user.get_lang_stu() + "', " +
"'" + user.get_json_attrs() + "', " +
"'" + user.get_id_sup() + "', " +
"'" + user.get_email_sup() + "', " +
"'" + user.get_pwd_sup() + "', " +
"'" + user.get_name_sup() + "', " +
"'" + user.get_surname_sup() + "', " +
"'" + user.get_url_img_sup() + "'," +
"'" + user.get_gender_sup() + "'," +
"'" + user.get_lang_sup() + "'," +
"'" + user.get_tts_engine_sup() + "'," +
"'" + user.get_office() + "'" +
")");
String sentence = "INSERT INTO users_detail values (" +
user.get_id_stu() + ", " +
"'" + user.get_nickname_stu() + "', " +
(user.get_pwd_stu()==null || user.get_pwd_stu().length()==0 ? "NULL" : "'"+user.get_pwd_stu()+"'") + ", "+
"'" + user.get_name_stu() + "', " +
"'" + user.get_surname_stu() + "', "
+ user.get_active_scene() + ", " +
"'" + user.get_url_img_stu() + "', " +
"'" + user.get_gender_stu() + "', " +
"'" + user.get_lang_stu() + "', " +
"'" + user.get_json_attrs() + "', " +
"'" + user.get_id_sup() + "', " +
"'" + user.get_email_sup() + "', " +
"'" + user.get_pwd_sup() + "', " +
"'" + user.get_name_sup() + "', " +
"'" + user.get_surname_sup() + "', " +
"'" + user.get_url_img_sup() + "'," +
"'" + user.get_gender_sup() + "'," +
"'" + user.get_lang_sup() + "'," +
"'" + user.get_tts_engine_sup() + "'," +
"'" + user.get_office() + "'" +
")";
db.execSQL(sentence);
Log.e(LOG_TAG,"LLAMA A INSERT USER->"+sentence);
db.setTransactionSuccessful();
db.endTransaction();
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
......
......@@ -34,10 +34,10 @@ public class Picto extends Img {
public int get_stupicto_id() {
int stupicto_id;
try {
stupicto_id=this.attributes.getInt(JSON_ATTTRS.STUPICTO_ID);
return this.attributes.getInt(JSON_ATTTRS.STUPICTO_ID);
} catch (JSONException e) {
e.printStackTrace();
stupicto_id=STUPICTO_NULL ;
stupicto_id = STUPICTO_NULL ;
}
return stupicto_id;
}
......@@ -471,7 +471,7 @@ public class Picto extends Img {
* @return true if current status is enabled. False in other case.
*/
public boolean alter_status(String status) {
Log.i(LOG_TAG,"Picto id. "+get_id()+" status enabled/disabled modified to "+is_enabled());
Log.i(LOG_TAG,"Picto id. "+get_stupicto_id()+" status enabled/disabled modified to "+is_enabled());
try {
this.attributes.put(JSON_ATTTRS.STATUS, status);
set_local_status(true);
......@@ -500,7 +500,6 @@ public class Picto extends Img {
public void set_local_status(boolean local) {
if (local)
try {
this.attributes.remove(JSON_ATTTRS.STUPICTO_ID);
this.attributes.put(JSON_ATTTRS.PCB_STATUS_MODIFICATION, true);
PCBcontext.getPcbdb().modifyPicto(this.get_id(), this.get_json_attrs());
} catch (JSONException e) {
......
......@@ -5,6 +5,7 @@ import android.util.Log;
import com.yottacode.net.RestapiWrapper;
import com.yottacode.pictogram.R;
import com.yottacode.pictogram.action.PictoAction;
import com.yottacode.pictogram.action.VocabularyAction;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.net.ImgDownloader;
......@@ -195,7 +196,7 @@ public class Vocabulary implements Iterable<Picto> {
setHas_categories(result.getBoolean("categories"));
setId_scene(result.getInt("id"));
//PCBcontext.getPcbdb().getCurrentUser().set_active_scene(result.getInt("id"));
JSONArray stu_pictos = result.getJSONArray("pictos"); //Obtengo el JSONArray de los pictos
JSONArray stu_pictos = result.getJSONArray("pictos"); //Obtengo el JSONArray de los stupictos
Picto[] pictos = new Picto[stu_pictos.length()];
for (int i = 0; i < stu_pictos.length(); i++) {
......@@ -203,6 +204,7 @@ public class Vocabulary implements Iterable<Picto> {
picto = stupicto.getJSONObject("picto");
attributes = stupicto.getJSONObject("attributes");
attributes.put(Picto.JSON_ATTTRS.STUPICTO_ID, stupicto.getInt("id"));
//OK AQUI Log.i("TAG_PRUEBAS","stupictoid: "+stupicto.getInt("id")+"--PictoId: "+picto.getInt("id"));
pictos[i] = new Picto(picto.getInt("id"),
picto.getString("uri"),
attributes);
......@@ -264,6 +266,7 @@ public class Vocabulary implements Iterable<Picto> {
pictos_cat.add(picto);
imgs.add(picto);
}
Log.d(this.getClass().getName(), "Vocabulary size: " + updated_collection.length);
ImgDownloader downloader = new ImgDownloader(PCBcontext.getContext(), imgListener,ImgDownloader.tsource.remote);
downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, imgs);
......@@ -437,7 +440,7 @@ public class Vocabulary implements Iterable<Picto> {
public void saveLocalPicto(String url, String exp, int cat, int coord_x, int coord_y, int free_category_coord_x, int free_category_coord_y,String user_avatar, String path_sound,final iLocalPicto listener) {
Picto prev_picto=PCBcontext.getVocabulary().has_categories() ? find_picto(cat, coord_x,coord_y) : find_picto(free_category_coord_x,free_category_coord_y); //¿estamos reemplazanddo un picto que ya existe?
Picto prev_picto=PCBcontext.getVocabulary().has_categories() ? find_picto(cat, coord_x,coord_y) : find_picto(free_category_coord_x,free_category_coord_y);//¿estamos reemplazanddo un picto que ya existe?
if (prev_picto!=null) { //El picto ya existe
removePicto(prev_picto.get_category(),prev_picto.get_id()); //borramos el picto local actual
......@@ -446,7 +449,7 @@ public class Vocabulary implements Iterable<Picto> {
int id=PCBcontext.getDevice().getNextLocalPictoID();
try {
final Picto picto = new Picto(id, url, exp, cat, coord_x, coord_y, free_category_coord_x, free_category_coord_y,prev_picto!=null ? prev_picto.get_stupicto_id() : Picto.STUPICTO_NULL,user_avatar/*, prev_picto.get_id_scene()*/);
final Picto picto = new Picto(id, url, exp, cat, coord_x, coord_y, free_category_coord_x, free_category_coord_y,prev_picto!=null ? prev_picto.get_stupicto_id() : Picto.STUPICTO_NULL,user_avatar);
if (path_sound!=null)
new File(path_sound).renameTo(new File(picto.get_audioPath()));
......
......@@ -320,12 +320,13 @@ public class PictoUploader {
public void uploadState( ){
Hashtable<String, String> params = new Hashtable<String, String>(1);
Log.i(LOG_TAG,"Picto con id stupicto: "+picto.get_stupicto_id());
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()));
params.put("id_scene" , Integer.toString(PCBcontext.getPcbdb().getCurrentUser().get_active_scene()));
//params.put("id_pic", Integer.toString(this.picto.get_id()));
//params.put("id_scene" , Integer.toString(PCBcontext.getPcbdb().getCurrentUser().get_active_scene()));
//params.put("id_stuPicto", Integer.toString(this.picto.get_stupicto_id()));
params.put("id_stuPicto", Integer.toString(this.picto.get_stupicto_id()));
Log.i(LOG_TAG, "Picto "+ this.picto.get_id()+" stupicto id:"+this.picto.get_stupicto_id()+" Uploading " + params.toString());
PCBcontext.getRestapiWrapper().ask(
PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu() + "/picto",
......
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