From df1e68c672de71633e99234360ea92d77e67a86d Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Tue, 16 Jan 2018 18:31:37 +0100 Subject: corretly handle dialog on orientation change --- .../bitmaskclient/BaseConfigurationWizard.java | 25 ++++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java index 64ea4779..d0868437 100644 --- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java +++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java @@ -118,6 +118,7 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity //TODO: add some states (values for progressbarText) about ongoing setup or remove that field private boolean isActivityShowing; + private String reasonToFail; public abstract void retrySetUpProvider(); @@ -140,6 +141,13 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity outState.putString(PROGRESSBAR_TEXT, progressbarDescription.getText().toString()); outState.putString(ACTIVITY_STATE, mConfigState.getAction()); outState.putParcelable(Provider.KEY, selectedProvider); + + DialogFragment dialogFragment = (DialogFragment) fragmentManager.findFragmentByTag(DownloadFailedDialog.TAG); + if (dialogFragment != null) { + outState.putString(REASON_TO_FAIL, reasonToFail); + dialogFragment.dismiss(); + } + super.onSaveInstanceState(outState); } @@ -160,9 +168,15 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity } private void restoreState(Bundle savedInstanceState) { + selectedProvider = savedInstanceState.getParcelable(Provider.KEY); mConfigState.setAction(savedInstanceState.getString(ACTIVITY_STATE, PROVIDER_NOT_SET)); + reasonToFail = savedInstanceState.getString(REASON_TO_FAIL); + if(reasonToFail != null) { + showDownloadFailedDialog(); + } + if (SETTING_UP_PROVIDER.equals(mConfigState.getAction()) || PENDING_SHOW_FAILED_DIALOG.equals(mConfigState.getAction()) ) { @@ -180,9 +194,8 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity showProgressBar(); adapter.hideAllBut(adapter.indexOf(selectedProvider)); checkProviderSetUp(); - showDownloadFailedDialog(null); } else if (PENDING_SHOW_FAILED_DIALOG.equals(mConfigState.getAction())) { - showDownloadFailedDialog(mConfigState.getStringExtra(REASON_TO_FAIL)); + showDownloadFailedDialog(); } else if (SHOWING_PROVIDER_DETAILS.equals(mConfigState.getAction())) { cancelAndShowAllProviders(); } @@ -259,8 +272,8 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity setResult(RESULT_CANCELED, mConfigState); - String reasonToFail = resultData.getString(ERRORS); - showDownloadFailedDialog(reasonToFail); + reasonToFail = resultData.getString(ERRORS); + showDownloadFailedDialog(); } void handleCorrectlyDownloadedCertificate() { @@ -418,10 +431,8 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity /** * Shows an error dialog, if configuring of a provider failed. - * - * @param reasonToFail - the reason it has failed */ - public void showDownloadFailedDialog(String reasonToFail) { + public void showDownloadFailedDialog() { try { FragmentTransaction fragmentTransaction = fragmentManager.removePreviousFragment(DownloadFailedDialog.TAG); DialogFragment newFragment; -- cgit v1.2.3