summaryrefslogtreecommitdiff
path: root/src/se/leap
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-04-01 19:34:12 +0200
committerParménides GV <parmegv@sdf.org>2014-04-01 19:34:12 +0200
commitc5492cf88f081ab4c94cdbf8bdacf33e446da977 (patch)
treeb931219a9818f15989e81d4fa7afa30ae09ab35d /src/se/leap
parent709a26bf3a703636a6df713ae4a93d7817f8a906 (diff)
No duplicated providers can be entered by a user.
getId method is more intelligent, it builds URL objects and compare between them comparing their hosts, their ports and their protocols.
Diffstat (limited to 'src/se/leap')
-rw-r--r--src/se/leap/bitmaskclient/ConfigurationWizard.java78
1 files changed, 54 insertions, 24 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java
index 4b3673c5..f0aac40b 100644
--- a/src/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -16,21 +16,11 @@
*/
package se.leap.bitmaskclient;
-import java.io.IOException;
-import java.util.Iterator;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver;
-import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
-import se.leap.bitmaskclient.DownloadFailedDialog.DownloadFailedDialogInterface;
-import se.leap.bitmaskclient.NewProviderDialog.NewProviderDialogInterface;
-import se.leap.bitmaskclient.ProviderDetailFragment.ProviderDetailFragmentInterface;
+
+
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
@@ -48,16 +38,28 @@ import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.View.MeasureSpec;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ProgressBar;
-import android.view.View.MeasureSpec;
import android.view.WindowManager;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
+import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Iterator;
+import org.json.JSONException;
+import org.json.JSONObject;
+import se.leap.bitmaskclient.DownloadFailedDialog.DownloadFailedDialogInterface;
+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.R;
/**
* Activity that builds and shows the list of known available providers.
@@ -264,17 +266,44 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
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 String getId(String provider_main_url_string) {
+ try {
+ URL provider_url = new URL(provider_main_url_string);
+ URL aux_provider_url;
+ Iterator<ProviderItem> providers_iterator = ProviderListContent.ITEMS.iterator();
+ while(providers_iterator.hasNext()) {
+ ProviderItem provider = providers_iterator.next();
+ aux_provider_url = new URL(provider.providerMainUrl());
+ if(isSameURL(provider_url, aux_provider_url)) {
+ return provider.name();
+ }
+ }
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ return "";
}
+ /**
+ * Checks, whether 2 urls are pointing to the same location.
+ *
+ * @param url a url
+ * @param baseUrl an other url, that should be compared.
+ * @return true, if the urls point to the same host and port and use the
+ * same protocol, false otherwise.
+ */
+ private boolean isSameURL(final URL url, final URL baseUrl) {
+ if (!url.getProtocol().equals(baseUrl.getProtocol())) {
+ return false;
+ }
+ if (!url.getHost().equals(baseUrl.getHost())) {
+ return false;
+ }
+ if (url.getPort() != baseUrl.getPort()) {
+ return false;
+ }
+ return true;
+ }
private void startProgressBar() {
mProgressBar.setVisibility(ProgressBar.VISIBLE);
@@ -442,8 +471,9 @@ 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);
- autoSelectProvider(provider_main_url, danger_on);
+ autoSelectProvider(provider_main_url, danger_on);
}
private void showProvider(final String provider_main_url, final boolean danger_on) {