From 6ff5c7934e079a19a4d66499057aaaaa860c0e27 Mon Sep 17 00:00:00 2001 From: houxg Date: Thu, 16 Feb 2017 23:08:58 +0800 Subject: [PATCH] fix switch account issue --- .../org/houxg/leamonax/ui/Navigation.java | 1 + .../org/houxg/leamonax/ui/SignInActivity.java | 44 +++++++++---------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/org/houxg/leamonax/ui/Navigation.java b/app/src/main/java/org/houxg/leamonax/ui/Navigation.java index 59ba7c6..26e6b89 100644 --- a/app/src/main/java/org/houxg/leamonax/ui/Navigation.java +++ b/app/src/main/java/org/houxg/leamonax/ui/Navigation.java @@ -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); } } diff --git a/app/src/main/java/org/houxg/leamonax/ui/SignInActivity.java b/app/src/main/java/org/houxg/leamonax/ui/SignInActivity.java index 76ab0bc..e6146e9 100644 --- a/app/src/main/java/org/houxg/leamonax/ui/SignInActivity.java +++ b/app/src/main/java/org/houxg/leamonax/ui/SignInActivity.java @@ -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); } }); } @@ -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