summaryrefslogtreecommitdiff
path: root/src/se/leap
diff options
context:
space:
mode:
Diffstat (limited to 'src/se/leap')
-rw-r--r--src/se/leap/bitmaskclient/ConfigurationWizard.java78
-rw-r--r--src/se/leap/bitmaskclient/Dashboard.java30
-rw-r--r--src/se/leap/bitmaskclient/ProviderAPI.java38
-rw-r--r--src/se/leap/bitmaskclient/ProviderListAdapter.java1
-rw-r--r--src/se/leap/bitmaskclient/ProviderListFragment.java8
5 files changed, 61 insertions, 94 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java
index 362e3c7a..0e44dd04 100644
--- a/src/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -31,8 +31,10 @@ import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.os.Handler;
@@ -61,7 +63,6 @@ import android.widget.TextView;
public class ConfigurationWizard extends Activity
implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogInterface, ProviderDetailFragment.ProviderDetailFragmentInterface, Receiver {
- private ProviderItem mSelectedProvider;
private ProgressBar mProgressBar;
private TextView progressbar_description;
private ProviderListFragment provider_list_fragment;
@@ -75,6 +76,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
final protected static String SERVICES_RETRIEVED = "SERVICES RETRIEVED";
public ProviderAPIResultReceiver providerAPI_result_receiver;
+ private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -87,7 +90,11 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
progressbar_description.setVisibility(TextView.INVISIBLE);
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
providerAPI_result_receiver.setReceiver(this);
-
+ providerAPI_broadcast_receiver_update = new ProviderAPIBroadcastReceiver_Update();
+ IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_PROGRESSBAR);
+ update_intent_filter.addCategory(Intent.CATEGORY_DEFAULT);
+ registerReceiver(providerAPI_broadcast_receiver_update, update_intent_filter);
+
ConfigHelper.setSharedPreferences(getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE));
loadPreseededProviders();
@@ -113,6 +120,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
// TODO: If exposing deep links into your app, handle intents here.
}
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ unregisterReceiver(providerAPI_broadcast_receiver_update);
+ }
+
public void refreshProviderList(int top_padding) {
ProviderListFragment new_provider_list_fragment = new ProviderListFragment();
Bundle top_padding_bundle = new Bundle();
@@ -132,29 +145,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
try {
provider_json = new JSONObject(resultData.getString(Provider.KEY));
boolean danger_on = resultData.getBoolean(ProviderItem.DANGER_ON);
- ConfigHelper.saveSharedPref(Provider.KEY, provider_json);
- ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, danger_on);
- 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);
-
- //refreshProviderList(0);
-
- if(!mProgressBar.isShown()) {
- int provider_index = getProviderIndex(provider_id);
- startProgressBar(provider_index);
- provider_list_fragment.hide(provider_index-2);
- //setProviderList(provider_list_fragment);
- }
- mProgressBar.incrementProgressBy(1);
- }
-
-
if (ConfigHelper.getBoolFromSharedPref(EIP.ALLOWED_ANON)){
mConfigState.putExtra(SERVICES_RETRIEVED, true);
downloadAnonCert();
@@ -162,14 +154,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
mProgressBar.incrementProgressBy(1);
mProgressBar.setVisibility(ProgressBar.GONE);
progressbar_description.setVisibility(TextView.GONE);
- //refreshProviderList(0);
- //Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG).show();
setResult(RESULT_OK);
showProviderDetails(getCurrentFocus());
}
- //downloadJSONFiles(provider_json, danger_on);
} catch (JSONException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
mProgressBar.setVisibility(ProgressBar.GONE);
progressbar_description.setVisibility(TextView.GONE);
@@ -212,8 +200,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
ProviderItem selected_provider = getProvider(id);
int provider_index = getProviderIndex(id);
startProgressBar(provider_index);
- mSelectedProvider = selected_provider;
- setUpProvider(mSelectedProvider.providerMainUrl(), true);
+ provider_list_fragment.hideAllBut(provider_index);
+ setUpProvider(selected_provider.providerMainUrl(), true);
}
@Override
@@ -236,16 +224,27 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
setResult(RESULT_CANCELED, ask_quit);
}
- private ProviderItem getProvider(String id) {
+ private ProviderItem getProvider(String name) {
Iterator<ProviderItem> providers_iterator = ProviderListContent.ITEMS.iterator();
while(providers_iterator.hasNext()) {
ProviderItem provider = providers_iterator.next();
- if(provider.name().equalsIgnoreCase(id)) {
+ if(provider.name().equalsIgnoreCase(name)) {
return provider;
}
}
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 void startProgressBar(int list_item_index) {
mProgressBar.setVisibility(ProgressBar.VISIBLE);
@@ -262,10 +261,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
Iterator<ProviderItem> providers_iterator = ProviderListContent.ITEMS.iterator();
while(providers_iterator.hasNext()) {
ProviderItem provider = providers_iterator.next();
- index++;
if(provider.name().equalsIgnoreCase(id)) {
break;
}
+ index++;
}
return index;
}
@@ -389,7 +388,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
public void showAndSelectProvider(String provider_main_url, boolean danger_on) {
showProvider(provider_main_url, danger_on);
- setUpProvider(provider_main_url, danger_on);
+ autoSelectProvider(provider_main_url, danger_on);
}
private void showProvider(final String provider_main_url, final boolean danger_on) {
@@ -398,6 +397,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
provider_list_fragment.addItem(added_provider);
}
+ private void autoSelectProvider(String provider_main_url, boolean danger_on) {
+ onItemSelected(getId(provider_main_url));
+ }
+
/**
* Asks ProviderAPI to download a new provider.json file
* @param provider_name
@@ -474,4 +477,13 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
setResult(RESULT_OK);
finish();
}
+
+ public class ProviderAPIBroadcastReceiver_Update extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int update = intent.getIntExtra(ProviderAPI.CURRENT_PROGRESS, 0);
+ mProgressBar.setProgress(update);
+ }
+ }
}
diff --git a/src/se/leap/bitmaskclient/Dashboard.java b/src/se/leap/bitmaskclient/Dashboard.java
index fa91f9d2..dab8742a 100644
--- a/src/se/leap/bitmaskclient/Dashboard.java
+++ b/src/se/leap/bitmaskclient/Dashboard.java
@@ -16,8 +16,6 @@
*/
package se.leap.bitmaskclient;
-import org.apache.http.cookie.Cookie;
-import org.apache.http.impl.cookie.BasicClientCookie;
import org.json.JSONException;
import org.json.JSONObject;
@@ -30,12 +28,9 @@ import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
-import android.app.ProgressDialog;
-import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
@@ -44,11 +39,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.view.ViewStub;
-import android.widget.CompoundButton;
import android.widget.ProgressBar;
-import android.widget.RelativeLayout;
-import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
@@ -71,7 +62,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
private ProgressBar mProgressBar;
private TextView eipStatus;
- private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
private static Context app;
private static SharedPreferences preferences;
private static Provider provider;
@@ -92,10 +82,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
//mProgressBar = (ProgressBar) findViewById(R.id.progressbar_dashboard);
- providerAPI_broadcast_receiver_update = new ProviderAPIBroadcastReceiver_Update();
- IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_ACTION);
- update_intent_filter.addCategory(Intent.CATEGORY_DEFAULT);
- registerReceiver(providerAPI_broadcast_receiver_update, update_intent_filter);
+ mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
ConfigHelper.setSharedPreferences(getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE));
preferences = ConfigHelper.shared_preferences;
@@ -110,7 +97,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
@Override
protected void onDestroy() {
super.onDestroy();
- unregisterReceiver(providerAPI_broadcast_receiver_update);
}
@Override
@@ -167,11 +153,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
provider.init( this );
setContentView(R.layout.client_dashboard);
-
- providerAPI_broadcast_receiver_update = new ProviderAPIBroadcastReceiver_Update();
- IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_ACTION);
- update_intent_filter.addCategory(Intent.CATEGORY_DEFAULT);
- registerReceiver(providerAPI_broadcast_receiver_update, update_intent_filter);
providerNameTV = (TextView) findViewById(R.id.providerName);
providerNameTV.setText(provider.getDomain());
@@ -455,13 +436,4 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
eip_intent.putExtra(EIP.RECEIVER_TAG, eip_receiver);
startService(eip_intent);
}
-
- public class ProviderAPIBroadcastReceiver_Update extends BroadcastReceiver {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- int update = intent.getIntExtra(ProviderAPI.UPDATE_DATA, 0);
- //mProgressBar.setProgress(update);
- }
- }
}
diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java
index 60ed1e1f..27081df2 100644
--- a/src/se/leap/bitmaskclient/ProviderAPI.java
+++ b/src/se/leap/bitmaskclient/ProviderAPI.java
@@ -97,8 +97,8 @@ public class ProviderAPI extends IntentService {
SESSION_ID_COOKIE_KEY = "session_id_cookie_key",
SESSION_ID_KEY = "session_id",
ERRORS = "errors",
- UPDATE_ACTION = "update_action",
- UPDATE_DATA = "update data",
+ UPDATE_PROGRESSBAR = "update_action",
+ CURRENT_PROGRESS = "update data",
TAG = "provider_api_tag"
;
@@ -266,9 +266,9 @@ public class ProviderAPI extends IntentService {
*/
private void broadcast_progress(int progress) {
Intent intentUpdate = new Intent();
- intentUpdate.setAction(UPDATE_ACTION);
+ intentUpdate.setAction(UPDATE_PROGRESSBAR);
intentUpdate.addCategory(Intent.CATEGORY_DEFAULT);
- intentUpdate.putExtra(UPDATE_DATA, progress);
+ intentUpdate.putExtra(CURRENT_PROGRESS, progress);
sendBroadcast(intentUpdate);
}
@@ -421,38 +421,18 @@ public class ProviderAPI extends IntentService {
*/
private Bundle setUpProvider(Bundle task) {
Bundle result = new Bundle();
+ int progress = 0;
boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON);
String provider_main_url = task.getString(Provider.MAIN_URL);
if(downloadCACert(provider_main_url, danger_on)) {
+ broadcast_progress(progress++);
result.putBoolean(RESULT_KEY, true);
- if(getAndSetProviderJson(provider_main_url))
+ if(getAndSetProviderJson(provider_main_url)) {
+ broadcast_progress(progress++);
if(getAndSetEipServiceJson())
- ;
- }
- /*
- try {
- String provider_dot_json_string = downloadWithCommercialCA(provider_json_url, danger_on);
- if(provider_dot_json_string.isEmpty()) {
- result.putBoolean(RESULT_KEY, false);
- } else {
- JSONObject provider_json = new JSONObject(provider_dot_json_string);
- if(provider_json.has(ERRORS)) {
- String reason_to_fail = provider_json.getString(ERRORS);
- result.putString(ERRORS, reason_to_fail);
- result.putBoolean(RESULT_KEY, false);
- } else {
- ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
-
- result.putString(Provider.NAME, added_provider.name());
- result.putBoolean(RESULT_KEY, true);
- result.putString(Provider.KEY, provider_json.toString());
- result.putBoolean(ProviderItem.DANGER_ON, danger_on);
+ broadcast_progress(progress++);
}
- } catch (JSONException e) {
- result.putBoolean(RESULT_KEY, false);
- result.putString(ERRORS, "Corrupt download");
}
- */
return result;
}
diff --git a/src/se/leap/bitmaskclient/ProviderListAdapter.java b/src/se/leap/bitmaskclient/ProviderListAdapter.java
index bb1318fc..4abf15a2 100644
--- a/src/se/leap/bitmaskclient/ProviderListAdapter.java
+++ b/src/se/leap/bitmaskclient/ProviderListAdapter.java
@@ -1,6 +1,5 @@
package se.leap.bitmaskclient;
-import java.lang.reflect.Array;
import java.util.List;
import android.content.Context;
diff --git a/src/se/leap/bitmaskclient/ProviderListFragment.java b/src/se/leap/bitmaskclient/ProviderListFragment.java
index 6a0f2a05..862177a2 100644
--- a/src/se/leap/bitmaskclient/ProviderListFragment.java
+++ b/src/se/leap/bitmaskclient/ProviderListFragment.java
@@ -202,8 +202,12 @@ public class ProviderListFragment extends ListFragment {
content_adapter.notifyDataSetChanged();
}
- public void hide(int position) {
- content_adapter.hide(position);
+ public void hideAllBut(int position) {
+ for(int i = 0; i < content_adapter.getCount(); i++)
+ if(i != position)
+ content_adapter.hide(i);
+ else
+ content_adapter.unHide(i);
}
public void unhideAll() {