Bug #377 fixed

parent f5adcd27
...@@ -46,7 +46,7 @@ public class MainActivity extends Activity { ...@@ -46,7 +46,7 @@ public class MainActivity extends Activity {
Intent serialActivity = new Intent(this, SerialActivity.class); Intent serialActivity = new Intent(this, SerialActivity.class);
serialActivity.putExtra("activity_name","MainActivity"); serialActivity.putExtra("resetPrevUser", false);
startActivity(serialActivity); startActivity(serialActivity);
} }
......
...@@ -403,7 +403,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -403,7 +403,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
//Log.d(LOG_TAG, "SALTO A LOGIN"); //Log.d(LOG_TAG, "SALTO A LOGIN");
// 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("activity_name", "PictogramActivity"); serialActivity.putExtra("resetPrevUser", true);
startActivity(serialActivity); startActivity(serialActivity);
} }
......
...@@ -215,8 +215,6 @@ public class SerialActivity extends Activity { ...@@ -215,8 +215,6 @@ public class SerialActivity extends Activity {
GUITools.show_alert(SerialActivity.this, R.string.passErrorMsg); GUITools.show_alert(SerialActivity.this, R.string.passErrorMsg);
else if (((LoginException)e).no_username_found()) else if (((LoginException)e).no_username_found())
GUITools.show_alert(SerialActivity.this, R.string.userErrorMsg); GUITools.show_alert(SerialActivity.this, R.string.userErrorMsg);
else if (((LoginException)e).no_supervisor_students())
GUITools.show_alert(SerialActivity.this, R.string.noStudentsError);
else else
GUITools.show_alert(SerialActivity.this, R.string.serverError, e.getMessage()); GUITools.show_alert(SerialActivity.this, R.string.serverError, e.getMessage());
...@@ -262,7 +260,13 @@ public class SerialActivity extends Activity { ...@@ -262,7 +260,13 @@ public class SerialActivity extends Activity {
else else
manageStudentLogin(username,password,online); manageStudentLogin(username,password,online);
} }
public static void resetDefaultUser() {
SharedPreferences settings = PCBcontext.getContext().getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("username", "");
editor.putString("password", "");
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -270,14 +274,14 @@ public class SerialActivity extends Activity { ...@@ -270,14 +274,14 @@ public class SerialActivity extends Activity {
setContentView(R.layout.activity_serial); setContentView(R.layout.activity_serial);
Intent intent=getIntent(); Intent intent=getIntent();
String activityName=intent.getStringExtra("activity_name");
final EditText mSerialViewMail = (EditText) findViewById(R.id.serialmail); final EditText mSerialViewMail = (EditText) findViewById(R.id.serialmail);
final EditText mSerialViewPass = (EditText) findViewById(R.id.serialpass); final EditText mSerialViewPass = (EditText) findViewById(R.id.serialpass);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String username = settings.getString("username", ""); String username = settings.getString("username", "");
String password = activityName.equals("MainActivity") ? settings.getString("password", "") : ""; String password = intent.getBooleanExtra("resetPrevUser", true) ? "" : settings.getString("password", "");
// Escribo el último valor indicado de username // Escribo el último valor indicado de username
......
...@@ -220,13 +220,21 @@ public class StudentFragmentGrid extends Fragment{ ...@@ -220,13 +220,21 @@ public class StudentFragmentGrid extends Fragment{
e.printStackTrace(); e.printStackTrace();
} }
} }
show_student_list_online();
switch (students.length()) { switch (students.length()) {
case 0: case 0:
GUITools.show_alert(getActivity(),R.string.noStudentsError); GUITools.show_alert(getActivity(), R.string.LoginError,getString(R.string.noStudentsError), new GUITools.iOKListener() {
@Override
public void ok() {
PCBcontext.restart_app();
}
});
break; break;
case 1: case 1:
new_user(0); new_user(0);
break;
default:
show_student_list_online();
} }
} }
@Override @Override
......
...@@ -13,6 +13,7 @@ import com.yottacode.pictogram.R; ...@@ -13,6 +13,7 @@ import com.yottacode.pictogram.R;
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.gui.PictogramActivity; import com.yottacode.pictogram.gui.PictogramActivity;
import com.yottacode.pictogram.gui.SerialActivity;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONArray; import org.json.JSONArray;
...@@ -49,16 +50,6 @@ public class NetService implements Runnable { ...@@ -49,16 +50,6 @@ public class NetService implements Runnable {
exec.scheduleWithFixedDelay(this, 0, delay, TimeUnit.SECONDS); exec.scheduleWithFixedDelay(this, 0, delay, TimeUnit.SECONDS);
} }
/**
* 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 offline
*/
private void restart_app() {
Intent i = PCBcontext.getContext().getPackageManager()
.getLaunchIntentForPackage(PCBcontext.getContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PCBcontext.getContext().startActivity(i);
}
public void login() { public void login() {
User user=PCBcontext.getPcbdb().getCurrentUser(); User user=PCBcontext.getPcbdb().getCurrentUser();
...@@ -81,8 +72,8 @@ public class NetService implements Runnable { ...@@ -81,8 +72,8 @@ public class NetService implements Runnable {
@Override @Override
public void error(Exception e) { public void error(Exception e) {
Log.e(this.getClass().getSimpleName(),"Error un when server login:"+e.getMessage()); Log.e(this.getClass().getSimpleName(), "Error un when server login:" + e.getMessage());
if (e instanceof LoginException) restart_app(); if (e instanceof LoginException) PCBcontext.restart_app();
} }
}); });
else ServerLogin.login_student(user.get_nickname_stu(), user.get_pwd_stu(), new iRestapiListener() { else ServerLogin.login_student(user.get_nickname_stu(), user.get_pwd_stu(), new iRestapiListener() {
...@@ -104,7 +95,7 @@ public class NetService implements Runnable { ...@@ -104,7 +95,7 @@ public class NetService implements Runnable {
@Override @Override
public void error(Exception e) { public void error(Exception e) {
Log.e(this.getClass().getSimpleName(),"Error un when server login:"+e.getMessage()); Log.e(this.getClass().getSimpleName(),"Error un when server login:"+e.getMessage());
if (e instanceof LoginException) restart_app(); if (e instanceof LoginException) PCBcontext.restart_app();;
} }
}); });
} }
......
package com.yottacode.pictogram.tools; package com.yottacode.pictogram.tools;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.util.Log; import android.util.Log;
import com.yottacode.net.RestapiWrapper; import com.yottacode.net.RestapiWrapper;
...@@ -11,6 +12,7 @@ import com.yottacode.pictogram.dao.Device; ...@@ -11,6 +12,7 @@ import com.yottacode.pictogram.dao.Device;
import com.yottacode.pictogram.dao.PCBDBHelper; import com.yottacode.pictogram.dao.PCBDBHelper;
import com.yottacode.pictogram.dao.User; import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.grammar.Vocabulary; import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.gui.SerialActivity;
import com.yottacode.pictogram.net.NetService; import com.yottacode.pictogram.net.NetService;
import com.yottacode.pictogram.action.Room; import com.yottacode.pictogram.action.Room;
import com.yottacode.pictogram.net.iImgDownloaderListener; import com.yottacode.pictogram.net.iImgDownloaderListener;
...@@ -80,10 +82,18 @@ public final class PCBcontext { ...@@ -80,10 +82,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);
} }
/**
* 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 offline
*/
public static void restart_app() {
SerialActivity.resetDefaultUser();
Intent serialActivity = new Intent(PCBcontext.getContext(), SerialActivity.class);
serialActivity.putExtra("resetPrevUser", true);
PCBcontext.getContext().startActivity(serialActivity);
}
/** /**
* *
* @return true if the user is logged offline and it has not been online previously. False in other case (user not logged, user logged online, user offline but it was previously online logged * @return true if the user is logged offline and it has not been online previously. False in other case (user not logged, user logged online, user offline but it was previously online logged
......
...@@ -9,21 +9,30 @@ import android.util.Log; ...@@ -9,21 +9,30 @@ import android.util.Log;
* Created by Fernando on 01/04/2016. * Created by Fernando on 01/04/2016.
*/ */
public class GUITools { public class GUITools {
public static void show_alert(Context context, int resource_msg) { public interface iOKListener {
show_alert(context, resource_msg, null); public void ok();
} }
public static void show_alert(Context context, int resource_msg, String additional_msg) {
public static void show_alert(Context context, int resource_msg, String additional_msg, final iOKListener oklistener) {
AlertDialog.Builder builder = new AlertDialog.Builder(context); AlertDialog.Builder builder = new AlertDialog.Builder(context);
String msg = context.getString(resource_msg); String msg = context.getString(resource_msg);
if (additional_msg!=null) msg+=": "+additional_msg; if (additional_msg != null) msg += ": " + additional_msg;
Log.i(GUITools.class.getName(), "FERNANDO Alert:" + msg); Log.i(GUITools.class.getName(), "Alert:" + msg);
builder.setMessage(msg) builder.setMessage(msg)
.setCancelable(false) .setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() { .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
if (oklistener != null) oklistener.ok();
} }
}); });
AlertDialog alert = builder.create(); AlertDialog alert = builder.create();
alert.show(); alert.show();
} }
public static void show_alert(Context context, int resource_msg) {
show_alert(context, resource_msg, null);
}
public static void show_alert(Context context, int resource_msg, String additional_msg) {
show_alert(context, resource_msg, additional_msg,null);
}
} }
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