working on serial/login activity refactorization (iv)

parent dc3761c6
...@@ -122,8 +122,9 @@ public class SerialActivity extends Activity { ...@@ -122,8 +122,9 @@ public class SerialActivity extends Activity {
loginActivity.putExtra("password", password); loginActivity.putExtra("password", password);
} }
} }
private void set_student_oline(User student, String token) { private void set_student_oline(User student, String token, final Intent pictogramActivity) {
final ProgressDialog progressDialog=ProgressDialog.show(this, getString(R.string.userLoadingTxt),getString(R.string.loadingGrammar)); final ProgressDialog progressDialog=ProgressDialog.show(this, getString(R.string.userLoadingTxt),getString(R.string.loadingGrammar));
Vector<User> vstudent = new Vector<>(1); Vector<User> vstudent = new Vector<>(1);
vstudent.add(student); vstudent.add(student);
try { try {
...@@ -145,6 +146,8 @@ public class SerialActivity extends Activity { ...@@ -145,6 +146,8 @@ public class SerialActivity extends Activity {
@Override @Override
public void loadComplete() { public void loadComplete() {
progressDialog.dismiss(); progressDialog.dismiss();
startActivity(pictogramActivity);
Log.i(SerialActivity.this.LOG_TAG, "4 FERNANDO pA");
} }
@Override @Override
...@@ -155,15 +158,15 @@ public class SerialActivity extends Activity { ...@@ -155,15 +158,15 @@ public class SerialActivity extends Activity {
} }
private void manageStudentLogin(final String username, final String password, boolean online) private void manageStudentLogin(final String username, final String password, boolean online)
{ {
final ProgressDialog progressDialog=ProgressDialog.show(this, getString(R.string.userLoadingTxt),getString(R.string.userLoadingMsg));
final Intent pictogramActivity = new Intent(SerialActivity.this, PictogramActivity.class); final Intent pictogramActivity = new Intent(SerialActivity.this, PictogramActivity.class);
if (online) { if (online) {
Log.d(LOG_TAG, "Entro con usuario y password");
String operation = "stu/login"; String operation = "stu/login";
Hashtable<String, String> postDataParams = new Hashtable<String, String>(); Hashtable<String, String> postDataParams = new Hashtable<String, String>();
postDataParams.put("username", username); postDataParams.put("username", username);
postDataParams.put("password", password); postDataParams.put("password", password);
Log.i(this.LOG_TAG, "2 FERNANDO username:" + username);
PCBcontext.getRestapiWrapper().ask(operation, postDataParams, "post", new iRestapiListener() { PCBcontext.getRestapiWrapper().ask(operation, postDataParams, "post", new iRestapiListener() {
@Override @Override
public void preExecute() { public void preExecute() {
...@@ -188,6 +191,7 @@ public class SerialActivity extends Activity { ...@@ -188,6 +191,7 @@ public class SerialActivity extends Activity {
String st_gender = user.getString(TAG_GENDER); String st_gender = user.getString(TAG_GENDER);
String st_lang = user.getString(TAG_LANG); String st_lang = user.getString(TAG_LANG);
String st_attributes = user.getString(TAG_ATTRIBUTES); String st_attributes = user.getString(TAG_ATTRIBUTES);
progressDialog.dismiss();
set_student_oline( set_student_oline(
new User(st_id_int, new User(st_id_int,
username, username,
...@@ -199,10 +203,13 @@ public class SerialActivity extends Activity { ...@@ -199,10 +203,13 @@ public class SerialActivity extends Activity {
st_lang, st_lang,
st_attributes, st_attributes,
User.NO_SUPERVISOR, "", "", "", "", "", "M", "es-es", "") User.NO_SUPERVISOR, "", "", "", "", "", "M", "es-es", "")
,result.getString(TAG_TOKEN)); , result.getString(TAG_TOKEN)
startActivity(pictogramActivity); ,pictogramActivity);
Log.i(SerialActivity.this.LOG_TAG, "3 FERNANDO sso");
} catch (JSONException e) { } catch (JSONException e) {
SerialActivity.this.error(e); SerialActivity.this.error(e);
progressDialog.dismiss();
} }
} }
...@@ -210,6 +217,7 @@ public class SerialActivity extends Activity { ...@@ -210,6 +217,7 @@ public class SerialActivity extends Activity {
@Override @Override
public void error(Exception e) { public void error(Exception e) {
SerialActivity.this.error(e); SerialActivity.this.error(e);
progressDialog.dismiss();
} }
}); });
} }
...@@ -242,7 +250,7 @@ public class SerialActivity extends Activity { ...@@ -242,7 +250,7 @@ public class SerialActivity extends Activity {
e.printStackTrace(); e.printStackTrace();
} }
startActivity(pictogramActivity); startActivity(pictogramActivity);
} } //offline student login
} }
...@@ -259,31 +267,37 @@ public class SerialActivity extends Activity { ...@@ -259,31 +267,37 @@ public class SerialActivity extends Activity {
Log.d(LOG_TAG, "JSON en result:" + result.toString()); Log.d(LOG_TAG, "JSON en result:" + result.toString());
if (result.toString().contains("error")){ if (result.toString().contains("error")){
AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this);
if (result.toString().contains("Invalid password")) { if (result.toString().contains("Invalid password"))
builder.setMessage(this.getString(R.string.passErrorMsg)) show_pwd_unknown();
.setCancelable(false) else if (result.toString().contains("User not found"))
.setPositiveButton("Ok", new DialogInterface.OnClickListener() { show_user_unknown();
public void onClick(DialogInterface dialog, int id) {
}
});
} else if (result.toString().contains("User not found")) {
builder.setMessage(this.getString(R.string.userErrorMsg))
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
}
AlertDialog alert = builder.create();
alert.show();
result = null; result = null;
} }
return result==null; return result==null;
} }
private void show_login_failed(int msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this);
builder.setMessage(getString(msg))
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void show_user_unknown() {
show_login_failed(R.string.userErrorMsg);
}
private void show_pwd_unknown() {
show_login_failed(R.string.passErrorMsg);
}
private void error(Exception e) { private void error(Exception e) {
Log.e(this.getClass().getName(), " Server restapi error: " + e.getLocalizedMessage()); Log.e(this.getClass().getName(), " Server restapi error: " + e.getLocalizedMessage());
...@@ -291,7 +305,7 @@ public class SerialActivity extends Activity { ...@@ -291,7 +305,7 @@ public class SerialActivity extends Activity {
builder.setMessage(getString(R.string.serverError) + ":" + e.getLocalizedMessage()) builder.setMessage(getString(R.string.serverError) + ":" + e.getLocalizedMessage())
.setCancelable(false) .setCancelable(false)
.setPositiveButton("Entendido", new DialogInterface.OnClickListener() { .setPositiveButton(getString(R.string.ok) + ":" + e.getLocalizedMessage(), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
//do things //do things
} }
...@@ -320,7 +334,7 @@ public class SerialActivity extends Activity { ...@@ -320,7 +334,7 @@ public class SerialActivity extends Activity {
// Escribo el último valor indicado de username // Escribo el último valor indicado de username
mSerialViewMail.setText(username); mSerialViewMail.setText(username);
username=""; username="";
Log.i(this.LOG_TAG,"1 FERNANDO username:"+username); Log.i(this.LOG_TAG, "1 FERNANDO username:" + username);
if (username.equals("")) { // No tengo aún usuario. Espero a que lo indique if (username.equals("")) { // No tengo aún usuario. Espero a que lo indique
Button mEntrarButton = (Button) findViewById(R.id.entrar_button); Button mEntrarButton = (Button) findViewById(R.id.entrar_button);
mEntrarButton.setOnClickListener(new OnClickListener() { mEntrarButton.setOnClickListener(new OnClickListener() {
......
...@@ -59,7 +59,7 @@ public final class PCBcontext { ...@@ -59,7 +59,7 @@ public final class PCBcontext {
wrapper = new RestapiWrapper(context.getResources().getString(R.string.server), null); wrapper = new RestapiWrapper(context.getResources().getString(R.string.server), null);
service = new NetService(context.getResources().getInteger(R.integer.netservice_timing)); service = new NetService(context.getResources().getInteger(R.integer.netservice_timing));
device.deleteDeprecatedImgs(); device.deleteDeprecatedImgs();
Log.i(PCBcontext.class.getCanonicalName(), "PCB context started. It's required to be invoked set_user method"); 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, revise your code"); else Log.e(PCBcontext.class.getClass().getCanonicalName(), "Init method was previously invoked! Please, revise your code");
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<string name="title_activity_pictogram">PictogramActivity</string> <string name="title_activity_pictogram">PictogramActivity</string>
<string name="title_activity_splash_screen">SplashScreenActivity</string> <string name="title_activity_splash_screen">SplashScreenActivity</string>
<string name="loginTitle">Who are you?</string> <string name="loginTitle">Who are you?</string>
<string name="passErrorTxt">Invalid password</string> <string name="LoginError">Login</string>
<string name="passErrorMsg">This password is not correct. Try again.</string> <string name="passErrorMsg">This password is not correct. Try again.</string>
<string name="userErrorTxt">User not found</string> <string name="userErrorTxt">User not found</string>
<string name="userErrorMsg">The user is not correct. Try again.</string> <string name="userErrorMsg">The user is not correct. Try again.</string>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<string name="prompt_serial_pass">Contraseña</string> <string name="prompt_serial_pass">Contraseña</string>
<string name="action_entrar">Entrar</string> <string name="action_entrar">Entrar</string>
<string name="loginTitle">¿Quién eres?</string> <string name="loginTitle">¿Quién eres?</string>
<string name="passErrorTxt">Invalid password</string> <string name="LoginError">Login</string>
<string name="passErrorMsg">La contraseña indicada no es correcta. Inténtelo de nuevo.</string> <string name="passErrorMsg">La contraseña indicada no es correcta. Inténtelo de nuevo.</string>
<string name="userErrorTxt">User not found</string> <string name="userErrorTxt">User not found</string>
<string name="userErrorMsg">El usuario indicado no es correcto. Inténtelo de nuevo.</string> <string name="userErrorMsg">El usuario indicado no es correcto. Inténtelo de nuevo.</string>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<string name="prompt_serial_pass">Contraseña</string> <string name="prompt_serial_pass">Contraseña</string>
<string name="action_entrar">Entrar</string> <string name="action_entrar">Entrar</string>
<string name="loginTitle">¿Quién eres?</string> <string name="loginTitle">¿Quién eres?</string>
<string name="passErrorTxt">Clave inválida</string> <string name="LoginError">Login</string>
<string name="passErrorMsg">La contraseña indicada no es correcta. Inténtelo de nuevo.</string> <string name="passErrorMsg">La contraseña indicada no es correcta. Inténtelo de nuevo.</string>
<string name="userErrorTxt">Usuario no encontrado</string> <string name="userErrorTxt">Usuario no encontrado</string>
<string name="userErrorMsg">El usuario indicado no es correcto. Inténtelo de nuevo.</string> <string name="userErrorMsg">El usuario indicado no es correcto. Inténtelo de nuevo.</string>
......
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