summaryrefslogtreecommitdiff
path: root/src/se/leap
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-09-02 19:52:17 +0200
committercyBerta <richy@cyborgsociety.org>2013-11-15 23:25:16 +0100
commite865889715b8511dd432b89958e27975592d98ea (patch)
tree62496deb4f66cd3127b6511a9c5068557c5fb0cd /src/se/leap
parent1d57d052814b8d46f3bdc850893171f238cdb2ef (diff)
New provider hides other providers.
If a new provider is added, it gets selected automatically hiding all other providers, as if it had been selected clicking on it.
Diffstat (limited to 'src/se/leap')
-rw-r--r--src/se/leap/bitmaskclient/ConfigurationWizard.java38
-rw-r--r--src/se/leap/bitmaskclient/ProviderDetailFragment.java15
-rw-r--r--src/se/leap/bitmaskclient/ProviderListContent.java4
-rw-r--r--src/se/leap/bitmaskclient/ProviderListFragment.java12
-rw-r--r--src/se/leap/leapclient/ProviderListAdapter.java29
5 files changed, 67 insertions, 31 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java
index 0a0858ec..94400eaa 100644
--- a/src/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -61,6 +61,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
private ProviderItem mSelectedProvider;
private ProgressBar mProgressBar;
+ private ProviderListFragment provider_list_fragment;
private Intent mConfigState = new Intent();
final public static String TYPE_OF_CERTIFICATE = "type_of_certificate";
@@ -91,7 +92,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
if ( savedInstanceState == null ){
// TODO Some welcome screen?
// We will need better flow control when we have more Fragments (e.g. user auth)
- ProviderListFragment provider_list_fragment = new ProviderListFragment();
+ provider_list_fragment = new ProviderListFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
@@ -103,16 +104,23 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
}
public void refreshProviderList(int top_padding) {
- ProviderListFragment providerList = new ProviderListFragment();
+ ProviderListFragment new_provider_list_fragment = new ProviderListFragment();
Bundle top_padding_bundle = new Bundle();
top_padding_bundle.putInt(getResources().getString(R.string.top_padding), top_padding);
- providerList.setArguments(top_padding_bundle);
+ new_provider_list_fragment.setArguments(top_padding_bundle);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
- .replace(R.id.configuration_wizard_layout, providerList, getResources().getString(R.string.provider_list_fragment_tag))
+ .replace(R.id.configuration_wizard_layout, new_provider_list_fragment, getResources().getString(R.string.provider_list_fragment_tag))
.commit();
}
+
+ private void setProviderList(ProviderListFragment new_provider_list_fragment) {
+ FragmentManager fragmentManager = getFragmentManager();
+ fragmentManager.beginTransaction()
+ .replace(R.id.configuration_wizard_layout, new_provider_list_fragment, getResources().getString(R.string.provider_list_fragment_tag))
+ .commit();
+ }
@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
@@ -126,17 +134,21 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
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);
+
if(mSelectedProvider.custom)
refreshProviderList(0);
-
+
if(!mProgressBar.isShown()) {
int provider_index = getProviderIndex(provider_id);
startProgressBar(provider_index);
+ provider_list_fragment = (ProviderListFragment) getFragmentManager().findFragmentByTag(getResources().getString(R.string.provider_list_fragment_tag));
+ provider_list_fragment.hide(provider_index-2);
+ //setProviderList(provider_list_fragment);
}
mProgressBar.incrementProgressBy(1);
}
@@ -240,12 +252,6 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
return null;
}
- private void startProgressBar() {
- mProgressBar.setVisibility(ProgressBar.VISIBLE);
- mProgressBar.setProgress(0);
- mProgressBar.setMax(3);
- }
-
private void startProgressBar(int list_item_index) {
mProgressBar.setVisibility(ProgressBar.VISIBLE);
mProgressBar.setProgress(0);
@@ -509,6 +515,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
fragment_transaction.replace(R.id.configuration_wizard_layout, newFragment, AboutFragment.TAG).commit();
}
}
+
+ public void unhideAll() {
+ provider_list_fragment.unhideAll();
+ setProviderList(provider_list_fragment);
+ refreshProviderList(0);
+ }
@Override
public void login() {
diff --git a/src/se/leap/bitmaskclient/ProviderDetailFragment.java b/src/se/leap/bitmaskclient/ProviderDetailFragment.java
index 2616cdbf..8ec7d154 100644
--- a/src/se/leap/bitmaskclient/ProviderDetailFragment.java
+++ b/src/se/leap/bitmaskclient/ProviderDetailFragment.java
@@ -82,19 +82,12 @@ public class ProviderDetailFragment extends DialogFragment {
@Override
public void onCancel(DialogInterface dialog) {
- super.onCancel(dialog);
-<<<<<<< HEAD
+ super.onCancel(dialog);
ConfigHelper.removeFromSharedPref(Provider.KEY);
ConfigHelper.removeFromSharedPref(ProviderItem.DANGER_ON);
ConfigHelper.removeFromSharedPref(EIP.ALLOWED_ANON);
- ConfigHelper.removeFromSharedPref(EIP.KEY);
-=======
- ConfigHelper.removeFromSharedPref(ConfigHelper.PROVIDER_KEY);
- ConfigHelper.removeFromSharedPref(ConfigHelper.DANGER_ON);
- ConfigHelper.removeFromSharedPref(ConfigHelper.ALLOWED_ANON);
- ConfigHelper.removeFromSharedPref(ConfigHelper.EIP_SERVICE_KEY);
- interface_with_configuration_wizard.refreshProviderList(0);
->>>>>>> Only selected provider remain visible.
+ ConfigHelper.removeFromSharedPref(EIP.KEY);
+ interface_with_configuration_wizard.unhideAll();
}
public static DialogFragment newInstance() {
@@ -116,7 +109,7 @@ public class ProviderDetailFragment extends DialogFragment {
public interface ProviderDetailFragmentInterface {
public void login();
public void use_anonymously();
- public void refreshProviderList(int top_padding);
+ public void unhideAll();
}
ProviderDetailFragmentInterface interface_with_configuration_wizard;
diff --git a/src/se/leap/bitmaskclient/ProviderListContent.java b/src/se/leap/bitmaskclient/ProviderListContent.java
index 940a594d..75d91733 100644
--- a/src/se/leap/bitmaskclient/ProviderListContent.java
+++ b/src/se/leap/bitmaskclient/ProviderListContent.java
@@ -48,6 +48,10 @@ public class ProviderListContent {
ITEMS.add(item);
ITEM_MAP.put(String.valueOf(ITEMS.size()), item);
}
+ public static void removeItem(ProviderItem item) {
+ ITEMS.remove(item);
+ ITEM_MAP.remove(item);
+ }
/**
* A provider item.
diff --git a/src/se/leap/bitmaskclient/ProviderListFragment.java b/src/se/leap/bitmaskclient/ProviderListFragment.java
index d7ead700..8ccabd8f 100644
--- a/src/se/leap/bitmaskclient/ProviderListFragment.java
+++ b/src/se/leap/bitmaskclient/ProviderListFragment.java
@@ -182,4 +182,16 @@ public class ProviderListFragment extends ListFragment {
mActivatedPosition = position;
}
+
+ public void addItem(ProviderItem provider) {
+ content_adapter.add(provider);
+ }
+
+ public void hide(int position) {
+ content_adapter.hide(position);
+ }
+
+ public void unhideAll() {
+ content_adapter.unHideAll();
+ }
}
diff --git a/src/se/leap/leapclient/ProviderListAdapter.java b/src/se/leap/leapclient/ProviderListAdapter.java
index 61fe6bfa..e8782130 100644
--- a/src/se/leap/leapclient/ProviderListAdapter.java
+++ b/src/se/leap/leapclient/ProviderListAdapter.java
@@ -10,19 +10,25 @@ import android.widget.ArrayAdapter;
import android.widget.TwoLineListItem;
public class ProviderListAdapter<T> extends ArrayAdapter<T> {
- T[] items = null;
- boolean[] hidden = null;
+ private T[] items = null;
+ 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 unHideAll() {
+ for (int provider_index = 0; provider_index < hidden.length; provider_index++)
+ hidden[provider_index] = false;
+ }
private int getRealPosition(int position) {
int hElements = getHiddenCountUpTo(position);
@@ -58,9 +64,20 @@ public class ProviderListAdapter<T> extends ArrayAdapter<T> {
public ProviderListAdapter(Context mContext, int layout, List<T> objects) {
super(mContext, layout, objects);
items = objects.toArray((T[])new Object[0]);
- hidden = new boolean[items.length];
- for (int i = 0; i < items.length; i++)
- hidden[i] = false;
+ if(hidden == null) {
+ hidden = new boolean[items.length];
+ for (int i = 0; i < items.length; i++)
+ hidden[i] = false;
+ }
+ }
+
+ @Override
+ public void add(T item) {
+ super.add(item);
+ 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
@@ -76,8 +93,6 @@ public class ProviderListAdapter<T> extends ArrayAdapter<T> {
ProviderListContent.ProviderItem data = ProviderListContent.ITEMS.get(position);
row.getText1().setText(data.domain);
row.getText2().setText(data.name);
-
-
return row;
}