Pictogram 1.6, Beta 6, bug en pcb.netservice solucionado

parent b9a62918
......@@ -327,16 +327,14 @@ public class Picto extends Img {
visited.add(get_child_grid());
LinkedList<Picto> childs = PCBcontext.getVocabulary().next(get_child_grid());
if (childs==null) {
Log.e(LOG_TAG, " Picto " + this.get_translation() + " with empty grid " + get_child_grid() + " is invisible?" + (!visible));
if (childs==null)
visible=false;
}else {
else
for (Picto child : childs) {
visible = !child.is_invisible(visited);
if (visible) break;
}
}
}
return !visible;
}
......
......@@ -38,6 +38,7 @@ import java.util.concurrent.TimeUnit;
public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
private static final String LOG_TAG=NetService.class.getCanonicalName();
private static final String ping_session="server/ping_session";
private static final String ping="server/ping";
private boolean updated;
private final Vector<iNetServiceStatus> listeners;
......@@ -46,7 +47,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
private long nextRestfullSynchro;
private long nextServerPing;
public NetService(iNetServiceStatus listener) {
this.updated=RestapiWrapper.ping(PCBcontext.getContext().getResources().getString(R.string.server), ping_session);
this.updated=RestapiWrapper.ping(PCBcontext.getContext().getResources().getString(R.string.server), ping);
nextServerPing=0;
this.listeners = new Vector<>(2);
this.listeners.add(listener);
......@@ -151,19 +152,17 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
public void run() {
try {
ConnectivityManager cm =
(ConnectivityManager)PCBcontext.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
(ConnectivityManager) PCBcontext.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
if (!isConnected) {
if (!isConnected)
setOffline(new NetworkErrorException("No Internet access"));
return;
}
long now = new Date().getTime();
if (now < nextServerPing || !!updated) return;
nextServerPing=now+serverPingTimming;
PCBcontext.getRestapiWrapper().ask(ping_session, new RestapiWrapper.iRestapiListener() {
else {
final long now = new Date().getTime();
if (now >= nextServerPing || !updated) {
nextServerPing = now + serverPingTimming;
PCBcontext.getRestapiWrapper().ask(updated ? ping_session : ping, new RestapiWrapper.iRestapiListener() {
@Override
public void preExecute() {
......@@ -172,29 +171,21 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
@Override
public void result(JSONArray result) {
}
@Override
public void result(final JSONObject result) {
try {
final float version = ((float)(Float.valueOf(result.getString("version")).intValue()*10))/10;
final float version = ((float) (Float.valueOf(result.getString("version")).intValue() * 10)) / 10;
if (PCBcontext.getActivityContext() != null && version > DeviceHelper.getAppVersion() && newVersionContext!=PCBcontext.getActivityContext()) {
newVersionContext=PCBcontext.getActivityContext(); // prevent from showing several times the alert
newVersionAlert(version,PCBcontext.getActivityContext(), version);
if (PCBcontext.getActivityContext() != null && version > DeviceHelper.getAppVersion() && newVersionContext != PCBcontext.getActivityContext()) {
newVersionContext = PCBcontext.getActivityContext(); // prevent from showing several times the alert
newVersionAlert(version, PCBcontext.getActivityContext(), version);
}
} catch (Exception e) {
Log.e(LOG_TAG, "PING JSON ERROR: " + result + " " + e.getMessage());
}
long now = new Date().getTime();
if (!updated) {
nextRestfullSynchro = now;
updated = true;
String TAG_TOKEN="token";
try {
PCBcontext.getRestapiWrapper().setToken(result.getString(TAG_TOKEN));
} catch (JSONException e) {
Log.e(LOG_TAG,"Error when ping:"+e.getMessage()+" res:"+result.toString());
}
setOnline();
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())
......@@ -204,32 +195,41 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
PCBcontext.getRoom().connect();
synchronizeStuData();
PCBcontext.getActionLog().batch();
};
}
;
} else {
try {
PCBcontext.getRestapiWrapper().setToken(result.getString("token"));
Log.i(LOG_TAG, "session token updated");
} catch (JSONException e) {
Log.e(LOG_TAG, "Error when ping:" + e.getMessage() + " res:" + result.toString());
}
//cada restfullSynchroTimming aprox. se fuerza sincronización de vocabulario y configuración de usuario
if (PCBcontext.is_user_logged()) {
if (restfullSynchroTimming > 0 && (now >= nextRestfullSynchro)) {
Log.i(LOG_TAG, "Vocabulary request.");
if(!PCBcontext.getRoom().inRoom()){
if (!PCBcontext.getRoom().inRoom()) {
PCBcontext.getRoom().connect();
}
synchronizeStuData();
nextSynchro(now+restfullSynchroTimming);
nextSynchro(now + restfullSynchroTimming);
}
} else nextSynchro(now+restfullSynchroTimming);
} else nextSynchro(now + restfullSynchroTimming);
}
}
@Override
public void error(RestapiWrapper.HTTPException e) {
Log.e(LOG_TAG,"Error when asking:"+e.getMessage());
Log.e(LOG_TAG, "Error when asking:" + e.getMessage());
setOffline(e);
}
});
notifyStatus();
}catch(Exception e) {
Log.e(LOG_TAG,"THREAD NOT WORKING BECAUSE:"+e.getMessage());
}
}
}catch(Exception e){
Log.e(LOG_TAG, "THREAD NOT WORKING BECAUSE:" + e.getMessage());
this.restart_app(true);
}
}
......@@ -289,11 +289,18 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
public void setOffline(Exception e) {
this.updated=false;
PCBcontext.getRoom().exit();
//PCBcontext.getRoom().exit();
Log.e(LOG_TAG, "PCB offline because exception happens: " + e.getMessage());
notifyStatus();
}
public void setOnline() {
this.updated=true;
Log.e(LOG_TAG, "PCB online");
notifyStatus();
}
public iNetServiceDevice getNetServiceDevice() {
iNetServiceDevice device=null;
for (iNetServiceStatus listener: listeners)
......
......@@ -150,7 +150,7 @@ public class TTSHelper {
public void play(String input) {
Bundle params = new Bundle();
params.putString(TextToSpeech.Engine.KEY_PARAM_VOLUME, "1");
params.putFloat(TextToSpeech.Engine.KEY_PARAM_VOLUME, new Float(1));
params.putString(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "TAPE_READ");
ttobj.speak(input, TextToSpeech.QUEUE_FLUSH, params, "TAPE_READ");
}
......
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