diff options
author | Parménides GV <parmegv@sdf.org> | 2013-10-10 21:12:32 +0200 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2013-12-10 18:08:52 +0100 |
commit | 3c1a4d2da2531b510fd01f921093f8c007bb4d5a (patch) | |
tree | f617cce816dc27bb7e02baecddf2895d36bda3ec /src/se/leap/bitmaskclient/ConfigurationWizard.java | |
parent | 50ad1c04cee7fe3409a1c2958d4dba98882cd45d (diff) |
Simplified the methods to add a new provider.
Adding a new provider is the same that selecting a new one, using the same methods and following the same workflow.
Diffstat (limited to 'src/se/leap/bitmaskclient/ConfigurationWizard.java')
-rw-r--r-- | src/se/leap/bitmaskclient/ConfigurationWizard.java | 74 |
1 files changed, 23 insertions, 51 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java index 6d088a85..43ac8dd8 100644 --- a/src/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java @@ -238,7 +238,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn int provider_index = getProviderIndex(id);
startProgressBar(provider_index);
mSelectedProvider = selected_provider;
- updateProviderDotJson(mSelectedProvider.name(), mSelectedProvider.providerJsonUrl(), mSelectedProvider.completelyTrusted());
+ updateProviderDotJson(mSelectedProvider.providerMainUrl(), mSelectedProvider.completelyTrusted());
}
@Override
@@ -344,37 +344,6 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn }
/** - * Saves provider.json file associated with provider.
- *
- * If the provider is custom, the file has already been downloaded so we load it from memory.
- * If not, the file is updated using the provider's URL.
- * @param provider
- */
- private void saveProviderJson(ProviderItem provider) {
- JSONObject provider_json = new JSONObject();
- try {
- if(!provider.custom()) {
- updateProviderDotJson(mSelectedProvider.name(), provider.providerJsonUrl(), provider.completelyTrusted());
- } else {
- // FIXME!! We should we be updating our seeded providers list at ConfigurationWizard onStart() ?
- // I think yes, but if so, where does this list live? leap.se, as it's the non-profit project for the software?
- // If not, we should just be getting names/urls, and fetching the provider.json like in custom entries
- provider_json = ConfigHelper.getJsonFromSharedPref(Provider.KEY);
- ConfigHelper.saveSharedPref(Provider.KEY, provider_json);
- ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
- ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, provider.completelyTrusted());
-
- mProgressBar.incrementProgressBy(1);
-
- downloadJSONFiles(provider_json, provider.completelyTrusted());
- }
- } catch (JSONException e) {
- setResult(RESULT_CANCELED);
- finish();
- }
- }
-
- /** * Asks ProviderAPI to download provider site's certificate and eip-service.json
*
* URLs are fetched from the provider parameter
@@ -471,34 +440,37 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn newFragment.show(fragment_transaction, ProviderDetailFragment.TAG);
}
- @Override
- public void saveAndSelectProvider(String provider_main_url, boolean danger_on) {
- Intent provider_API_command = new Intent(this, ProviderAPI.class);
-
- Bundle parameters = new Bundle();
- parameters.putString(Provider.MAIN_URL, provider_main_url);
- parameters.putBoolean(ProviderItem.DANGER_ON, danger_on);
-
- provider_API_command.setAction(ProviderAPI.DOWNLOAD_NEW_PROVIDER_DOTJSON);
- provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
- provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
-
- startService(provider_API_command);
+ public void showAndSelectProvider(String provider_main_url, boolean danger_on) {
+ showProvider(provider_main_url, danger_on);
+ updateProviderDotJson(provider_main_url, danger_on);
+ }
+
+ private void showProvider(final String provider_main_url, final boolean danger_on) {
+ String provider_name = provider_main_url.replaceFirst("http[s]?://", "").replaceFirst("\\/", "_");
+ boolean custom = true;
+ final ProviderItem added_provider = new ProviderItem(provider_name, provider_main_url, custom, danger_on);
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ // TODO Auto-generated method stub
+ ProviderListContent.addItem(added_provider);
+ ProviderListFragment provider_list_fragment = (ProviderListFragment) getFragmentManager().findFragmentByTag("providerlist");
+ provider_list_fragment.notifyAdapter();
+ }
+ });
}
/**
* Asks ProviderAPI to download a new provider.json file
* @param provider_name
- * @param provider_json_url
+ * @param provider_main_url
* @param danger_on tells if HTTPS client should bypass certificate errors
*/
- public void updateProviderDotJson(String provider_name, String provider_json_url, boolean danger_on) {
-
-
+ public void updateProviderDotJson(String provider_main_url, boolean danger_on) {
Intent provider_API_command = new Intent(this, ProviderAPI.class);
Bundle parameters = new Bundle();
- parameters.putString(Provider.NAME, provider_name);
- parameters.putString(Provider.DOT_JSON_URL, provider_json_url);
+ parameters.putString(Provider.MAIN_URL, provider_main_url);
parameters.putBoolean(ProviderItem.DANGER_ON, danger_on);
provider_API_command.setAction(ProviderAPI.UPDATE_PROVIDER_DOTJSON);
|