issues #471, #73, #474 closed

parent 44de29f5
...@@ -49,21 +49,7 @@ public class Room { ...@@ -49,21 +49,7 @@ public class Room {
final String attributes_param="attributes"; final String attributes_param="attributes";
return new JSONObject().put(action_param, action).put(attributes_param, attributes); return new JSONObject().put(action_param, action).put(attributes_param, attributes);
} }
/* public void emit(String url, final Action action) {
Log.i(this.getClass().getName(), "Action: " + action.get_type() + " / Attributes emitted: " + action.get_json().toString());
try{
this.socket.emit(url, this.common_data(action.get_type(), action.get_json()), new Ack() {
@Override
public void call(Object... args) {
Log.i(this.getClass().getName(), "Ack");
for (Object arg : args)
Log.i(this.getClass().getName(), "Ack messsage:" + arg);
}
});
} catch (JSONException e) {
Log.e(this.getClass().getCanonicalName(), e.getClass().getCanonicalName() + e.getMessage() + "--" + e.getLocalizedMessage());
}
}*/
public void emit(final Action action) { public void emit(final Action action) {
String token=PCBcontext.getRestapiWrapper().getToken(); String token=PCBcontext.getRestapiWrapper().getToken();
final String token_param="token"; final String token_param="token";
...@@ -122,6 +108,10 @@ public class Room { ...@@ -122,6 +108,10 @@ public class Room {
}catch (Exception e) { }catch (Exception e) {
Log.e(this.getClass().getCanonicalName(), e.getMessage()); Log.e(this.getClass().getCanonicalName(), e.getMessage());
} }
}
public void finalize() throws java.lang.Throwable {
super.finalize();
if (this.socket!=null) this.socket.destroy();
} }
} }
...@@ -234,7 +234,7 @@ public class Device extends SQLiteOpenHelper { ...@@ -234,7 +234,7 @@ public class Device extends SQLiteOpenHelper {
/** /**
* @param auser * @param auser
* @param apwd * @param apwd
* @return the information of an specific user, if they are available in the local DB * @return information of a specific user, if it is available in the local DB
*/ */
public Vector<User> findUser(String auser, String apwd) throws JSONException, LoginException { public Vector<User> findUser(String auser, String apwd) throws JSONException, LoginException {
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
...@@ -303,7 +303,7 @@ public class Device extends SQLiteOpenHelper { ...@@ -303,7 +303,7 @@ public class Device extends SQLiteOpenHelper {
db.execSQL("INSERT INTO users_detail values (" + db.execSQL("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 ? "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_url_img_stu() + "', " + "'" + user.get_url_img_stu() + "', " +
......
...@@ -69,7 +69,7 @@ public class LoginActivity extends FragmentActivity { ...@@ -69,7 +69,7 @@ public class LoginActivity extends FragmentActivity {
final Vector<Img> imgs = new Vector<>(1); final Vector<Img> imgs = new Vector<>(1);
imgs.add(new Img( imgs.add(new Img(
this.getIntent().getIntExtra("id", -1), this.getIntent().getIntExtra("sup_id", -1),
this.getIntent().getStringExtra("pic"), this.getIntent().getStringExtra("pic"),
Img.SUPERVISOR Img.SUPERVISOR
)); ));
...@@ -77,9 +77,10 @@ public class LoginActivity extends FragmentActivity { ...@@ -77,9 +77,10 @@ public class LoginActivity extends FragmentActivity {
@Override @Override
public void loadComplete() { public void loadComplete() {
try { try {
supervisorPhotoView.setImageBitmap( supervisorPhotoView.setImageBitmap(
imgs.get(0).get_bitmap(PCBcontext.getContext()) imgs.get(0).get_bitmap(PCBcontext.getContext())
); );
supervisorPhotoView.invalidate();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -600,7 +600,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -600,7 +600,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
Picto p = getCurrentPictoGridAdapter().getItem(position); Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p == null) { if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria // No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if (currentCategory != null) { if (currentCategory != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
Log.d(LOG_TAG, "No tengo pictograma. Abro carrete..."); Log.d(LOG_TAG, "No tengo pictograma. Abro carrete...");
int cols = getResources().getInteger(R.integer.columns); int cols = getResources().getInteger(R.integer.columns);
addPicto(position % cols, (int) (position / cols)); addPicto(position % cols, (int) (position / cols));
...@@ -714,6 +714,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -714,6 +714,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
count_deletelong++; count_deletelong++;
if (count_deletelong >= 3) { if (count_deletelong >= 3) {
PCBcontext.unset_user();
// Paso un parámetro a la SerialActivity, para controlar de dónde viene // Paso un parámetro a la SerialActivity, para controlar de dónde viene
Intent serialActivity = new Intent(getBaseContext(), SerialActivity.class); Intent serialActivity = new Intent(getBaseContext(), SerialActivity.class);
serialActivity.putExtra("resetPrevUser", true); serialActivity.putExtra("resetPrevUser", true);
...@@ -772,7 +773,9 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -772,7 +773,9 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
int cat = PictogramActivity.this.currentCategory != null ? PictogramActivity.this.currentCategory.get_id() : Picto.NO_CATEGORY; int cat = PictogramActivity.this.currentCategory != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories()
? PictogramActivity.this.currentCategory.get_id()
: Picto.NO_CATEGORY;
PCBcontext.getVocabulary().saveLocalPicto( PCBcontext.getVocabulary().saveLocalPicto(
selectedImagePath, selectedImagePath,
input.getText().toString(), input.getText().toString(),
......
...@@ -142,6 +142,9 @@ public class SerialActivity extends Activity { ...@@ -142,6 +142,9 @@ public class SerialActivity extends Activity {
} else { } else {
Intent loginActivity = new Intent(SerialActivity.this, LoginActivity.class); Intent loginActivity = new Intent(SerialActivity.this, LoginActivity.class);
loginActivity.putExtra("sup_id", localUsers.elementAt(0).get_id_sup()); loginActivity.putExtra("sup_id", localUsers.elementAt(0).get_id_sup());
loginActivity.putExtra("name", localUsers.elementAt(0).get_name_sup());
loginActivity.putExtra("surname", localUsers.elementAt(0).get_surname_sup());
loginActivity.putExtra("pic", localUsers.elementAt(0).get_url_img_sup());
loginActivity.putExtra("offline", true); loginActivity.putExtra("offline", true);
startActivity(loginActivity); startActivity(loginActivity);
} }
......
...@@ -152,7 +152,8 @@ public class NetService implements Runnable { ...@@ -152,7 +152,8 @@ public class NetService implements Runnable {
} }
}); });
} }
private void notifyStatus() {
public void notifyStatus() {
int notifyID = 1; int notifyID = 1;
String user=""; String user="";
if (PCBcontext.getPcbdb()!=null) { if (PCBcontext.getPcbdb()!=null) {
......
...@@ -68,7 +68,7 @@ public final class PCBcontext { ...@@ -68,7 +68,7 @@ public final class PCBcontext {
} }
/** /**
* @param student @TODO user is not student * @param student
* @param listener * @param listener
*/ */
public static void set_user(User student, String token, iImgDownloaderListener listener) { public static void set_user(User student, String token, iImgDownloaderListener listener) {
...@@ -83,8 +83,18 @@ public final class PCBcontext { ...@@ -83,8 +83,18 @@ public final class PCBcontext {
room = new Room(); room = new Room();
actionLog = new ActionLog(); actionLog = new ActionLog();
vocabulary = new Vocabulary(listener); vocabulary = new Vocabulary(listener);
} getNetService().notifyStatus();
}
/**
*
*/
public static void unset_user() {
pcbdb = null;
room = null;
vocabulary = null;
getNetService().notifyStatus();
}
/** /**
* if the user becomes from offline to online and the login is failed, then the user relogin in * if the user becomes from offline to online and the login is failed, then the user relogin in
* the app. The most frequent reason is a password change while the user have been logged * the app. The most frequent reason is a password change while the user have been logged
......
...@@ -196,7 +196,7 @@ END ...@@ -196,7 +196,7 @@ END
CREATE TRIGGER trg_insert_users_detail CREATE TRIGGER trg_insert_users_detail
INSTEAD OF INSERT ON users_detail INSTEAD OF INSERT ON users_detail
FOR EACH ROW FOR EACH ROW
WHEN NEW.pwd_stu IS NOT NULL WHEN NEW.pwd_stu NOT IS NULL
BEGIN BEGIN
INSERT OR REPLACE INTO student VALUES (NEW.id_stu, NEW.nickname_stu, NEW.pwd_stu, NEW.name_stu, NEW.surname_stu, NEW.url_img_stu, NEW.gender_stu, NEW.lang_stu, NEW.attributes_stu); INSERT OR REPLACE INTO student VALUES (NEW.id_stu, NEW.nickname_stu, NEW.pwd_stu, NEW.name_stu, NEW.surname_stu, NEW.url_img_stu, NEW.gender_stu, NEW.lang_stu, NEW.attributes_stu);
INSERT OR REPLACE INTO supervisor VALUES (NEW.id_sup, NEW.email_sup, NEW.pwd_sup, NEW.name_sup, NEW.surname_sup, NEW.url_img_sup, NEW.gender_sup, NEW.lang_sup, NEW.tts_engine_sup); INSERT OR REPLACE INTO supervisor VALUES (NEW.id_sup, NEW.email_sup, NEW.pwd_sup, NEW.name_sup, NEW.surname_sup, NEW.url_img_sup, NEW.gender_sup, NEW.lang_sup, NEW.tts_engine_sup);
...@@ -204,20 +204,19 @@ BEGIN ...@@ -204,20 +204,19 @@ BEGIN
END END
;-- ;--
CREATE TRIGGER trg_insert_users_detail_nostudentpwd CREATE TRIGGER trg_insert_users_detail_knonwstudent
INSTEAD OF INSERT ON users_detail INSTEAD OF INSERT ON users_detail
FOR EACH ROW FOR EACH ROW
WHEN NEW.pwd_stu IS NULL WHEN NEW.pwd_stu IS NULL
BEGIN BEGIN
INSERT OR REPLACE INTO INSERT OR REPLACE INTO student(id,nickname, name, surname, url_img, gender, lang, attributes)
student (id, nickname,name,surname,url_img,gender,lang,attributes) VALUES (NEW.id_stu, NEW.nickname_stu, NEW.name_stu, NEW.surname_stu, NEW.url_img_stu, NEW.gender_stu, NEW.lang_stu, NEW.attributes_stu);
VALUES ( INSERT OR REPLACE INTO supervisor VALUES (NEW.id_sup, NEW.email_sup, NEW.pwd_sup, NEW.name_sup, NEW.surname_sup, NEW.url_img_sup, NEW.gender_sup, NEW.lang_sup, NEW.tts_engine_sup);
NEW.id_stu, NEW.nickname_stu, NEW.name_stu, NEW.surname_stu, NEW.url_img_stu, NEW.gender_stu, NEW.lang_stu, NEW.attributes_stu);
INSERT OR REPLACE INTO supervisor VALUES (NEW.id_sup, NEW.email_sup, NEW.pwd_sup, NEW.name_sup, NEW.surname_sup, NEW.url_img_sup, NEW.gender_sup, NEW.lang_sup, NEW.tts_engine_sup);
INSERT OR REPLACE INTO users VALUES (NEW.id_stu,NEW.id_sup); INSERT OR REPLACE INTO users VALUES (NEW.id_stu,NEW.id_sup);
END END
;-- ;--
CREATE TRIGGER trg_update_users_detail CREATE TRIGGER trg_update_users_detail
INSTEAD OF UPDATE ON users_detail INSTEAD OF UPDATE ON users_detail
FOR EACH ROW FOR EACH ROW
...@@ -252,4 +251,4 @@ BEGIN ...@@ -252,4 +251,4 @@ 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.attributes); INSERT INTO collection VALUES (NEW.id_stu,NEW.id_picto,NEW.attributes);
END END
;-- ;--
\ No newline at end of file
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