#issue #900,#902 closed. working on #903

parent 2bc412d7
...@@ -17,6 +17,7 @@ import com.yottacode.pictogram.dao.DeviceHelper; ...@@ -17,6 +17,7 @@ import com.yottacode.pictogram.dao.DeviceHelper;
import com.yottacode.pictogram.dao.LoginException; import com.yottacode.pictogram.dao.LoginException;
import com.yottacode.pictogram.dao.User; import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -142,7 +143,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -142,7 +143,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
public void restart_app(boolean direct_login) { public void restart_app(boolean direct_login) {
for (iNetServiceStatus listener: listeners) for (iNetServiceStatus listener: listeners)
if (listener instanceof iNetServiceDevice) ((iNetServiceDevice)listener).restart_app(direct_login); if (listener instanceof iNetServiceDevice) ((iNetServiceDevice)listener).restart_app(direct_login);
PCBcontext.unset_user(); PCBcontext.unset_user();
} }
public void restart_app(Intent intent, boolean direct_login) { public void restart_app(Intent intent, boolean direct_login) {
for (iNetServiceStatus listener: listeners) for (iNetServiceStatus listener: listeners)
...@@ -155,66 +156,69 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -155,66 +156,69 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
*/ */
@Override @Override
public void run() { public void run() {
PCBcontext.getRestapiWrapper().ask(ping_session, new RestapiWrapper.iRestapiListener() { try {
@Override PCBcontext.getRestapiWrapper().ask(ping_session, new RestapiWrapper.iRestapiListener() {
public void preExecute() { @Override
public void preExecute() {
}
@Override
public void result(JSONArray result) {
}
@Override
public void result(JSONObject result) {
try {
float version=Float.valueOf(result.getString("version")).floatValue();
if (PCBcontext.getActivityContext()!=null && version> DeviceHelper.getAppVersion(PCBcontext.getActivityContext())) {
Log.e(LOG_TAG,"New version is required! from v"+DeviceHelper.getAppVersion(PCBcontext.getContext())+" to v"+version);
newVersionAlert(PCBcontext.getActivityContext(),version);
}
} catch (JSONException e) {
Log.e(LOG_TAG,"PING JSON ERROR: "+result+" "+e.getMessage());
} }
if (!updated) {
lastRestfullSynchro=new Date().getTime(); @Override
updated = true; public void result(JSONArray result) {
if (PCBcontext.is_user_logged()) //si el usuario aun no hizo login, en realidad no es necesario hacer nada
// Comprobar si hay usuario offline, para hacer login transparente
if (PCBcontext.is_user_offline()){
Log.i(LOG_TAG, "PCB online login from offline login");
login();
} else if (PCBcontext.is_user_online()){
Log.i(LOG_TAG, "PCB reconnect");
PCBcontext.getRoom().connect();
PCBcontext.getVocabulary().synchronize();
PCBcontext.getActionLog().batch();
}
notifyStatus();
} }
else {
//cada restfullSynchroTimming aprox. se fuerza sincronización de vocabulario y configuración de usuario
long now=new Date().getTime();
if (PCBcontext.is_user_logged()) {
if (restfullSynchroTimming>0 && (now - lastRestfullSynchro > restfullSynchroTimming)) {
Log.i(LOG_TAG, "Vocabulary request");
PCBcontext.getVocabulary().synchronize();
synchronizeStudentAttributes();
lastRestfullSynchro = now;
}
}
else lastRestfullSynchro=new Date().getTime();
}
} @Override
public void result(JSONObject result) {
try {
float version = Float.valueOf(result.getString("version")).floatValue();
if (PCBcontext.getActivityContext() != null && version > DeviceHelper.getAppVersion(PCBcontext.getActivityContext())) {
Log.e(LOG_TAG, "New version is required! from v" + DeviceHelper.getAppVersion(PCBcontext.getContext()) + " to v" + version);
newVersionAlert(PCBcontext.getActivityContext(), version);
}
} catch (JSONException e) {
Log.e(LOG_TAG, "PING JSON ERROR: " + result + " " + e.getMessage());
}
if (!updated) {
lastRestfullSynchro = new Date().getTime();
updated = true;
if (PCBcontext.is_user_logged()) //si el usuario aun no hizo login, en realidad no es necesario hacer nada
// Comprobar si hay usuario offline, para hacer login transparente
if (PCBcontext.is_user_offline()) {
Log.i(LOG_TAG, "PCB online login from offline login");
login();
} else if (PCBcontext.is_user_online()) {
Log.i(LOG_TAG, "PCB reconnect");
PCBcontext.getRoom().connect();
PCBcontext.getVocabulary().synchronize();
PCBcontext.getActionLog().batch();
}
} else {
//cada restfullSynchroTimming aprox. se fuerza sincronización de vocabulario y configuración de usuario
long now = new Date().getTime();
if (PCBcontext.is_user_logged()) {
if (restfullSynchroTimming > 0 && (now - lastRestfullSynchro > restfullSynchroTimming)) {
Log.i(LOG_TAG, "Vocabulary request");
PCBcontext.getVocabulary().synchronize();
synchronizeStudentAttributes();
lastRestfullSynchro = now;
}
} else lastRestfullSynchro = new Date().getTime();
}
@Override }
public void error(RestapiWrapper.HTTPException e) {
setOffline(e);
}
});
@Override
public void error(RestapiWrapper.HTTPException e) {
setOffline(e);
}
});
notifyStatus();
Log.e(LOG_TAG, "working");
}catch(Exception e) {
Log.e(LOG_TAG,"NOT WORKING BECAUSE:"+e.getMessage());
this.restart_app(true);
}
} }
private void synchronizeStudentAttributes() { private void synchronizeStudentAttributes() {
......
...@@ -57,6 +57,7 @@ import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet; ...@@ -57,6 +57,7 @@ import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet;
import com.yottacode.pictogram.tools.Img; import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.pictogram.tts.TTSHelper; import com.yottacode.pictogram.tts.TTSHelper;
import com.yottacode.tools.GUITools;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -1055,16 +1056,22 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1055,16 +1056,22 @@ protected void showOnlyTape(boolean onlyTape) {
if (!student_view || !PCBcontext.getPcbdb().getCurrentUser().is_teacher()) { if (!student_view || !PCBcontext.getPcbdb().getCurrentUser().is_teacher()) {
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(student_view ? PCBcontext.getDevice().getLastSupId() : User.NO_SUPERVISOR); PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(student_view ? PCBcontext.getDevice().getLastSupId() : User.NO_SUPERVISOR);
nextActivity = intent; nextActivity = intent;
} else { } else
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(PCBcontext.getDevice().getLastSupId()); if (!PCBcontext.getNetService().online())
nextActivity = new Intent(this, SessionActivity.class); GUITools.show_alert(PictogramActivity.this, R.string.session_noinet);
} else {
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(PCBcontext.getDevice().getLastSupId());
nextActivity = new Intent(this, SessionActivity.class);
}
in = R.anim.rightin; in = R.anim.rightin;
out = R.anim.rightout; out = R.anim.rightout;
overridePendingTransition(R.anim.leftin, R.anim.leftout); overridePendingTransition(R.anim.leftin, R.anim.leftout);
} else if (firstTouchX > event.getX() + 150) { //derecha a izquierda } else if (firstTouchX > event.getX() + 150) { //derecha a izquierda
if (!student_view && PCBcontext.getPcbdb().getCurrentUser().is_teacher() ) { if (!student_view && PCBcontext.getPcbdb().getCurrentUser().is_teacher() ) {
nextActivity = new Intent(this, SessionActivity.class); if (!PCBcontext.getNetService().online())
GUITools.show_alert(PictogramActivity.this, R.string.session_noinet);
else
nextActivity = new Intent(this, SessionActivity.class);
} else { } else {
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(student_view ? PCBcontext.getDevice().getLastSupId() : User.NO_SUPERVISOR); PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(student_view ? PCBcontext.getDevice().getLastSupId() : User.NO_SUPERVISOR);
nextActivity = intent; nextActivity = intent;
......
package com.yottacode.pictogram.tabletlibrary.net; package com.yottacode.pictogram.tabletlibrary.net;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent; import android.content.Intent;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.util.Log; import android.util.Log;
import com.yottacode.pictogram.dao.User; import com.yottacode.pictogram.dao.User;
...@@ -22,11 +24,12 @@ public class NetServiceTablet implements NetService.iNetServiceDevice { ...@@ -22,11 +24,12 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
private static NotificationCompat.Builder builder; private static NotificationCompat.Builder builder;
private PictogramActivity pictogramActivity; private PictogramActivity pictogramActivity;
int notifyID = 666;
public void build() { public void build() {
this.builder = new NotificationCompat.Builder(PCBcontext.getContext()); this.builder = new NotificationCompat.Builder(PCBcontext.getContext()).setAutoCancel(true);
/* Intent resultIntent = new Intent(PCBcontext.getContext(), PictogramActivity.class); /*Intent resultIntent = new Intent(PCBcontext.getContext(), PictogramActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(PCBcontext.getContext()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(PCBcontext.getContext());
stackBuilder.addParentStack(PictogramActivity.class); stackBuilder.addParentStack(PictogramActivity.class);
stackBuilder.addNextIntent(resultIntent); stackBuilder.addNextIntent(resultIntent);
...@@ -36,8 +39,8 @@ public class NetServiceTablet implements NetService.iNetServiceDevice { ...@@ -36,8 +39,8 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
} }
public void notifyStatus(boolean updated) { public void notifyStatus(boolean updated) {
int notifyID = 1;
String user=""; String user="";
if (PCBcontext.getPcbdb()!=null) { if (PCBcontext.getPcbdb()!=null) {
user=PCBcontext.getPcbdb().getCurrentUser().get_name_stu()+" "+PCBcontext.getPcbdb().getCurrentUser().get_surname_stu(); user=PCBcontext.getPcbdb().getCurrentUser().get_name_stu()+" "+PCBcontext.getPcbdb().getCurrentUser().get_surname_stu();
if (PCBcontext.getPcbdb().getCurrentUser().is_supervisor()) if (PCBcontext.getPcbdb().getCurrentUser().is_supervisor())
...@@ -57,7 +60,6 @@ public class NetServiceTablet implements NetService.iNetServiceDevice { ...@@ -57,7 +60,6 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
mNotificationManager.notify(notifyID, builder.build()); mNotificationManager.notify(notifyID, builder.build());
} }
public void closeNotifyStatus(){ public void closeNotifyStatus(){
int notifyID = 1;
NotificationManager mNotificationManager = NotificationManager mNotificationManager =
(NotificationManager) PCBcontext.getContext().getSystemService(PCBcontext.getContext().NOTIFICATION_SERVICE); (NotificationManager) PCBcontext.getContext().getSystemService(PCBcontext.getContext().NOTIFICATION_SERVICE);
mNotificationManager.cancel(notifyID); mNotificationManager.cancel(notifyID);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<string name="session_closed_ok">Sesión grabada correctamente. Hora</string> <string name="session_closed_ok">Sesión grabada correctamente. Hora</string>
<string name="session_closed_fail">Sesión no cerrada. Por favor cierre la sesión en el panel de control de Pictogram Tablet</string> <string name="session_closed_fail">Sesión no cerrada. Por favor cierre la sesión en el panel de control de Pictogram Tablet</string>
<string name="session_pause_error">Error pausando la sesión</string> <string name="session_pause_error">Error pausando la sesión</string>
<string name="session_noinet">No hay conexión con el servidor. Por favor, asegúrese que tiene conexión a Internet</string> <string name="session_noinet">Conexión a Internet necesaria para grabar sesiones. Por favor, asegúrese que tiene conexión</string>
<string name="session_inetok">Conexión con el servidor restablecida</string> <string name="session_inetok">Conexión con el servidor restablecida</string>
<string name="session_log_startingsession">iniciando sesión</string> <string name="session_log_startingsession">iniciando sesión</string>
<string name="session_log_closingsession">cerrando sesión</string> <string name="session_log_closingsession">cerrando sesión</string>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<string name="session_closed_ok">Sesión grabada correctamente</string> <string name="session_closed_ok">Sesión grabada correctamente</string>
<string name="session_closed_fail">Sesión no cerrada. Por favor intente cerrarla desde</string> <string name="session_closed_fail">Sesión no cerrada. Por favor intente cerrarla desde</string>
<string name="session_pause_error">Error pausando la sesión</string> <string name="session_pause_error">Error pausando la sesión</string>
<string name="session_noinet">No hay conexión con el servidor. Por favor, asegúrese que tiene conexión a Internet</string> <string name="session_noinet">Conexión a Internet necesaria para grabar sesiones. Por favor, asegúrese que tiene conexión</string>
<string name="session_inetok">Conexión con el servidor restablecida</string> <string name="session_inetok">Conexión con el servidor restablecida</string>
<string name="session_log_startingsession">iniciando sesión</string> <string name="session_log_startingsession">iniciando sesión</string>
<string name="session_log_closingsession">cerrando sesión</string> <string name="session_log_closingsession">cerrando sesión</string>
......
...@@ -22,6 +22,7 @@ public class AppContext extends Application { ...@@ -22,6 +22,7 @@ public class AppContext extends Application {
instance = this; instance = this;
registerKioskModeScreenOffReceiver(); registerKioskModeScreenOffReceiver();
startKioskService(); // Service for restarting the app when another app go to foreground startKioskService(); // Service for restarting the app when another app go to foreground
} }
private void registerKioskModeScreenOffReceiver() { private void registerKioskModeScreenOffReceiver() {
......
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