Editar picto de escena desde PCB funcionando con los websockets

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