Escenas funcionando en PCB, a falta de arreglar el issue #209

parent 7cc915b7
...@@ -172,7 +172,7 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -172,7 +172,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
Log.i(LOG_TAG,"Scene to be inserted: "+sql_scene); Log.i(LOG_TAG,"Scene to be inserted: "+sql_scene);
getWritableDatabase().execSQL(sql_scene); getWritableDatabase().execSQL(sql_scene);
//Added //Added
PCBcontext.getVocabulary().setId_scene(params.getInt("id"));
PCBcontext.getPcbdb().getCurrentUser().set_active_scene(params.getInt("id")); PCBcontext.getPcbdb().getCurrentUser().set_active_scene(params.getInt("id"));
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -210,7 +210,7 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -210,7 +210,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
Log.i(LOG_TAG, "Local recovering " + cursor.getCount() + " pictos for student " + id_stu + " from local DB"); Log.i(LOG_TAG, "Local recovering " + cursor.getCount() + " pictos for student " + id_stu + " from local DB");
cursor.moveToFirst(); cursor.moveToFirst();
if (cursor.getCount()>0) do{ if (cursor.getCount()>0) do{
Picto picto = new Picto(cursor.getInt(1), cursor.getString(3), cursor.getString(4), cursor.getString(5)); Picto picto = new Picto(cursor.getInt(1), cursor.getString(4), cursor.getInt(3), new JSONObject(cursor.getString(6)));
vocabulary.addPicto(picto); vocabulary.addPicto(picto);
}while (cursor.moveToNext()); }while (cursor.moveToNext());
cursor.close(); cursor.close();
...@@ -230,7 +230,7 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -230,7 +230,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
int id_stu = this.getCurrentUser().get_id_stu(); int id_stu = this.getCurrentUser().get_id_stu();
db.delete("collection", "id_stu=" + id_stu, null); db.delete("collection", "id_stu=" + id_stu, null);
ContentValues values=new ContentValues(6); ContentValues values=new ContentValues(7);
values.put("id_stu", id_stu); values.put("id_stu", id_stu);
db.beginTransaction(); db.beginTransaction();
for (Picto picto : vocabulary) { for (Picto picto : vocabulary) {
...@@ -238,7 +238,8 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -238,7 +238,8 @@ public class PCBDBHelper extends SQLiteOpenHelper {
values.put("id_picto", picto.get_id()); values.put("id_picto", picto.get_id());
values.put("id_scene", vocabulary.getId_scene()); values.put("id_scene", PCBcontext.getPcbdb().getCurrentUser().get_active_scene());
values.put("id_stupicto", picto.get_stupicto_id());
values.put("url", picto.get_url()); values.put("url", picto.get_url());
values.put("translation",picto.get_translation()); values.put("translation",picto.get_translation());
values.put("attributes",picto.get_json_attrs()); values.put("attributes",picto.get_json_attrs());
...@@ -263,7 +264,8 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -263,7 +264,8 @@ public class PCBDBHelper extends SQLiteOpenHelper {
values.put("id_stu", id_stu); values.put("id_stu", id_stu);
values.put("id_picto", picto.get_id()); values.put("id_picto", picto.get_id());
//TODO: Añadir aqui el id de escena activa para el estudiante //TODO: Añadir aqui el id de escena activa para el estudiante
values.put("id_scene",getActiveSceneForStudent(id_stu)); values.put("id_scene",PCBcontext.getPcbdb().getCurrentUser().get_active_scene());
values.put("id_stupicto",picto.get_stupicto_id());
values.put("url", picto.get_url()); values.put("url", picto.get_url());
values.put("translation",picto.get_translation()); values.put("translation",picto.get_translation());
values.put("attributes",picto.get_json_attrs()); values.put("attributes",picto.get_json_attrs());
...@@ -284,7 +286,7 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -284,7 +286,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
db.delete("collection","id_stu=? AND id_picto=? AND id_scene=?", db.delete("collection","id_stu=? AND id_picto=? AND id_scene=?",
new String[]{ Integer.toString(this.currentUser.get_id_stu()), new String[]{ Integer.toString(this.currentUser.get_id_stu()),
Integer.toString(picto_id), Integer.toString(picto_id),
Integer.toString(getActiveSceneForStudent(this.currentUser.get_id_stu()))}); Integer.toString(this.currentUser.get_active_scene())});
//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
} }
...@@ -297,13 +299,13 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -297,13 +299,13 @@ public class PCBDBHelper extends SQLiteOpenHelper {
*/ */
public void modifyPicto(int picto_id, String attrs) { public void modifyPicto(int picto_id, String attrs) {
int id_stu = this.getCurrentUser().get_id_stu(); int id_stu = this.getCurrentUser().get_id_stu();
int id_scene = this.getCurrentUser().get_active_scene();
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues(1); ContentValues values = new ContentValues(1);
values.put("attributes",attrs); values.put("attributes",attrs);
//TODO: Añadir aqui el id de escena activa para el estudiante
int updates=db.update("collection",values, "id_stu=? AND id_picto=? AND id_scene=?", new String[] {Integer.toString(id_stu), int updates=db.update("collection",values, "id_stu=? AND id_picto=? AND id_scene=?", new String[] {Integer.toString(id_stu),
Integer.toString(picto_id), Integer.toString(picto_id),
Integer.toString(getActiveSceneForStudent(this.currentUser.get_id_stu()))}); Integer.toString(id_scene)});
Log.i(this.getClass().getCanonicalName(),"Modify "+updates+" Picto, id. "+picto_id+" attributes="+attrs);//+ "::"+ Arrays.toString(Thread.currentThread().getStackTrace())); Log.i(this.getClass().getCanonicalName(),"Modify "+updates+" Picto, id. "+picto_id+" attributes="+attrs);//+ "::"+ Arrays.toString(Thread.currentThread().getStackTrace()));
//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
} }
......
...@@ -31,15 +31,19 @@ public class Picto extends Img { ...@@ -31,15 +31,19 @@ public class Picto extends Img {
public static final int STUPICTO_NULL = -1; public static final int STUPICTO_NULL = -1;
public void set_stupicto_id(int id){
this.id_stupicto = id;
}
public int get_stupicto_id() { public int get_stupicto_id() {
int stupicto_id; /*int stupicto_id;
try { try {
return 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 id_stupicto;
} }
public final static class JSON_ATTTRS { public final static class JSON_ATTTRS {
...@@ -76,7 +80,7 @@ public class Picto extends Img { ...@@ -76,7 +80,7 @@ public class Picto extends Img {
public final static int COL_UNCATEGORIZED_CONCEPTS=0; public final static int COL_UNCATEGORIZED_CONCEPTS=0;
private int id_stupicto;
private JSONObject attributes; private JSONObject attributes;
private boolean is_mirror=false; private boolean is_mirror=false;
private boolean highlight_background=false; private boolean highlight_background=false;
...@@ -96,8 +100,8 @@ public class Picto extends Img { ...@@ -96,8 +100,8 @@ public class Picto extends Img {
Log.e(LOG_TAG,e.getMessage()); Log.e(LOG_TAG,e.getMessage());
} }
} }
public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn, int stupicto_id, String user_avatar/*, int scene*/) throws JSONException { public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn, int stupicto_id, String user_avatar) throws JSONException {
this(id, url, new JSONObject() this(id, url,stupicto_id, new JSONObject()
.put(JSON_ATTTRS.CATEGORY, cat) .put(JSON_ATTTRS.CATEGORY, cat)
.put(JSON_ATTTRS.COLUMN, column) .put(JSON_ATTTRS.COLUMN, column)
.put(JSON_ATTTRS.ROW, row) .put(JSON_ATTTRS.ROW, row)
...@@ -110,13 +114,14 @@ public class Picto extends Img { ...@@ -110,13 +114,14 @@ public class Picto extends Img {
.put(JSON_ATTTRS.USER_AVATAR,user_avatar) .put(JSON_ATTTRS.USER_AVATAR,user_avatar)
); );
} }
public Picto(int id, String url,String translation, String attributes) throws JSONException { public Picto(int id, String url,int id_stupicto, String translation, String attributes) throws JSONException {
this(id, url, new JSONObject(attributes).put(JSON_ATTTRS.EXPRESSION,translation)); this(id, url,id_stupicto, new JSONObject(attributes).put(JSON_ATTTRS.EXPRESSION,translation));
} }
public Picto(int id, String url, JSONObject attributes) { public Picto(int id, String url,int id_stupicto, JSONObject attributes) {
super(id,url,Img.VOCABULARY); super(id,url,Img.VOCABULARY);
this.id_stupicto = id_stupicto;
this.attributes = attributes; this.attributes = attributes;
try { try {
if (this.attributes.get(JSON_ATTTRS.CATEGORY)==null) if (this.attributes.get(JSON_ATTTRS.CATEGORY)==null)
......
...@@ -263,12 +263,12 @@ public class User { ...@@ -263,12 +263,12 @@ public class User {
} }
public void set_active_scene(int id) { public void set_active_scene(int id) {
try { //try {
this.id_scene_stu = id; this.id_scene_stu = id;
this.attributes_stu.put(JSON_STUDENT_ATTTRS.ID_ACTIVE_SCENE,id); //this.attributes_stu.put(JSON_STUDENT_ATTTRS.ID_ACTIVE_SCENE,id);
} catch (JSONException e) { /*} catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }*/
} }
/** /**
* *
......
...@@ -38,7 +38,6 @@ import java.util.Vector; ...@@ -38,7 +38,6 @@ import java.util.Vector;
public class Vocabulary implements Iterable<Picto> { public class Vocabulary implements Iterable<Picto> {
private boolean has_categories; private boolean has_categories;
private int id_scene;
private static final String LOG_TAG = Vocabulary.class.getName(); private static final String LOG_TAG = Vocabulary.class.getName();
Hashtable<Integer,LinkedList<Picto>> pictos; Hashtable<Integer,LinkedList<Picto>> pictos;
static int DEFAULT_VOCABULARY_SIZE=200; static int DEFAULT_VOCABULARY_SIZE=200;
...@@ -75,9 +74,11 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -75,9 +74,11 @@ public class Vocabulary implements Iterable<Picto> {
removePicto(picto_cat, picto_id); removePicto(picto_cat, picto_id);
break; break;
} }
case update:{ case update:{
Log.i(this.getClass().getCanonicalName(), "Picto update "+args.toString()); Log.i(this.getClass().getCanonicalName(), "Picto update "+args.toString());
try { try {
Log.i("TAG_PRUEBAS","Mensaje update: "+args.getJSONObject("attributes").toString());
modifyAttsPicto(picto_cat, picto_id, args.getJSONObject("attributes")); modifyAttsPicto(picto_cat, picto_id, args.getJSONObject("attributes"));
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -95,7 +96,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -95,7 +96,7 @@ public class Vocabulary implements Iterable<Picto> {
String uri=args.getJSONObject("picto").getString("uri"); String uri=args.getJSONObject("picto").getString("uri");
JSONObject attrs_picto = args.getJSONObject("attributes"); JSONObject attrs_picto = args.getJSONObject("attributes");
attrs_picto.put(Picto.JSON_ATTTRS.STUPICTO_ID,args.getInt("id")); attrs_picto.put(Picto.JSON_ATTTRS.STUPICTO_ID,args.getInt("id"));
Picto newPicto=new Picto(picto_id, uri, attrs_picto); Picto newPicto=new Picto(picto_id, uri,args.getInt("id"), attrs_picto);
Picto prev_picto=PCBcontext.getVocabulary().has_categories() Picto prev_picto=PCBcontext.getVocabulary().has_categories()
? find_picto(newPicto.get_category(), newPicto.get_row(),newPicto.get_column()) ? find_picto(newPicto.get_category(), newPicto.get_row(),newPicto.get_column())
: find_picto(newPicto.getFreeRow(),newPicto.getFreeColumn()); : find_picto(newPicto.getFreeRow(),newPicto.getFreeColumn());
...@@ -194,7 +195,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -194,7 +195,7 @@ public class Vocabulary implements Iterable<Picto> {
JSONObject stupicto = null; JSONObject stupicto = null;
try { try {
setHas_categories(result.getBoolean("categories")); setHas_categories(result.getBoolean("categories"));
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 stupictos 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()];
...@@ -207,6 +208,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -207,6 +208,7 @@ public class Vocabulary implements Iterable<Picto> {
//OK AQUI Log.i("TAG_PRUEBAS","stupictoid: "+stupicto.getInt("id")+"--PictoId: "+picto.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"),
stupicto.getInt("id"),
attributes); attributes);
} }
synchronizeImgs(pictos); synchronizeImgs(pictos);
...@@ -254,6 +256,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -254,6 +256,7 @@ public class Vocabulary implements Iterable<Picto> {
LinkedList<Picto> pictos_cat; LinkedList<Picto> pictos_cat;
Picto picto = new Picto(updated_picto.get_id(), Picto picto = new Picto(updated_picto.get_id(),
updated_picto.get_url(), updated_picto.get_url(),
updated_picto.get_stupicto_id(),
updated_picto.get_translation(), updated_picto.get_translation(),
updated_picto.get_json_attrs()); updated_picto.get_json_attrs());
if (pictos.containsKey(picto.get_category())) { if (pictos.containsKey(picto.get_category())) {
...@@ -518,11 +521,4 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -518,11 +521,4 @@ public class Vocabulary implements Iterable<Picto> {
this.has_categories = has_categories; this.has_categories = has_categories;
} }
public int getId_scene() {
return id_scene;
}
public void setId_scene(int id_scene) {
this.id_scene = id_scene;
}
} }
...@@ -158,8 +158,8 @@ public class PictoUploader { ...@@ -158,8 +158,8 @@ public class PictoUploader {
json_attrs.put(Picto.JSON_ATTTRS.CATEGORY, picto.NO_CATEGORY) json_attrs.put(Picto.JSON_ATTTRS.CATEGORY, picto.NO_CATEGORY)
.put(Picto.JSON_ATTTRS.FREE_COLUMN, picto.getFreeColumn()) .put(Picto.JSON_ATTTRS.FREE_COLUMN, picto.getFreeColumn())
.put(Picto.JSON_ATTTRS.FREE_ROW, picto.getFreeRow()); .put(Picto.JSON_ATTTRS.FREE_ROW, picto.getFreeRow());
params.put("json", new JSONObject().put("attributes",json_attrs).put("id_scene",PCBcontext.getPcbdb().getActiveSceneForStudent(PCBcontext.getPcbdb().getCurrentUser().get_id_stu())).toString()); //params.put("json", new JSONObject().put("attributes",json_attrs).put("id_scene",PCBcontext.getPcbdb().getActiveSceneForStudent(PCBcontext.getPcbdb().getCurrentUser().get_id_stu())).toString());
params.put("id_scene", String.valueOf(PCBcontext.getPcbdb().getCurrentUser().get_active_scene()));
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
Log.e(LOG_TAG, " Error: " + e.getLocalizedMessage()); Log.e(LOG_TAG, " Error: " + e.getLocalizedMessage());
......
...@@ -53,7 +53,7 @@ public class VocabularyTalk implements Emitter.Listener { ...@@ -53,7 +53,7 @@ public class VocabularyTalk implements Emitter.Listener {
JSONObject picto_stupicto = stu_picto.optJSONObject(param_picto); JSONObject picto_stupicto = stu_picto.optJSONObject(param_picto);
int picto_id = picto_stupicto.getInt(param_picto_id); int picto_id = picto_stupicto.getInt(param_picto_id);
int picto_cat = attrs_stu_picto!=null ? attrs_stu_picto.optInt(param_picto_cat, Picto.NO_CATEGORY) : 0; int picto_cat = attrs_stu_picto!=null ? attrs_stu_picto.optInt(param_picto_cat, Picto.NO_CATEGORY) : 0;
if(PCBcontext.getVocabulary().getId_scene() == msg.getJSONObject("attributes").getInt("id_scene")) { if(PCBcontext.getPcbdb().getCurrentUser().get_active_scene() == msg.getJSONObject("attributes").getInt("id_scene")) {
PCBcontext.getNetService().nextSynchro(new Date().getTime() + PCBcontext.getNetService().getSynchroTimingLength() * 2); //nos saltamos una sincronización para evitar que llegue antes que los websockets PCBcontext.getNetService().nextSynchro(new Date().getTime() + PCBcontext.getNetService().getSynchroTimingLength() * 2); //nos saltamos una sincronización para evitar que llegue antes que los websockets
Log.i(LOG_TAG, "Received message '" + action + Log.i(LOG_TAG, "Received message '" + action +
"' for picto " + picto_id + " (cat " + picto_cat + ", picto: " + picto_stupicto); "' for picto " + picto_id + " (cat " + picto_cat + ", picto: " + picto_stupicto);
......
...@@ -76,11 +76,12 @@ public final class PCBcontext { ...@@ -76,11 +76,12 @@ public final class PCBcontext {
studentTalk=new StudentTalk(room, new StudentTalk.iStudentListener[] {new StudentTalk.iStudentListener() { studentTalk=new StudentTalk(room, new StudentTalk.iStudentListener[] {new StudentTalk.iStudentListener() {
@Override @Override
public void change(User updatedStudent) { public void change(User updatedStudent) {
//ID ANTIGUO
PCBcontext.getDevice().insertUser(updatedStudent); PCBcontext.getDevice().insertUser(updatedStudent);
Log.i("TAG_PRUEBAS","ID_SCENE_VOCAB: "+PCBcontext.getVocabulary().getId_scene()+ //ID NUEVO
"ID_SCENE_USER: "+PCBcontext.getPcbdb().getCurrentUser().get_active_scene()); Log.i("TAG_PRUEBAS","nuevo: "+ updatedStudent.get_active_scene() +"--Anterior: "+PCBcontext.getPcbdb().getCurrentUser().get_active_scene());
if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big() || PCBcontext.getVocabulary().has_categories() != vocabulary.has_categories() if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big() || PCBcontext.getVocabulary().has_categories() != vocabulary.has_categories()
|| PCBcontext.getVocabulary().getId_scene()!= PCBcontext.getPcbdb().getCurrentUser().get_active_scene()) { || updatedStudent.get_active_scene() != PCBcontext.getPcbdb().getCurrentUser().get_active_scene()) {
PCBcontext.getNetService().restart_app(false); PCBcontext.getNetService().restart_app(false);
}else { }else {
......
...@@ -89,6 +89,7 @@ CREATE TABLE collection ( ...@@ -89,6 +89,7 @@ CREATE TABLE collection (
id_stu INTEGER NOT NULL REFERENCES student ON DELETE CASCADE, id_stu INTEGER NOT NULL REFERENCES student ON DELETE CASCADE,
id_picto INTEGER NOT NULL REFERENCES picto ON DELETE CASCADE, id_picto INTEGER NOT NULL REFERENCES picto ON DELETE CASCADE,
id_scene INTEGER NOT NULL REFERENCES scene ON DELETE CASCADE, id_scene INTEGER NOT NULL REFERENCES scene ON DELETE CASCADE,
id_stupicto INTEGER NOT NULL,
attributes VARCHAR(1024), attributes VARCHAR(1024),
constraint ck_collection UNIQUE(id_stu,id_picto,id_scene) constraint ck_collection UNIQUE(id_stu,id_picto,id_scene)
) )
...@@ -159,7 +160,7 @@ DROP VIEW IF EXISTS collection_detail ...@@ -159,7 +160,7 @@ DROP VIEW IF EXISTS collection_detail
;-- ;--
CREATE VIEW collection_detail AS CREATE VIEW collection_detail AS
SELECT id_stu, id_picto, id_scene, b.url, translation, attributes SELECT id_stu, id_picto, id_scene, id_stupicto, b.url, translation, attributes
FROM collection a, picto b FROM collection a, picto b
WHERE a.id_picto=b.id WHERE a.id_picto=b.id
;-- ;--
...@@ -360,6 +361,6 @@ INSTEAD OF INSERT ON collection_detail ...@@ -360,6 +361,6 @@ INSTEAD OF INSERT ON collection_detail
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
INSERT OR REPLACE INTO picto VALUES (NEW.id_picto,NEW.url, NEW.translation); INSERT OR REPLACE INTO picto VALUES (NEW.id_picto,NEW.url, NEW.translation);
INSERT INTO collection VALUES (NEW.id_stu,NEW.id_picto,NEW.id_scene,NEW.attributes); INSERT INTO collection VALUES (NEW.id_stu,NEW.id_picto,NEW.id_scene,NEW.id_stupicto,NEW.attributes);
END END
;-- ;--
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