summaryrefslogtreecommitdiff
path: root/app/src/main/java/se
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-12-09 14:08:17 +0100
committerParménides GV <parmegv@sdf.org>2014-12-09 14:08:17 +0100
commit5978db9bf758b7b229616d0575e327c58ad8cf94 (patch)
treefd8e968d07cf1e053713b41250fd7bae8ca2ec59 /app/src/main/java/se
parentafc9998ebefb19fcb2f9e3c46c6430fd69262e47 (diff)
EIP fragment shown correctly.
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java47
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Provider.java10
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/Constants.java1
3 files changed, 39 insertions, 19 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index e3bd9b7d..b84b834c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -37,6 +37,9 @@ import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
+import java.net.MalformedURLException;
+import java.net.URL;
+
import de.blinkt.openvpn.activities.LogWindow;
import se.leap.bitmaskclient.eip.Constants;
import se.leap.bitmaskclient.eip.EIP;
@@ -75,6 +78,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
private static boolean authed_eip;
@Override
+ protected void onSaveInstanceState(Bundle outState) {
+ if(provider != null)
+ outState.putParcelable(Provider.KEY, provider);
+ super.onSaveInstanceState(outState);
+ }
+
+ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -88,7 +98,19 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
handleVersion();
- if (provider == null)
+ if(savedInstanceState != null)
+ provider = savedInstanceState.getParcelable(Provider.KEY);
+ if(provider == null && preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false))
+ try {
+ provider = new Provider(new URL(preferences.getString(Provider.MAIN_URL, "")));
+ provider.define(new JSONObject(preferences.getString(Provider.KEY, "")));
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+
+ if (provider == null || provider.getName().isEmpty())
startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP);
else
buildDashboard(getIntent().getBooleanExtra(ON_BOOT, false));
@@ -116,16 +138,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
Log.d(TAG, "Handle version didn't find any " + getPackageName() + " package");
}
}
-
- @Override
- protected void onDestroy() {
-
- super.onDestroy();
- }
-
- protected void onPause() {
- super.onPause();
- }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
@@ -137,8 +149,12 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
updateEipService();
- if (data.hasExtra(Provider.KEY))
+ if (data.hasExtra(Provider.KEY)) {
provider = data.getParcelableExtra(Provider.KEY);
+ preferences.edit().putBoolean(Constants.PROVIDER_CONFIGURED, true).commit();
+ preferences.edit().putString(Provider.MAIN_URL, provider.mainUrl().toString()).apply();
+ preferences.edit().putString(Provider.KEY, provider.definition().toString()).apply();
+ }
buildDashboard(false);
invalidateOptionsMenu();
if (data.hasExtra(LogInDialog.TAG)) {
@@ -172,7 +188,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
.setNegativeButton(getResources().getString(R.string.setup_error_close_button), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- preferences.edit().remove(Provider.KEY).apply();
+ preferences.edit().remove(Provider.KEY).remove(Constants.PROVIDER_CONFIGURED).apply();
finish();
}
})
@@ -194,9 +210,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
if ( provider.hasEIP()){
- EipServiceFragment eip_fragment = (EipServiceFragment) fragment_manager.findFragmentByTag(EipServiceFragment.TAG);
- if(eip_fragment == null)
- eip_fragment = new EipServiceFragment();
+ fragment_manager.removePreviousFragment(EipServiceFragment.TAG);
+ EipServiceFragment eip_fragment = new EipServiceFragment();
if (hide_and_turn_on_eip) {
preferences.edit().remove(Dashboard.START_ON_BOOT).apply();
diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java
index dd679bb2..0b021b84 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java
@@ -100,6 +100,8 @@ public final class Provider implements Parcelable {
definition = provider_json;
}
+ protected JSONObject definition() { return definition; }
+
protected String getDomain(){
return main_url.getHost();
}
@@ -111,14 +113,16 @@ public final class Provider implements Parcelable {
protected String getName(){
// Should we pass the locale in, or query the system here?
String lang = Locale.getDefault().getLanguage();
- String name = "Null"; // Should it actually /be/ null, for error conditions?
+ String name = "";
try {
if(definition != null)
name = definition.getJSONObject(API_TERM_NAME).getString(lang);
else throw new JSONException("Provider not defined");
} catch (JSONException e) {
- String host = main_url.getHost();
- name = host.substring(0, host.indexOf("."));
+ if(main_url != null) {
+ String host = main_url.getHost();
+ name = host.substring(0, host.indexOf("."));
+ }
}
return name;
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java b/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java
index e1a7e616..01a83d5f 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java
@@ -43,5 +43,6 @@ public interface Constants {
public final static String RECEIVER_TAG = TAG + ".RECEIVER_TAG";
public final static String REQUEST_TAG = TAG + ".REQUEST_TAG";
public final static String START_BLOCKING_VPN_PROFILE = TAG + ".START_BLOCKING_VPN_PROFILE";
+ public final static String PROVIDER_CONFIGURED = TAG + ".PROVIDER_CONFIGURED";
}