Skip to content

Commit

Permalink
fix switch account issue
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingRadish committed Feb 16, 2017
1 parent 2d56432 commit 6ff5c79
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/org/houxg/leamonax/ui/Navigation.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public void onClickAccount(View v, final Account account) {
@Override
public void onClickAddAccount() {
Intent intent = new Intent(mActivity, SignInActivity.class);
intent.setAction(SignInActivity.ACTION_ADD_ACCOUNT);
mActivity.startActivityForResult(intent, REQ_ADD_ACCOUNT);
}
}
Expand Down
44 changes: 20 additions & 24 deletions app/src/main/java/org/houxg/leamonax/ui/SignInActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,7 @@ public void onError(Throwable e) {

@Override
public void onNext(Authentication authentication) {
if (authentication.isOk()) {
long localId = AccountService.saveToAccount(authentication, host);
if (ACTION_ADD_ACCOUNT.equals(getIntent().getAction())) {
Intent intent = new Intent();
intent.putExtra(EXTRA_ACCOUNT_LOCAL_ID, localId);
setResult(RESULT_OK, intent);
} else {
Intent intent = MainActivity.getOpenIntent(SignInActivity.this, true);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
} else {
ToastUtils.show(SignInActivity.this, R.string.email_or_password_incorrect);
}
handleAuthResponse(authentication, host);
}
});
}
Expand Down Expand Up @@ -290,19 +276,29 @@ public void onError(Throwable e) {

@Override
public void onNext(Authentication authentication) {
if (authentication.isOk()) {
AccountService.saveToAccount(authentication, host);
Intent intent = MainActivity.getOpenIntent(SignInActivity.this, true);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
} else {
ToastUtils.show(SignInActivity.this, R.string.email_or_password_incorrect);
}
handleAuthResponse(authentication, host);
}
});
}

private void handleAuthResponse(Authentication authentication, String host) {
if (authentication.isOk()) {
long localId = AccountService.saveToAccount(authentication, host);
if (ACTION_ADD_ACCOUNT.equals(getIntent().getAction())) {
Intent intent = new Intent();
intent.putExtra(EXTRA_ACCOUNT_LOCAL_ID, localId);
setResult(RESULT_OK, intent);
} else {
Intent intent = MainActivity.getOpenIntent(SignInActivity.this, true);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
finish();
} else {
ToastUtils.show(SignInActivity.this, R.string.email_or_password_incorrect);
}
}

/**
*
* @param data
Expand Down

0 comments on commit 6ff5c79

Please sign in to comment.