Bug #377 fixed

parent f5adcd27
......@@ -46,7 +46,7 @@ public class MainActivity extends Activity {
Intent serialActivity = new Intent(this, SerialActivity.class);
serialActivity.putExtra("activity_name","MainActivity");
serialActivity.putExtra("resetPrevUser", false);
startActivity(serialActivity);
}
......
......@@ -403,7 +403,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
//Log.d(LOG_TAG, "SALTO A LOGIN");
// Paso un parámetro a la SerialActivity, para controlar de dónde viene
Intent serialActivity = new Intent(getBaseContext(), SerialActivity.class);
serialActivity.putExtra("activity_name", "PictogramActivity");
serialActivity.putExtra("resetPrevUser", true);
startActivity(serialActivity);
}
......
......@@ -215,8 +215,6 @@ public class SerialActivity extends Activity {
GUITools.show_alert(SerialActivity.this, R.string.passErrorMsg);
else if (((LoginException)e).no_username_found())
GUITools.show_alert(SerialActivity.this, R.string.userErrorMsg);
else if (((LoginException)e).no_supervisor_students())
GUITools.show_alert(SerialActivity.this, R.string.noStudentsError);
else
GUITools.show_alert(SerialActivity.this, R.string.serverError, e.getMessage());
......@@ -262,7 +260,13 @@ public class SerialActivity extends Activity {
else
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -270,14 +274,14 @@ public class SerialActivity extends Activity {
setContentView(R.layout.activity_serial);
Intent intent=getIntent();
String activityName=intent.getStringExtra("activity_name");
final EditText mSerialViewMail = (EditText) findViewById(R.id.serialmail);
final EditText mSerialViewPass = (EditText) findViewById(R.id.serialpass);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
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
......
......@@ -220,13 +220,21 @@ public class StudentFragmentGrid extends Fragment{
e.printStackTrace();
}
}
show_student_list_online();
switch (students.length()) {
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;
case 1:
new_user(0);
break;
default:
show_student_list_online();
}
}
@Override
......
......@@ -13,6 +13,7 @@ import com.yottacode.pictogram.R;
import com.yottacode.pictogram.dao.LoginException;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.gui.PictogramActivity;
import com.yottacode.pictogram.gui.SerialActivity;
import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONArray;
......@@ -49,16 +50,6 @@ public class NetService implements Runnable {
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() {
User user=PCBcontext.getPcbdb().getCurrentUser();
......@@ -81,8 +72,8 @@ public class NetService implements Runnable {
@Override
public void error(Exception e) {
Log.e(this.getClass().getSimpleName(),"Error un when server login:"+e.getMessage());
if (e instanceof LoginException) restart_app();
Log.e(this.getClass().getSimpleName(), "Error un when server login:" + e.getMessage());
if (e instanceof LoginException) PCBcontext.restart_app();
}
});
else ServerLogin.login_student(user.get_nickname_stu(), user.get_pwd_stu(), new iRestapiListener() {
......@@ -104,7 +95,7 @@ public class NetService implements Runnable {
@Override
public void error(Exception e) {
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;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.yottacode.net.RestapiWrapper;
......@@ -11,6 +12,7 @@ import com.yottacode.pictogram.dao.Device;
import com.yottacode.pictogram.dao.PCBDBHelper;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.gui.SerialActivity;
import com.yottacode.pictogram.net.NetService;
import com.yottacode.pictogram.action.Room;
import com.yottacode.pictogram.net.iImgDownloaderListener;
......@@ -80,10 +82,18 @@ public final class PCBcontext {
room = new Room();
actionLog = new ActionLog();
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
......
......@@ -9,21 +9,30 @@ import android.util.Log;
* Created by Fernando on 01/04/2016.
*/
public class GUITools {
public static void show_alert(Context context, int resource_msg) {
show_alert(context, resource_msg, null);
public interface iOKListener {
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);
String msg = context.getString(resource_msg);
if (additional_msg!=null) msg+=": "+additional_msg;
Log.i(GUITools.class.getName(), "FERNANDO Alert:" + msg);
if (additional_msg != null) msg += ": " + additional_msg;
Log.i(GUITools.class.getName(), "Alert:" + msg);
builder.setMessage(msg)
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (oklistener != null) oklistener.ok();
}
});
AlertDialog alert = builder.create();
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