diff options
author | Parménides GV <parmegv@sdf.org> | 2014-12-03 21:02:58 +0100 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2014-12-03 21:02:58 +0100 |
commit | d67d127aa9691fbad10f93294c6b0b7e45406ed8 (patch) | |
tree | 093e94bac3e070fe28ee1428b29185d068ad1c90 /app/src/debug | |
parent | b4d6003265e49e537ec3fae16740de7885864520 (diff) | |
parent | 64c08c28dbd1b22451d990559b3f345cfcae05ba (diff) |
Merge branch 'bug/Configuration-wizard-crashes-after-changing-orientation-#6471' into develop
Diffstat (limited to 'app/src/debug')
-rw-r--r-- | app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java | 140 |
1 files changed, 85 insertions, 55 deletions
diff --git a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java index 38084493..7c79c7c7 100644 --- a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java @@ -18,9 +18,7 @@ package se.leap.bitmaskclient; import android.app.*; import android.content.*; -import android.content.res.AssetManager; import android.os.*; -import android.util.Log; import android.view.*; import android.widget.*; import java.io.*; @@ -33,9 +31,7 @@ import se.leap.bitmaskclient.NewProviderDialog.NewProviderDialogInterface; import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver; import se.leap.bitmaskclient.ProviderDetailFragment.ProviderDetailFragmentInterface; import se.leap.bitmaskclient.ProviderListContent.ProviderItem; -import se.leap.bitmaskclient.FragmentManagerEnhanced; import se.leap.bitmaskclient.eip.Constants; -import se.leap.bitmaskclient.R; /** * Activity that builds and shows the list of known available providers. @@ -52,6 +48,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD private TextView progressbar_description; private ProviderListFragment provider_list_fragment; private Intent mConfigState = new Intent(); + private ProviderItem selected_provider; final public static String TAG = ConfigurationWizard.class.getSimpleName(); final public static String TYPE_OF_CERTIFICATE = "type_of_certificate"; @@ -61,6 +58,9 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD final protected static String PROVIDER_SET = "PROVIDER SET"; final protected static String SERVICES_RETRIEVED = "SERVICES RETRIEVED"; final protected static String ASSETS_URL_FOLDER = "urls"; + + final private static String PROGRESSBAR_TEXT = TAG + "PROGRESSBAR_TEXT"; + final private static String PROGRESSBAR_NUMBER = TAG + "PROGRESSBAR_NUMBER"; public ProviderAPIResultReceiver providerAPI_result_receiver; private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update; @@ -68,32 +68,62 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD private static SharedPreferences preferences; FragmentManagerEnhanced fragment_manager; private static boolean setting_up_provider = false; - + private String progressbar_text = ""; + private String provider_name = ""; + private int progress = -1; + + @Override + protected void onSaveInstanceState(Bundle outState) { + if(mProgressBar != null) + outState.putInt(PROGRESSBAR_NUMBER, mProgressBar.getProgress()); + if(progressbar_description != null) + outState.putString(PROGRESSBAR_TEXT, progressbar_description.getText().toString()); + if(selected_provider != null) + outState.putString(Provider.NAME, selected_provider.name()); + outState.putParcelable(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver); + super.onSaveInstanceState(outState); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - preferences = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE); - fragment_manager = new FragmentManagerEnhanced(getFragmentManager()); + preferences = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE); + fragment_manager = new FragmentManagerEnhanced(getFragmentManager()); + + setUpInitialUI(); - setUpInitialUI(); + loadPreseededProviders(); - loadPreseededProviders(); + setUpProviderAPIResultReceiver(); - setUpProviderAPIResultReceiver(); - - // Only create our fragments if we're not restoring a saved instance - if ( savedInstanceState == null ){ - // TODO Some welcome screen? - // We will need better flow control when we have more Fragments (e.g. user auth) - setUpProviderList(); + setUpProviderList(); + + if(savedInstanceState != null) { + progressbar_text = savedInstanceState.getString(PROGRESSBAR_TEXT, ""); + provider_name = savedInstanceState.getString(Provider.NAME, ""); + selected_provider = getProvider(provider_name); + progress = savedInstanceState.getInt(PROGRESSBAR_NUMBER, -1); + providerAPI_result_receiver = savedInstanceState.getParcelable(ProviderAPI.RECEIVER_KEY); + providerAPI_result_receiver.setReceiver(this); } + } - // TODO: If exposing deep links into your app, handle intents here. + @Override + protected void onPostResume() { + super.onPostResume(); + if(!progressbar_text.isEmpty() && !provider_name.isEmpty() && progress != -1) { + progressbar_description.setText(progressbar_text); + onItemSelectedUi(getProvider(provider_name)); + mProgressBar.setProgress(progress); + + progressbar_text = ""; + provider_name = ""; + progress = -1; + } } private void setUpInitialUI() { - setContentView(R.layout.configuration_wizard_activity); - + setContentView(R.layout.configuration_wizard_activity); hideProgressBar(); } @@ -119,15 +149,15 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD } private void putProviderListFragment(ProviderListFragment fragment) { - fragment_manager.replace(R.id.configuration_wizard_layout, provider_list_fragment, ProviderListFragment.TAG); } - @Override - protected void onDestroy() { - super.onDestroy(); - unregisterReceiver(providerAPI_broadcast_receiver_update); - } + @Override + protected void onDestroy() { + super.onDestroy(); + if(providerAPI_broadcast_receiver_update != null) + unregisterReceiver(providerAPI_broadcast_receiver_update); + } private void setUpProviderAPIResultReceiver() { providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); @@ -153,12 +183,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD hideProgressBar(); setResult(RESULT_OK); - + showProviderDetails(); } } else if(resultCode == ProviderAPI.PROVIDER_NOK) { hideProgressBar(); - preferences.edit().remove(Provider.KEY).commit(); + preferences.edit().remove(Provider.KEY).apply(); setting_up_provider = false; setResult(RESULT_CANCELED, mConfigState); @@ -169,10 +199,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) { mProgressBar.incrementProgressBy(1); hideProgressBar(); - - setResult(RESULT_OK); - + showProviderDetails(); + + setResult(RESULT_OK); } else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) { hideProgressBar(); @@ -190,17 +220,20 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD @Override public void onItemSelected(String id) { //TODO Code 2 pane view - ProviderItem selected_provider = getProvider(id); - int provider_index = getProviderIndex(id); - - startProgressBar(provider_index+1); - provider_list_fragment.hideAllBut(provider_index); + selected_provider = getProvider(id); + onItemSelectedUi(selected_provider); boolean danger_on = true; if(preferences.contains(ProviderItem.DANGER_ON)) danger_on = preferences.getBoolean(ProviderItem.DANGER_ON, false); setUpProvider(selected_provider.providerMainUrl(), danger_on); } + + private void onItemSelectedUi(ProviderItem provider) { + startProgressBar(); + int provider_index = getProviderIndex(provider.name()); + provider_list_fragment.hideAllBut(provider_index); + } @Override public void onBackPressed() { @@ -216,7 +249,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD mProgressBar.setVisibility(ProgressBar.GONE); mProgressBar.setProgress(0); progressbar_description.setVisibility(TextView.GONE); - preferences.edit().remove(Provider.KEY).commit(); + + preferences.edit().remove(Provider.KEY).apply(); setting_up_provider = false; showAllProviders(); } @@ -254,19 +288,16 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD return null; } - private void startProgressBar() { - mProgressBar.setVisibility(ProgressBar.VISIBLE); - progressbar_description.setVisibility(TextView.VISIBLE); - mProgressBar.setProgress(0); - mProgressBar.setMax(3); - } - - private void startProgressBar(int list_item_index) { - startProgressBar(); - int measured_height = listItemHeight(list_item_index); - mProgressBar.setTranslationY(measured_height); - progressbar_description.setTranslationY(measured_height + mProgressBar.getHeight()); - } + private void startProgressBar() { + mProgressBar.setVisibility(ProgressBar.VISIBLE); + progressbar_description.setVisibility(TextView.VISIBLE); + mProgressBar.setProgress(0); + mProgressBar.setMax(3); + + int measured_height = listItemHeight(); + mProgressBar.setTranslationY(measured_height); + progressbar_description.setTranslationY(measured_height + mProgressBar.getHeight()); + } private int getProviderIndex(String id) { int index = 0; @@ -280,7 +311,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD return index; } - private int listItemHeight(int list_item_index) { + private int listItemHeight() { ListView provider_list_view = (ListView)findViewById(android.R.id.list); ListAdapter provider_list_adapter = provider_list_view.getAdapter(); View listItem = provider_list_adapter.getView(0, null, provider_list_view); @@ -433,7 +464,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD DialogFragment newFragment = DownloadFailedDialog.newInstance(reason_to_fail); newFragment.show(fragment_transaction, DownloadFailedDialog.TAG); } - + /** * Once selected a provider, this fragment offers the user to log in, * use it anonymously (if possible) @@ -450,11 +481,11 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD public void showAndSelectProvider(String provider_main_url, boolean danger_on) { if(getId(provider_main_url).isEmpty()) - showProvider(provider_main_url, danger_on); + showProvider(provider_main_url); autoSelectProvider(provider_main_url, danger_on); } - private void showProvider(final String provider_main_url, final boolean danger_on) { + private void showProvider(final String provider_main_url) { String provider_name = provider_main_url.replaceFirst("http[s]?://", "").replaceFirst("\\/", "_"); ProviderItem added_provider = new ProviderItem(provider_name, provider_main_url); provider_list_fragment.addItem(added_provider); @@ -467,8 +498,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD /** * Asks ProviderAPI to download a new provider.json file - * @param provider_name - * @param provider_main_url +n * @param provider_main_url * @param danger_on tells if HTTPS client should bypass certificate errors */ public void setUpProvider(String provider_main_url, boolean danger_on) { |