diff --git a/app/src/main/java/com/proxerme/app/activity/DashboardActivity.java b/app/src/main/java/com/proxerme/app/activity/DashboardActivity.java index 33bdb1c3..1d654391 100644 --- a/app/src/main/java/com/proxerme/app/activity/DashboardActivity.java +++ b/app/src/main/java/com/proxerme/app/activity/DashboardActivity.java @@ -143,14 +143,14 @@ protected void onCreate(Bundle savedInstanceState) { userManager.addOnLoginStateListener(new UserManager.OnLoginStateListener() { @Override public void onLogin(@NonNull LoginUser user) { - if (!isFinishing()) { + if (!isDestroyedCompat()) { drawerHelper.refreshHeader(); } } @Override public void onLogout() { - if (!isFinishing()) { + if (!isDestroyedCompat()) { drawerHelper.refreshHeader(); } } diff --git a/app/src/main/java/com/proxerme/app/activity/MainActivity.java b/app/src/main/java/com/proxerme/app/activity/MainActivity.java index dbc4e769..6071268e 100644 --- a/app/src/main/java/com/proxerme/app/activity/MainActivity.java +++ b/app/src/main/java/com/proxerme/app/activity/MainActivity.java @@ -2,6 +2,7 @@ import android.annotation.SuppressLint; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.customtabs.CustomTabsIntent; @@ -59,4 +60,8 @@ public void showPage(@NonNull String url) { CustomTabActivityHelper.openCustomTab( this, customTabsIntent, Uri.parse(url), new WebviewFallback()); } + + public boolean isDestroyedCompat() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && isDestroyed(); + } } diff --git a/app/src/main/java/com/proxerme/app/dialog/LoginDialog.java b/app/src/main/java/com/proxerme/app/dialog/LoginDialog.java index e6cce612..5e6c6126 100644 --- a/app/src/main/java/com/proxerme/app/dialog/LoginDialog.java +++ b/app/src/main/java/com/proxerme/app/dialog/LoginDialog.java @@ -38,6 +38,8 @@ */ public class LoginDialog extends DialogFragment { + private static final String STATE_LOADING = "login_loading"; + ViewGroup root; @Bind(R.id.dialog_login_username_container) @@ -69,6 +71,8 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { initViews(); if (savedInstanceState != null) { + loading = savedInstanceState.getBoolean(STATE_LOADING); + handleVisibility(); } @@ -107,6 +111,12 @@ public void onDismiss(DialogInterface dialog) { ProxerConnection.cancelSync(ProxerTag.LOGIN, false); } + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(STATE_LOADING, loading); + } + private void findViews() { root = (ViewGroup) View.inflate(getContext(), R.layout.dialog_login, null); ButterKnife.bind(this, root); @@ -118,6 +128,7 @@ private void initViews() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_GO) { login(); + return true; } return false; @@ -156,9 +167,11 @@ public void onLogin(@NonNull LoginUser user) { @Override public void onLoginFailed(@NonNull ProxerException exception) { - Toast.makeText(getContext(), - ErrorHandler.getMessageForErrorCode(getContext(), - exception.getErrorCode()), Toast.LENGTH_LONG).show(); + if (getContext() != null) { + Toast.makeText(getContext(), + ErrorHandler.getMessageForErrorCode(getContext(), + exception.getErrorCode()), Toast.LENGTH_LONG).show(); + } loading = false; handleVisibility(); diff --git a/build.gradle b/build.gradle index de68776b..b8233f22 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,9 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { repositories { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.4.0-beta3' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'com.android.tools.build:gradle:1.3.1' } }