summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java29
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Provider.java10
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java112
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderManager.java50
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java8
6 files changed, 56 insertions, 158 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
index 375ef038..b5040cdc 100644
--- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
@@ -27,7 +27,6 @@ import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.Menu;
-import android.view.MenuItem;
import android.widget.ListView;
import com.pedrogomez.renderers.Renderer;
@@ -168,7 +167,6 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity
isActivityShowing = true;
if (SETTING_UP_PROVIDER.equals(mConfigState.getAction())) {
showProgressBar();
- adapter.hideAllBut(adapter.indexOf(provider));
checkProviderSetUp();
} else if (PENDING_SHOW_FAILED_DIALOG.equals(mConfigState.getAction())) {
showDownloadFailedDialog();
@@ -274,10 +272,15 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity
}
//TODO Code 2 pane view
- mConfigState.setAction(SETTING_UP_PROVIDER);
provider = adapter.getItem(position);
- showProgressBar();
- onItemSelectedLogic();
+ if (provider != null && !provider.isDefault()) {
+ //TODO Code 2 pane view
+ mConfigState.setAction(SETTING_UP_PROVIDER);
+ showProgressBar();
+ onItemSelectedLogic();
+ } else {
+ addAndSelectNewProvider();
+ }
}
@Override
@@ -302,7 +305,6 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity
public void cancelSettingUpProvider() {
hideProgressBar();
mConfigState.setAction(PROVIDER_NOT_SET);
- adapter.showAllProviders();
preferences.edit().remove(Provider.KEY).remove(PROVIDER_ALLOW_ANONYMOUS).remove(PROVIDER_KEY).apply();
}
@@ -410,24 +412,9 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity
return true;
}
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.about_leap:
- startActivityForResult(new Intent(this, AboutFragment.class), 0);
- return true;
- case R.id.new_provider:
- addAndSelectNewProvider();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
-
public void cancelAndShowAllProviders() {
mConfigState.setAction(PROVIDER_NOT_SET);
provider = null;
- adapter.showAllProviders();
}
public class ProviderAPIBroadcastReceiver extends BroadcastReceiver {
diff --git a/app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java b/app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java
index 52c797a4..57ff1fd8 100644
--- a/app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java
+++ b/app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java
@@ -1,6 +1,7 @@
package se.leap.bitmaskclient;
-import java.net.*;
+import java.net.MalformedURLException;
+import java.net.URL;
public class DefaultedURL {
private URL DEFAULT_URL;
@@ -8,7 +9,7 @@ public class DefaultedURL {
private URL url;
- public DefaultedURL() {
+ DefaultedURL() {
try {
DEFAULT_URL = new URL(default_url);
url = DEFAULT_URL;
diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java
index 30504080..4d8c741d 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java
@@ -306,4 +306,14 @@ public final class Provider implements Parcelable {
putString(Provider.MAIN_URL, getMainUrl().toString()).
putString(Provider.KEY, getDefinition().toString()).apply();
}
+
+ public boolean isDefault() {
+ return getMainUrl().isDefault() &&
+ getApiUrl().isDefault() &&
+ certificatePin.isEmpty() &&
+ certificatePinEncoding.isEmpty() &&
+ caCert.isEmpty();
+
+ }
+
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java
index 4a34caa0..6672c575 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java
@@ -1,119 +1,15 @@
package se.leap.bitmaskclient;
-import android.view.*;
+import android.view.LayoutInflater;
-import com.pedrogomez.renderers.*;
-
-import java.util.*;
+import com.pedrogomez.renderers.AdapteeCollection;
+import com.pedrogomez.renderers.RendererAdapter;
+import com.pedrogomez.renderers.RendererBuilder;
public class ProviderListAdapter extends RendererAdapter<Provider> {
- private static boolean[] hidden = null;
-
- public void hide(int position) {
- hidden[getRealPosition(position)] = true;
- notifyDataSetChanged();
- notifyDataSetInvalidated();
- }
-
- public void unHide(int position) {
- hidden[getRealPosition(position)] = false;
- notifyDataSetChanged();
- notifyDataSetInvalidated();
- }
-
- public void showAllProviders() {
- for (int i = 0; i < hidden.length; i++)
- hidden[i] = false;
- notifyDataSetChanged();
- notifyDataSetInvalidated();
- }
-
- public void hideAllBut(int position) {
- for (int i = 0; i < hidden.length; i++) {
- if (i != position)
- hidden[i] = true;
- else
- hidden[i] = false;
- }
- notifyDataSetChanged();
- notifyDataSetInvalidated();
- }
-
- private int getRealPosition(int position) {
- int hElements = getHiddenCountUpTo(position);
- int diff = 0;
- for (int i = 0; i < hElements; i++) {
- diff++;
- if (hidden[position + diff])
- i--;
- }
- return (position + diff);
- }
-
- private int getHiddenCount() {
- int count = 0;
- for (int i = 0; i < hidden.length; i++)
- if (hidden[i])
- count++;
- return count;
- }
-
- private int getHiddenCountUpTo(int location) {
- int count = 0;
- for (int i = 0; i <= location; i++) {
- if (hidden[i])
- count++;
- }
- return count;
- }
-
- @Override
- public int getCount() {
- return (hidden.length - getHiddenCount());
- }
-
public ProviderListAdapter(LayoutInflater layoutInflater, RendererBuilder rendererBuilder,
AdapteeCollection<Provider> collection) {
super(layoutInflater, rendererBuilder, collection);
- hidden = new boolean[collection.size()];
- for (int i = 0; i < collection.size(); i++)
- hidden[i] = false;
- }
-
- @Override
- public void add(Provider item) {
- super.add(item);
- if (getCollection().size() > hidden.length) {
- boolean[] new_hidden = new boolean[hidden.length + 1];
- System.arraycopy(hidden, 0, new_hidden, 0, hidden.length);
- new_hidden[hidden.length] = false;
- hidden = new_hidden;
- }
- }
-
- @Override
- public void remove(Provider item) {
- super.remove(item);
- boolean[] new_hidden = new boolean[hidden.length - 1];
- System.arraycopy(hidden, 0, new_hidden, 0, hidden.length - 1);
- hidden = new_hidden;
- }
-
- protected int indexOf(Provider item) {
- int index = 0;
- ProviderManager provider_manager = (ProviderManager) getCollection();
- Set<Provider> providers = provider_manager.providers();
- for (Provider provider : providers) {
- if (provider.equals(item)) {
- break;
- } else index++;
- }
- return index;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- return super.getView(getRealPosition(position), convertView, parent);
}
public void saveProviders() {
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java
index 62c04c1a..ed41be67 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java
@@ -15,9 +15,11 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
/**
@@ -25,15 +27,14 @@ import java.util.Set;
*/
public class ProviderManager implements AdapteeCollection<Provider> {
- private static final String TAG = ProviderManager.class.getName();
- private AssetManager assets_manager;
+ private AssetManager assetsManager;
private File externalFilesDir;
private Set<Provider> defaultProviders;
private Set<Provider> customProviders;
private static ProviderManager instance;
- final protected static String URLS = "urls";
+ final private static String URLS = "urls";
public static ProviderManager getInstance(AssetManager assetsManager, File externalFilesDir) {
if (instance == null)
@@ -42,8 +43,8 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return instance;
}
- public ProviderManager(AssetManager assetManager, File externalFilesDir) {
- this.assets_manager = assetManager;
+ private ProviderManager(AssetManager assetManager, File externalFilesDir) {
+ this.assetsManager = assetManager;
addDefaultProviders(assetManager);
addCustomProviders(externalFilesDir);
}
@@ -57,7 +58,7 @@ public class ProviderManager implements AdapteeCollection<Provider> {
}
private Set<Provider> providersFromAssets(String directory, String[] relativeFilePaths) {
- Set<Provider> providers = new HashSet<Provider>();
+ Set<Provider> providers = new HashSet<>();
for (String file : relativeFilePaths) {
String mainUrl = null;
@@ -65,10 +66,10 @@ public class ProviderManager implements AdapteeCollection<Provider> {
String providerDefinition = null;
try {
String provider = file.substring(0, file.length() - ".url".length());
- InputStream provider_file = assets_manager.open(directory + "/" + file);
+ InputStream provider_file = assetsManager.open(directory + "/" + file);
mainUrl = extractMainUrlFromInputStream(provider_file);
- certificate = ConfigHelper.loadInputStreamAsString(assets_manager.open(provider + ".pem"));
- providerDefinition = ConfigHelper.loadInputStreamAsString(assets_manager.open(provider + ".json"));
+ certificate = ConfigHelper.loadInputStreamAsString(assetsManager.open(provider + ".pem"));
+ providerDefinition = ConfigHelper.loadInputStreamAsString(assetsManager.open(provider + ".json"));
} catch (IOException e) {
e.printStackTrace();
}
@@ -91,11 +92,11 @@ public class ProviderManager implements AdapteeCollection<Provider> {
}
private Set<Provider> providersFromFiles(String[] files) {
- Set<Provider> providers = new HashSet<Provider>();
+ Set<Provider> providers = new HashSet<>();
try {
for (String file : files) {
- String main_url = extractMainUrlFromInputStream(new FileInputStream(externalFilesDir.getAbsolutePath() + "/" + file));
- providers.add(new Provider(new URL(main_url)));
+ String mainUrl = extractMainUrlFromInputStream(new FileInputStream(externalFilesDir.getAbsolutePath() + "/" + file));
+ providers.add(new Provider(new URL(mainUrl)));
}
} catch (MalformedURLException | FileNotFoundException e) {
e.printStackTrace();
@@ -104,12 +105,12 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return providers;
}
- private String extractMainUrlFromInputStream(InputStream input_stream) {
+ private String extractMainUrlFromInputStream(InputStream inputStream) {
String mainUrl = "";
- JSONObject file_contents = inputStreamToJson(input_stream);
- if (file_contents != null)
- mainUrl = file_contents.optString(Provider.MAIN_URL);
+ JSONObject fileContents = inputStreamToJson(inputStream);
+ if (fileContents != null)
+ mainUrl = fileContents.optString(Provider.MAIN_URL);
return mainUrl;
}
@@ -126,12 +127,13 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return json;
}
- public Set<Provider> providers() {
- Set<Provider> all_providers = new HashSet<Provider>();
- all_providers.addAll(defaultProviders);
+ public List<Provider> providers() {
+ List<Provider> allProviders = new ArrayList<>();
+ allProviders.addAll(defaultProviders);
if(customProviders != null)
- all_providers.addAll(customProviders);
- return all_providers;
+ allProviders.addAll(customProviders);
+ allProviders.add(new Provider());
+ return allProviders;
}
@Override
@@ -151,9 +153,7 @@ public class ProviderManager implements AdapteeCollection<Provider> {
@Override
public boolean add(Provider element) {
- if (!defaultProviders.contains(element))
- return customProviders.add(element);
- else return true;
+ return !defaultProviders.contains(element) || customProviders.add(element);
}
@Override
@@ -179,7 +179,7 @@ public class ProviderManager implements AdapteeCollection<Provider> {
customProviders.clear();
}
- protected void saveCustomProvidersToFile() {
+ void saveCustomProvidersToFile() {
try {
for (Provider provider : customProviders) {
File providerFile = new File(externalFilesDir, provider.getName() + ".json");
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java b/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java
index 4a5d0db1..5b3e5728 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java
@@ -45,7 +45,11 @@ public class ProviderRenderer extends Renderer<Provider> {
@Override
public void render() {
Provider provider = getContent();
- name.setText(provider.getName());
- domain.setText(provider.getDomain());
+ if (!provider.isDefault()) {
+ name.setText(provider.getName());
+ domain.setText(provider.getDomain());
+ } else {
+ domain.setText(R.string.add_provider);
+ }
}
}