From 39d1a866d042441bf5c05520203973cb3ff5d357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 12 Nov 2013 17:23:30 +0100 Subject: New provider dialog remembers previous data. It also (supposedly, I didn't test because Bitmask is working ok from our client point of view) distinguishes between cancelling a new custom provider and cancelling a preseeded provider. --- src/se/leap/bitmaskclient/ConfigurationWizard.java | 35 +++++++-------- .../leap/bitmaskclient/DownloadFailedDialog.java | 50 ++++++++++++---------- 2 files changed, 45 insertions(+), 40 deletions(-) (limited to 'src/se/leap/bitmaskclient') diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java index 44d35370..e0a0d799 100644 --- a/src/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java @@ -444,23 +444,19 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD } public void retrySetUpProvider() { - removeLastProviderItem(); - addAndSelectNewProvider(ProviderAPI.lastProviderMainUrl(), ProviderAPI.lastDangerOn()); - /* - Intent provider_API_command = new Intent(this, ProviderAPI.class); - startService(provider_API_command); - */ - } + cancelSettingUpProvider(); + if(!ProviderAPI.caCertDownloaded()) { + addAndSelectNewProvider(ProviderAPI.lastProviderMainUrl(), ProviderAPI.lastDangerOn()); + } else { + Intent provider_API_command = new Intent(this, ProviderAPI.class); - public void retrySetUpProvider() { - Intent provider_API_command = new Intent(this, ProviderAPI.class); - - provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER); - provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver); - - startService(provider_API_command); - } + provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER); + provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver); + startService(provider_API_command); + } + } + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.configuration_wizard_activity, menu); @@ -504,11 +500,16 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD provider_list_fragment.unhideAll(); } - private void removeLastProviderItem() { + public void cancelSettingUpProvider() { provider_list_fragment = (ProviderListFragment) getFragmentManager().findFragmentByTag(ProviderListFragment.TAG); - if(provider_list_fragment != null) { + if(provider_list_fragment != null && ConfigHelper.sharedPrefContainsKey(ProviderItem.DANGER_ON)) { provider_list_fragment.removeLastItem(); } + + ConfigHelper.removeFromSharedPref(Provider.KEY); + ConfigHelper.removeFromSharedPref(ProviderItem.DANGER_ON); + ConfigHelper.removeFromSharedPref(EIP.ALLOWED_ANON); + ConfigHelper.removeFromSharedPref(EIP.KEY); } @Override diff --git a/src/se/leap/bitmaskclient/DownloadFailedDialog.java b/src/se/leap/bitmaskclient/DownloadFailedDialog.java index 4930da95..f78002b0 100644 --- a/src/se/leap/bitmaskclient/DownloadFailedDialog.java +++ b/src/se/leap/bitmaskclient/DownloadFailedDialog.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - package se.leap.bitmaskclient; +package se.leap.bitmaskclient; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.NewProviderDialog.NewProviderDialogInterface; @@ -45,46 +45,50 @@ public class DownloadFailedDialog extends DialogFragment { return dialog_fragment; } - @Override + @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - + builder.setMessage(reason_to_fail) .setPositiveButton(R.string.retry, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); + dismiss(); interface_with_ConfigurationWizard.retrySetUpProvider(); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - ConfigHelper.removeFromSharedPref(Provider.KEY); - ConfigHelper.removeFromSharedPref(ProviderItem.DANGER_ON); - ConfigHelper.removeFromSharedPref(EIP.ALLOWED_ANON); - ConfigHelper.removeFromSharedPref(EIP.KEY); - interface_with_ConfigurationWizard.retrySetUpProvider(); + interface_with_ConfigurationWizard.cancelSettingUpProvider(); dialog.dismiss(); } }); - + // Create the AlertDialog object and return it return builder.create(); } - + public interface DownloadFailedDialogInterface { - public void retrySetUpProvider(); - } + public void retrySetUpProvider(); + public void cancelSettingUpProvider(); + } DownloadFailedDialogInterface interface_with_ConfigurationWizard; - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - try { - interface_with_ConfigurationWizard = (DownloadFailedDialogInterface) activity; - } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() - + " must implement NoticeDialogListener"); - } - } + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + interface_with_ConfigurationWizard = (DownloadFailedDialogInterface) activity; + } catch (ClassCastException e) { + throw new ClassCastException(activity.toString() + + " must implement NoticeDialogListener"); + } + } + + @Override + public void onCancel(DialogInterface dialog) { + interface_with_ConfigurationWizard.cancelSettingUpProvider(); + dialog.dismiss(); + } + } -- cgit v1.2.3