Skip to content

Commit

Permalink
Resolve #18 - Concurrency login issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vladholubiev committed Jan 26, 2015
1 parent 7dac9aa commit 5606766
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 0 additions & 6 deletions app/src/main/java/ua/samosfator/moduleok/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class Auth {
private boolean success;

public void signIn(String login, String password) {
EventBus.getDefault().register(this);
downloadSessionId(login, password);
}

Expand Down Expand Up @@ -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("");
}
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/ua/samosfator/moduleok/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected void onCreate(Bundle savedInstanceState) {
Preferences.init(getApplicationContext());

setContentView(R.layout.activity_main);
setAccountInfo();
initAndSetAccountInfo();
StudentKeeper.initSemesterIndex();

initToolbar();
Expand Down Expand Up @@ -74,7 +74,7 @@ public void run() {
});
}

private void setAccountInfo() {
private void initAndSetAccountInfo() {
if (!Auth.isLoggedIn()) {
eraseAccountInfo();
return;
Expand All @@ -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) {
Expand Down Expand Up @@ -140,7 +140,7 @@ public boolean onOptionsItemSelected(MenuItem item) {

@SuppressWarnings("UnusedDeclaration")
public void onEvent(LoginEvent event) {
setAccountInfo();
initAndSetAccountInfo();
}

@SuppressWarnings("UnusedDeclaration")
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/ua/samosfator/moduleok/StudentKeeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5606766

Please sign in to comment.