summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-12-09 11:20:31 +0100
committerParménides GV <parmegv@sdf.org>2014-12-09 11:20:31 +0100
commit84f71ca604abb2b4aeb410dcec2c3cc5dff9bc39 (patch)
tree53d1b8ada01b3de40de043a7781c5801da05bd5b /app/src/main
parent202036aa6befcb1c74a76803f22e020404d4ba34 (diff)
Switching provider doesn't refresh provider list.
It shows just one provider, and it's not the one that gets configured if selected.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java32
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Provider.java16
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java79
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderListFragment.java26
4 files changed, 82 insertions, 71 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index e1d08d08..e277221b 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -87,8 +87,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
handleVersion();
- boolean no_provider_configured = preferences.getString(Constants.KEY, "").isEmpty();
- if (no_provider_configured)
+
+ if (provider == null)
startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP);
else
buildDashboard(getIntent().getBooleanExtra(ON_BOOT, false));
@@ -132,21 +132,21 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
Log.d(TAG, "onActivityResult: requestCode = " + requestCode);
if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) {
// It should be equivalent: if ( (requestCode == CONFIGURE_LEAP) || (data!= null && data.hasExtra(STOP_FIRST))) {
- if ( resultCode == RESULT_OK ){
- preferences.edit().putInt(Constants.PARSED_SERIAL, 0).apply();
- preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
- updateEipService();
- buildDashboard(false);
- invalidateOptionsMenu();
- if(data != null)
- if(data.hasExtra(LogInDialog.TAG)) {
- logInDialog(Bundle.EMPTY);
- }
- if(data.hasExtra(Provider.KEY))
+ if ( resultCode == RESULT_OK ) {
+ preferences.edit().putInt(Constants.PARSED_SERIAL, 0).apply();
+ preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
+ updateEipService();
+
+ if (data.hasExtra(Provider.KEY))
provider = data.getParcelableExtra(Provider.KEY);
- } else if(resultCode == RESULT_CANCELED && (data == null || data.hasExtra(ACTION_QUIT))) {
- finish();
- } else
+ buildDashboard(false);
+ invalidateOptionsMenu();
+ if (data.hasExtra(LogInDialog.TAG)) {
+ logInDialog(Bundle.EMPTY);
+ } else if (resultCode == RESULT_CANCELED && data.hasExtra(ACTION_QUIT)) {
+ finish();
+ }
+ } else
configErrorDialog();
} else if(requestCode == EIP.DISCONNECT) {
EipStatus.getInstance().setConnectedOrDisconnected();
diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java
index 0d584310..dd679bb2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java
@@ -86,7 +86,9 @@ public final class Provider implements Parcelable {
private Provider(Parcel in) {
try {
main_url = new URL(in.readString());
- definition = new JSONObject((in.readString()));
+ String definition_string = in.readString();
+ if(definition_string != null)
+ definition = new JSONObject((definition_string));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (JSONException e) {
@@ -94,7 +96,6 @@ public final class Provider implements Parcelable {
}
}
-
protected void define(JSONObject provider_json) {
definition = provider_json;
}
@@ -175,6 +176,15 @@ public final class Provider implements Parcelable {
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(main_url.toString());
- parcel.writeString(definition.toString());
+ if(definition != null)
+ parcel.writeString(definition.toString());
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if(o instanceof Provider) {
+ Provider p = (Provider) o;
+ return p.mainUrl().equals(mainUrl());
+ } else return false;
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java
index 1148e65e..92b2ae2e 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java
@@ -7,9 +7,15 @@ import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TwoLineListItem;
+import com.pedrogomez.renderers.AdapteeCollection;
+import com.pedrogomez.renderers.RendererAdapter;
+import com.pedrogomez.renderers.RendererBuilder;
+
+import java.util.Collection;
import java.util.List;
+import java.util.Set;
-public class ProviderListAdapter<T> extends ArrayAdapter<T> {
+public class ProviderListAdapter extends RendererAdapter<Provider> {
private static boolean[] hidden = null;
public void hide(int position) {
@@ -23,10 +29,23 @@ public class ProviderListAdapter<T> extends ArrayAdapter<T> {
notifyDataSetChanged();
notifyDataSetInvalidated();
}
+
+ public void showAllProviders() {
+ for(int i = 0; i < hidden.length; i++)
+ hidden[i] = false;
+ notifyDataSetChanged();
+ notifyDataSetInvalidated();
+ }
- public void unHideAll() {
- for (int provider_index = 0; provider_index < hidden.length; provider_index++)
- hidden[provider_index] = false;
+ 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) {
@@ -60,26 +79,28 @@ public class ProviderListAdapter<T> extends ArrayAdapter<T> {
return (hidden.length - getHiddenCount());
}
- public ProviderListAdapter(Context mContext, int layout, List<T> objects) {
- super(mContext, layout, objects);
+ public ProviderListAdapter(LayoutInflater layoutInflater, RendererBuilder rendererBuilder,
+ AdapteeCollection<Provider> collection) {
+ super(layoutInflater, rendererBuilder, collection);
if(hidden == null) {
- hidden = new boolean[objects.size()];
- for (int i = 0; i < objects.size(); i++)
+ hidden = new boolean[collection.size()];
+ for (int i = 0; i < collection.size(); i++)
hidden[i] = false;
}
}
- public ProviderListAdapter(Context mContext, int layout, List<T> objects, boolean show_all_providers) {
- super(mContext, layout, objects);
+ public ProviderListAdapter(LayoutInflater layoutInflater, RendererBuilder rendererBuilder,
+ AdapteeCollection<Provider> collection, boolean show_all_providers) {
+ super(layoutInflater, rendererBuilder, collection);
if(show_all_providers) {
- hidden = new boolean[objects.size()];
- for (int i = 0; i < objects.size(); i++)
+ hidden = new boolean[collection.size()];
+ for (int i = 0; i < collection.size(); i++)
hidden[i] = false;
}
}
@Override
- public void add(T item) {
+ public void add(Provider item) {
super.add(item);
boolean[] new_hidden = new boolean[hidden.length+1];
System.arraycopy(hidden, 0, new_hidden, 0, hidden.length);
@@ -88,27 +109,27 @@ public class ProviderListAdapter<T> extends ArrayAdapter<T> {
}
@Override
- public void remove(T item) {
+ 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;
}
- @Override
- public View getView(int index, View convertView, ViewGroup parent) {
- TwoLineListItem row;
- int position = getRealPosition(index);
- if (convertView == null) {
- LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- row = (TwoLineListItem)inflater.inflate(R.layout.provider_list_item, null);
- } else {
- row = (TwoLineListItem)convertView;
- }
- ProviderListContent.ProviderItem data = ProviderListContent.ITEMS.get(position);
- row.getText1().setText(data.domain());
- row.getText2().setText(data.name());
+ 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;
+ }
- return row;
- }
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ return super.getView(getRealPosition(position), convertView, parent);
+ }
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderListFragment.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListFragment.java
index 6d40bf9f..875b76d7 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderListFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderListFragment.java
@@ -40,7 +40,7 @@ public class ProviderListFragment extends ListFragment {
public static String TAG = "provider_list_fragment";
public static String SHOW_ALL_PROVIDERS = "show_all_providers";
public static String TOP_PADDING = "top padding from providerlistfragment";
- private ProviderListAdapter<ProviderItem> content_adapter;
+ private ProviderListAdapter content_adapter;
/**
* The serialization (saved instance state) Bundle key representing the
@@ -91,19 +91,7 @@ public class ProviderListFragment extends ListFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if(getArguments().containsKey(SHOW_ALL_PROVIDERS))
- content_adapter = new ProviderListAdapter<ProviderListContent.ProviderItem>(
- getActivity(),
- R.layout.provider_list_item,
- ProviderListContent.ITEMS, getArguments().getBoolean(SHOW_ALL_PROVIDERS));
- else
- content_adapter = new ProviderListAdapter<ProviderListContent.ProviderItem>(
- getActivity(),
- R.layout.provider_list_item,
- ProviderListContent.ITEMS);
-
-
- setListAdapter(content_adapter);
+
}
@Override
@@ -198,12 +186,11 @@ public class ProviderListFragment extends ListFragment {
}
public void removeLastItem() {
- unhideAll();
content_adapter.remove(content_adapter.getItem(content_adapter.getCount()-1));
content_adapter.notifyDataSetChanged();
}
- public void addItem(ProviderItem provider) {
+ public void addItem(Provider provider) {
content_adapter.add(provider);
content_adapter.notifyDataSetChanged();
}
@@ -219,13 +206,6 @@ public class ProviderListFragment extends ListFragment {
i++;
}
}
-
- public void unhideAll() {
- if(content_adapter != null) {
- content_adapter.unHideAll();
- content_adapter.notifyDataSetChanged();
- }
- }
/**
* @return a new instance of this ListFragment.