diff --git a/app/src/main/java/ua/samosfator/moduleok/Auth.java b/app/src/main/java/ua/samosfator/moduleok/Auth.java index 4d44942..dcaf5f0 100644 --- a/app/src/main/java/ua/samosfator/moduleok/Auth.java +++ b/app/src/main/java/ua/samosfator/moduleok/Auth.java @@ -16,7 +16,6 @@ public class Auth { private boolean success; public void signIn(String login, String password) { - EventBus.getDefault().register(this); downloadSessionId(login, password); } @@ -61,11 +60,6 @@ public boolean isSuccess() { return success; } - @SuppressWarnings("UnusedDeclaration") - public void onEvent(LoginEvent event) { - StudentKeeper.initStudent(); - } - public static boolean isLoggedIn() { return !Preferences.read("SESSIONID", "").equals(""); } diff --git a/app/src/main/java/ua/samosfator/moduleok/MainActivity.java b/app/src/main/java/ua/samosfator/moduleok/MainActivity.java index 1304604..b406fd0 100644 --- a/app/src/main/java/ua/samosfator/moduleok/MainActivity.java +++ b/app/src/main/java/ua/samosfator/moduleok/MainActivity.java @@ -33,7 +33,7 @@ protected void onCreate(Bundle savedInstanceState) { Preferences.init(getApplicationContext()); setContentView(R.layout.activity_main); - setAccountInfo(); + initAndSetAccountInfo(); StudentKeeper.initSemesterIndex(); initToolbar(); @@ -74,7 +74,7 @@ public void run() { }); } - private void setAccountInfo() { + private void initAndSetAccountInfo() { if (!Auth.isLoggedIn()) { eraseAccountInfo(); return; @@ -87,8 +87,8 @@ private void setAccountInfo() { @Override public void run() { try { - studentName_TextView.setText(StudentKeeper.getCurrentStudent().getNameSurname()); - studentGroup_TextView.setText(StudentKeeper.getCurrentStudent().getGroupName()); + studentName_TextView.setText(StudentKeeper.forceInitAndGetCurrentStudent().getNameSurname()); + studentGroup_TextView.setText(StudentKeeper.forceInitAndGetCurrentStudent().getGroupName()); openSubjectsFragment(); } catch (SessionIdExpiredException e) { @@ -140,7 +140,7 @@ public boolean onOptionsItemSelected(MenuItem item) { @SuppressWarnings("UnusedDeclaration") public void onEvent(LoginEvent event) { - setAccountInfo(); + initAndSetAccountInfo(); } @SuppressWarnings("UnusedDeclaration") diff --git a/app/src/main/java/ua/samosfator/moduleok/StudentKeeper.java b/app/src/main/java/ua/samosfator/moduleok/StudentKeeper.java index d8ef383..8a40c82 100644 --- a/app/src/main/java/ua/samosfator/moduleok/StudentKeeper.java +++ b/app/src/main/java/ua/samosfator/moduleok/StudentKeeper.java @@ -13,6 +13,11 @@ public static Student getCurrentStudent() { return student; } + public static Student forceInitAndGetCurrentStudent() { + initStudent(); + return student; + } + public static void initStudent() { student = new Student(PageLoader.getMainPageHtml(false)); } diff --git a/app/src/main/java/ua/samosfator/moduleok/fragment/LogoutFragment.java b/app/src/main/java/ua/samosfator/moduleok/fragment/LogoutFragment.java index bb587e9..473dd42 100644 --- a/app/src/main/java/ua/samosfator/moduleok/fragment/LogoutFragment.java +++ b/app/src/main/java/ua/samosfator/moduleok/fragment/LogoutFragment.java @@ -24,6 +24,7 @@ public LogoutFragment() { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_logout, container, false); Preferences.save("SESSIONID", ""); + Preferences.save("mainPageHtml", ""); EventBus.getDefault().post(new LogoutEvent()); Mint.logEvent("log out", MintLogLevel.Info); return rootView;