summaryrefslogtreecommitdiff
path: root/src/se/leap/bitmaskclient/ConfigurationWizard.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/se/leap/bitmaskclient/ConfigurationWizard.java')
-rw-r--r--src/se/leap/bitmaskclient/ConfigurationWizard.java78
1 files changed, 45 insertions, 33 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java
index ee42bae9..b35123b0 100644
--- a/src/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -30,8 +30,10 @@ import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.os.Handler;
@@ -61,7 +63,6 @@ import android.widget.TextView;
public class ConfigurationWizard extends Activity
implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogInterface, ProviderDetailFragment.ProviderDetailFragmentInterface, Receiver {
- private ProviderItem mSelectedProvider;
private ProgressBar mProgressBar;
private TextView progressbar_description;
private ProviderListFragment provider_list_fragment;
@@ -76,6 +77,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
final protected static String SERVICES_RETRIEVED = "SERVICES RETRIEVED";
public ProviderAPIResultReceiver providerAPI_result_receiver;
+ private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -88,7 +91,11 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
progressbar_description.setVisibility(TextView.INVISIBLE);
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
providerAPI_result_receiver.setReceiver(this);
-
+ providerAPI_broadcast_receiver_update = new ProviderAPIBroadcastReceiver_Update();
+ IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_PROGRESSBAR);
+ update_intent_filter.addCategory(Intent.CATEGORY_DEFAULT);
+ registerReceiver(providerAPI_broadcast_receiver_update, update_intent_filter);
+
ConfigHelper.setSharedPreferences(getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE));
loadPreseededProviders();
@@ -114,6 +121,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
// TODO: If exposing deep links into your app, handle intents here.
}
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ unregisterReceiver(providerAPI_broadcast_receiver_update);
+ }
+
public void refreshProviderList(int top_padding) {
ProviderListFragment new_provider_list_fragment = new ProviderListFragment();
Bundle top_padding_bundle = new Bundle();
@@ -133,29 +146,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
try {
provider_json = new JSONObject(resultData.getString(Provider.KEY));
boolean danger_on = resultData.getBoolean(ProviderItem.DANGER_ON);
- ConfigHelper.saveSharedPref(Provider.KEY, provider_json);
- ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, danger_on);
- ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
mConfigState.setAction(PROVIDER_SET);
- if(resultData.containsKey(Provider.NAME)) {
- String provider_id = resultData.getString(Provider.NAME);
- mSelectedProvider = getProvider(provider_id);
- //provider_list_fragment.addItem(mSelectedProvider);
- //ProviderListContent.removeItem(mSelectedProvider);
-
- //refreshProviderList(0);
-
- if(!mProgressBar.isShown()) {
- int provider_index = getProviderIndex(provider_id);
- startProgressBar(provider_index);
- provider_list_fragment.hide(provider_index-2);
- //setProviderList(provider_list_fragment);
- }
- mProgressBar.incrementProgressBy(1);
- }
-
-
if (ConfigHelper.getBoolFromSharedPref(EIP.ALLOWED_ANON)){
mConfigState.putExtra(SERVICES_RETRIEVED, true);
downloadAnonCert();
@@ -163,14 +155,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
mProgressBar.incrementProgressBy(1);
mProgressBar.setVisibility(ProgressBar.GONE);
progressbar_description.setVisibility(TextView.GONE);
- //refreshProviderList(0);
- //Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG).show();
setResult(RESULT_OK);
showProviderDetails(getCurrentFocus());
}
- //downloadJSONFiles(provider_json, danger_on);
} catch (JSONException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
mProgressBar.setVisibility(ProgressBar.GONE);
progressbar_description.setVisibility(TextView.GONE);
@@ -214,8 +202,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
ProviderItem selected_provider = getProvider(id);
int provider_index = getProviderIndex(id);
startProgressBar(provider_index);
- mSelectedProvider = selected_provider;
- setUpProvider(mSelectedProvider.providerMainUrl(), true);
+ provider_list_fragment.hideAllBut(provider_index);
+ setUpProvider(selected_provider.providerMainUrl(), true);
}
@Override
@@ -238,16 +226,27 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
setResult(RESULT_CANCELED, ask_quit);
}
- private ProviderItem getProvider(String id) {
+ private ProviderItem getProvider(String name) {
Iterator<ProviderItem> providers_iterator = ProviderListContent.ITEMS.iterator();
while(providers_iterator.hasNext()) {
ProviderItem provider = providers_iterator.next();
- if(provider.name().equalsIgnoreCase(id)) {
+ if(provider.name().equalsIgnoreCase(name)) {
return provider;
}
}
return null;
}
+
+ private String getId(String provider_main_url) {
+ Iterator<ProviderItem> providers_iterator = ProviderListContent.ITEMS.iterator();
+ while(providers_iterator.hasNext()) {
+ ProviderItem provider = providers_iterator.next();
+ if(provider.providerMainUrl().equalsIgnoreCase(provider_main_url)) {
+ return provider.name();
+ }
+ }
+ return "";
+ }
private void startProgressBar(int list_item_index) {
mProgressBar.setVisibility(ProgressBar.VISIBLE);
@@ -264,10 +263,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
Iterator<ProviderItem> providers_iterator = ProviderListContent.ITEMS.iterator();
while(providers_iterator.hasNext()) {
ProviderItem provider = providers_iterator.next();
- index++;
if(provider.name().equalsIgnoreCase(id)) {
break;
}
+ index++;
}
return index;
}
@@ -391,7 +390,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
public void showAndSelectProvider(String provider_main_url, boolean danger_on) {
showProvider(provider_main_url, danger_on);
- setUpProvider(provider_main_url, danger_on);
+ autoSelectProvider(provider_main_url, danger_on);
}
private void showProvider(final String provider_main_url, final boolean danger_on) {
@@ -400,6 +399,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
provider_list_fragment.addItem(added_provider);
}
+ private void autoSelectProvider(String provider_main_url, boolean danger_on) {
+ onItemSelected(getId(provider_main_url));
+ }
+
/**
* Asks ProviderAPI to download a new provider.json file
* @param provider_name
@@ -475,4 +478,13 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
setResult(RESULT_OK);
finish();
}
+
+ public class ProviderAPIBroadcastReceiver_Update extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int update = intent.getIntExtra(ProviderAPI.CURRENT_PROGRESS, 0);
+ mProgressBar.setProgress(update);
+ }
+ }
}