issue #750 y #751 solved

parent 5d973e7e
......@@ -2,25 +2,17 @@ package com.yottacode.net;
import android.util.Log;
import com.github.nkzawa.emitter.Emitter;
import com.github.nkzawa.socketio.client.Ack;
import com.github.nkzawa.socketio.client.IO;
import com.github.nkzawa.socketio.client.Socket;
import com.github.nkzawa.emitter.Emitter;
import org.json.JSONException;
import org.json.JSONObject;
import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import java.security.SecureRandom;
/**
......@@ -74,7 +66,14 @@ public class SailsSocketsIO {
Log.d(this.getClass().getName(), " Listening:"+message);
socket.on(message, listener);
}
/**
* Unregisters a connection listener to a given message
* @param message
*/
public void unregisterMessage(String message) {
Log.d(this.getClass().getName(), " Unlistening:"+message);
socket.off(message);
}
public SailsSocketsIO(String sails_socket_io_url, String ptransport, Emitter.Listener connectListener, Emitter.Listener errorListener) {
......@@ -114,11 +113,13 @@ public class SailsSocketsIO {
JSONObject obj=new JSONObject().put("url", msg).put("data", params);
Log.d(this.getClass().getName(), "Emitted messsage:" + obj);
Log.i(this.getClass().getName(), "Emitted messsage:" + obj);
socket.emit(this.EMIT_METHOD, obj, ack);
}
public void destroy() {
this.socket.disconnect();
this.socket.off();
if (this.socket.connected()) {
this.socket.off();
this.socket.disconnect();
}
}
}
......@@ -113,14 +113,14 @@ public class NetService implements Runnable {
public boolean online() {return updated;}
public void restart_app(boolean direct_login) {
PCBcontext.unset_user();
for (iNetServiceStatus listener: listeners)
if (listener instanceof iNetServiceDevice) ((iNetServiceDevice)listener).restart_app(direct_login);
PCBcontext.unset_user();
}
public void restart_app(Intent intent, boolean direct_login) {
PCBcontext.unset_user();
for (iNetServiceStatus listener: listeners)
if (listener instanceof iNetServiceDevice) ((iNetServiceDevice)listener).restart_app(intent, direct_login);
PCBcontext.unset_user();
}
/**
......
......@@ -70,7 +70,6 @@ public class Room {
public void connect() {
final String transport="polling";
exit();
this.socket=new SailsSocketsIO(PCBcontext.getRestapiWrapper().getServer(), transport, new Emitter.Listener() {
@Override
public void call(Object... args) {
......@@ -83,6 +82,7 @@ public class Room {
@Override
public void call(Object... args) {
Log.e(this.getClass().getName(), "IO sockects error: "+args[0]);
for (StackTraceElement element: Thread.currentThread().getStackTrace() ) Log.e(this.getClass().getName(), "IO sockect error detail: "+element.getClassName()+"."+element.getMethodName());
inRoom=false;
PCBcontext.getNetService().setOffline(new SocketIOException(args[0].toString()));
}
......@@ -108,9 +108,16 @@ public class Room {
Log.e(this.getClass().getCanonicalName(), "subscribe room failed:"+e.getMessage());
}
}
void unlisten() {
for (String msg: this.listeners.keySet()) {
Log.i(this.getClass().getName(), "Unlistening to "+msg);
this.socket.unregisterMessage(msg);
}
}
void unsubscribe() {
void unsubscribe() {
try {
UnsubscribeAction action = new UnsubscribeAction();
this.emit(action);
}catch (Exception e) {
......@@ -120,13 +127,16 @@ public class Room {
public void exit() {
if (this.socket!=null) {
Log.i(this.getClass().getName(), "Leaving room");
unlisten();
unsubscribe();
this.socket.destroy();
this.socket=null;
}
}
public void finalize() throws java.lang.Throwable {
super.finalize();
Log.i(this.getClass().getName(), "Discarding room");
exit();
}
......
......@@ -33,7 +33,7 @@ public class StudentTalk implements Emitter.Listener {
@Override
public void call(Object... args) {
if (PCBcontext.getPcbdb()!=null)
try {
JSONObject msg = ((JSONObject) args[0]).getJSONObject("student");
Log.i(this.getClass().getName(), "raw Received message " +msg.toString());
......
......@@ -45,8 +45,8 @@ public final class PCBcontext {
Log.i(PCBcontext.class.getCanonicalName(), "PCB context started. It's required" +
"set_user method call");
} else {
Log.e(PCBcontext.class.getClass().getCanonicalName(), "Init method was previously" +
"invoked! Please, check your code");
Log.e(PCBcontext.class.getCanonicalName(), "Init method was previously " +
" invoked! Please, check your code");
}
}
......@@ -75,7 +75,7 @@ public final class PCBcontext {
public void change(User updatedStudent) {
PCBcontext.getDevice().insertUser(updatedStudent);
if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big() || updatedStudent.has_categories()!=getPcbdb().getCurrentUser().has_categories())
PCBcontext.getNetService().getNetServiceDevice().restart_app(true);
PCBcontext.getNetService().restart_app(true);
else {
PCBcontext.getPcbdb().setCurrentUser(updatedStudent);
PCBcontext.getNetService().getNetServiceDevice().updateUserConfig(updatedStudent);
......@@ -88,8 +88,8 @@ public final class PCBcontext {
public static void unset_user() {
Log.i(PCBcontext.class.getCanonicalName(), "User unset. Student " + getPcbdb().getCurrentUser().get_name_stu());
pcbdb = null;
if (room!=null) room.exit();
pcbdb = null;
room = null;
vocabulary = null;
getNetService().notifyStatus();
......
......@@ -112,7 +112,7 @@ public class LoginActivity extends FragmentActivity {
@Override
protected void onStop() {
super.onStop();
Log.i(LOG_TAG,"Closing app");
Log.i(LOG_TAG,"Closing Login window");
PCBcontext.getNetService().closeNotifyStatus();
}
}
......@@ -131,8 +131,9 @@ public class SerialActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e(this.getClass().getCanonicalName(),"Creating serial activity");
PCBcontext.init(this, new NetServiceTablet());
Log.i(this.getClass().getCanonicalName(),"Creating serial activity");
if (!PCBcontext.init())
PCBcontext.init(this, new NetServiceTablet());
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_serial);
......@@ -170,7 +171,7 @@ public class SerialActivity extends Activity {
@Override
public void onStart() {
Vector<User> users;
Log.e(this.getClass().getCanonicalName(),"Starting serial activity (direct login:"+getIntent().getBooleanExtra("resetPrevUser", true)+")");
Log.i(this.getClass().getCanonicalName(),"Starting serial activity (direct login:"+!getIntent().getBooleanExtra("resetPrevUser", true)+")");
if (!PCBcontext.init()) PCBcontext.init(this, new NetServiceTablet());
String default_user[] = loginUserPolicy();
String username = default_user[0];
......
......@@ -83,6 +83,10 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
serialActivity = new Intent(PCBcontext.getContext(), serialClass);
}
serialActivity.putExtra("resetPrevUser", !direct_login);
if (direct_login) {
serialActivity.putExtra("switch_usr",PCBcontext.getPcbdb().getCurrentUser().is_supervisor() ? PCBcontext.getPcbdb().getCurrentUser().get_email_sup() : PCBcontext.getPcbdb().getCurrentUser().get_nickname_stu());
serialActivity.putExtra("switch_pwd",PCBcontext.getPcbdb().getCurrentUser().is_supervisor() ? PCBcontext.getPcbdb().getCurrentUser().get_pwd_sup() : PCBcontext.getPcbdb().getCurrentUser().get_pwd_stu());
}
PCBcontext.getContext().startActivity(serialActivity);
}
......
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