summaryrefslogtreecommitdiff
path: root/app/src/release
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-12-03 21:02:58 +0100
committerParménides GV <parmegv@sdf.org>2014-12-03 21:02:58 +0100
commitd67d127aa9691fbad10f93294c6b0b7e45406ed8 (patch)
tree093e94bac3e070fe28ee1428b29185d068ad1c90 /app/src/release
parentb4d6003265e49e537ec3fae16740de7885864520 (diff)
parent64c08c28dbd1b22451d990559b3f345cfcae05ba (diff)
Merge branch 'bug/Configuration-wizard-crashes-after-changing-orientation-#6471' into develop
Diffstat (limited to 'app/src/release')
-rw-r--r--app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java107
1 files changed, 70 insertions, 37 deletions
diff --git a/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java
index d3203ab3..9afcf8a1 100644
--- a/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/app/src/release/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.*;
@@ -52,6 +50,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 +60,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,6 +70,21 @@ 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) {
@@ -80,16 +97,32 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
loadPreseededProviders();
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);
@@ -122,11 +155,11 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
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();
+ unregisterReceiver(providerAPI_broadcast_receiver_update);
+ }
private void setUpProviderAPIResultReceiver() {
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
@@ -169,9 +202,9 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
mProgressBar.incrementProgressBy(1);
hideProgressBar();
- setResult(RESULT_OK);
-
showProviderDetails();
+
+ setResult(RESULT_OK);
} else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
hideProgressBar();
@@ -189,14 +222,16 @@ 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);
setUpProvider(selected_provider.providerMainUrl());
}
+
+ private void onItemSelectedUi(ProviderItem provider) {
+ startProgressBar();
+ int provider_index = getProviderIndex(provider.name());
+ provider_list_fragment.hideAllBut(provider_index);
+ }
@Override
public void onBackPressed() {
@@ -212,6 +247,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
mProgressBar.setVisibility(ProgressBar.GONE);
mProgressBar.setProgress(0);
progressbar_description.setVisibility(TextView.GONE);
+
preferences.edit().remove(Provider.KEY).commit();
setting_up_provider = false;
showAllProviders();
@@ -250,19 +286,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;
@@ -276,7 +309,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);