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/AbstractProviderDetailActivity.java18
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java13
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/MainActivity.java15
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Provider.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java26
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/StartActivity.java26
6 files changed, 92 insertions, 14 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java b/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java
index a596cc7f..bd8ae228 100644
--- a/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java
@@ -21,6 +21,7 @@ import butterknife.InjectView;
import static se.leap.bitmaskclient.Constants.PROVIDER_ALLOW_ANONYMOUS;
import static se.leap.bitmaskclient.Constants.PROVIDER_KEY;
+import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
import static se.leap.bitmaskclient.MainActivity.ACTION_SHOW_VPN_FRAGMENT;
@@ -73,12 +74,13 @@ public abstract class AbstractProviderDetailActivity extends ConfigWizardBaseAct
intent = new Intent(getApplicationContext(), SignupActivity.class);
} else {
Log.d(TAG, "use anonymously selected");
- intent = new Intent(getApplicationContext(), MainActivity.class);
- intent.setAction(ACTION_SHOW_VPN_FRAGMENT);
+ setResult(RESULT_OK);
+ finish();
+ return;
}
intent.putExtra(PROVIDER_KEY, provider);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
- startActivity(intent);
+ startActivityForResult(intent, REQUEST_CODE_CONFIGURE_LEAP);
}
});
} catch (JSONException e) {
@@ -92,6 +94,16 @@ public abstract class AbstractProviderDetailActivity extends ConfigWizardBaseAct
provider = intent.getParcelableExtra(PROVIDER_KEY);
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_CODE_CONFIGURE_LEAP) {
+ if (resultCode == RESULT_OK) {
+ setResult(resultCode, data);
+ finish();
+ }
+ }
+ }
+
private boolean anonAllowed(JSONObject providerJson) {
try {
JSONObject serviceDescription = providerJson.getJSONObject(Provider.SERVICE);
diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
index 1025a64e..0726a785 100644
--- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
@@ -49,6 +49,7 @@ import static android.view.View.GONE;
import static se.leap.bitmaskclient.Constants.APP_ACTION_QUIT;
import static se.leap.bitmaskclient.Constants.PROVIDER_ALLOW_ANONYMOUS;
import static se.leap.bitmaskclient.Constants.PROVIDER_KEY;
+import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP;
import static se.leap.bitmaskclient.ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE;
import static se.leap.bitmaskclient.ProviderAPI.ERRORS;
import static se.leap.bitmaskclient.ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE;
@@ -198,6 +199,16 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity
providerAPIResultReceiver = null;
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_CODE_CONFIGURE_LEAP) {
+ if (resultCode == RESULT_OK) {
+ setResult(resultCode, data);
+ finish();
+ }
+ }
+ }
+
private void setUpProviderAPIResultReceiver() {
providerAPIResultReceiver = new ProviderAPIResultReceiver(new Handler(), this);
providerAPIBroadcastReceiver = new ProviderAPIBroadcastReceiver();
@@ -391,7 +402,7 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity
Intent intent = new Intent(this, ProviderDetailActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.putExtra(PROVIDER_KEY, provider);
- startActivity(intent);
+ startActivityForResult(intent, REQUEST_CODE_CONFIGURE_LEAP);
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
index 40a9052c..3fc1637e 100644
--- a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
@@ -2,6 +2,7 @@ package se.leap.bitmaskclient;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
@@ -12,11 +13,15 @@ import android.support.v7.widget.Toolbar;
import se.leap.bitmaskclient.drawer.NavigationDrawerFragment;
import se.leap.bitmaskclient.userstatus.SessionDialog;
+import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP;
+import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
+
public class MainActivity extends AppCompatActivity {
private static Provider provider = new Provider();
private static FragmentManagerEnhanced fragmentManager;
+ private SharedPreferences preferences;
public final static String ACTION_SHOW_VPN_FRAGMENT = "action_show_vpn_fragment";
@@ -34,6 +39,7 @@ public class MainActivity extends AppCompatActivity {
NavigationDrawerFragment navigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
+ preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
fragmentManager = new FragmentManagerEnhanced(getSupportFragmentManager());
// Set up the drawer.
navigationDrawerFragment.setUp(
@@ -81,5 +87,14 @@ public class MainActivity extends AppCompatActivity {
}
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_CODE_CONFIGURE_LEAP) {
+ if (resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) {
+ Provider provider = data.getParcelableExtra(Provider.KEY);
+ provider.storeInPreferences(preferences);
+ }
+ }
+ }
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java
index 95daccc6..30504080 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java
@@ -16,6 +16,7 @@
*/
package se.leap.bitmaskclient;
+import android.content.SharedPreferences;
import android.os.*;
import com.google.gson.Gson;
@@ -26,6 +27,8 @@ import java.io.Serializable;
import java.net.*;
import java.util.*;
+import static se.leap.bitmaskclient.Constants.PROVIDER_CONFIGURED;
+
/**
* @author Sean Leonard <meanderingcode@aetherislands.net>
* @author Parménides GV <parmegv@sdf.org>
@@ -298,4 +301,9 @@ public final class Provider implements Parcelable {
this.caCert = cert;
}
+ public void storeInPreferences(SharedPreferences preferences) {
+ preferences.edit().putBoolean(PROVIDER_CONFIGURED, true).
+ putString(Provider.MAIN_URL, getMainUrl().toString()).
+ putString(Provider.KEY, getDefinition().toString()).apply();
+ }
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java
index 67f4e787..f51618ad 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java
@@ -15,6 +15,7 @@ import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
+import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import butterknife.InjectView;
@@ -151,6 +152,8 @@ public abstract class ProviderCredentialsBaseActivity extends ConfigWizardBaseAc
@OnClick(R.id.button)
void handleButton() {
mConfigState.setAction(PERFORMING_ACTION);
+ hideKeyboard();
+ showProgressBar();
}
protected void setButtonText(@StringRes int buttonText) {
@@ -175,8 +178,6 @@ public abstract class ProviderCredentialsBaseActivity extends ConfigWizardBaseAc
}
void login(String username, String password) {
- showProgressBar();
-
User.setUserName(username);
Intent providerAPICommand = new Intent(this, ProviderAPI.class);
@@ -187,8 +188,6 @@ public abstract class ProviderCredentialsBaseActivity extends ConfigWizardBaseAc
}
public void signUp(String username, String password) {
- showProgressBar();
-
User.setUserName(username);
Intent providerAPICommand = new Intent(this, ProviderAPI.class);
@@ -311,6 +310,13 @@ public abstract class ProviderCredentialsBaseActivity extends ConfigWizardBaseAc
});
}
+ private void hideKeyboard() {
+ InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(passwordField.getWindowToken(), 0);
+ }
+ }
+
private void handleReceivedErrors(Bundle arguments) {
if (arguments.containsKey(ERRORS.PASSWORD_INVALID_LENGTH.toString()))
passwordError.setError(getString(R.string.error_not_valid_password_user_message));
@@ -335,9 +341,17 @@ public abstract class ProviderCredentialsBaseActivity extends ConfigWizardBaseAc
if (!usernameField.getText().toString().isEmpty() && passwordField.isFocusable())
passwordField.requestFocus();
+ mConfigState.setAction(SHOWING_FORM);
hideProgressBar();
}
+ private void successfullyFinished() {
+ Intent resultData = new Intent();
+ resultData.putExtra(Provider.KEY, provider);
+ setResult(RESULT_OK, resultData);
+ finish();
+ }
+
public class ProviderAPIBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
@@ -360,9 +374,7 @@ public abstract class ProviderCredentialsBaseActivity extends ConfigWizardBaseAc
break;
case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE:
- intent = new Intent(ProviderCredentialsBaseActivity.this, MainActivity.class);
- intent.setAction(ACTION_SHOW_VPN_FRAGMENT);
- startActivity(intent);
+ successfullyFinished();
//activity.eip_fragment.updateEipService();
break;
case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE:
diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
index bb01ddc0..69079735 100644
--- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
@@ -17,6 +17,7 @@ import se.leap.bitmaskclient.userstatus.User;
import static se.leap.bitmaskclient.Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE;
import static se.leap.bitmaskclient.Constants.PREFERENCES_APP_VERSION;
+import static se.leap.bitmaskclient.Constants.PROVIDER_CONFIGURED;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
@@ -153,9 +154,7 @@ public class StartActivity extends Activity {
//buildDashboard(getIntent().getBooleanExtra(EIP_RESTART_ON_BOOT, false));
// user_status_fragment.restoreSessionStatus(savedInstanceState);
- Intent intent = new Intent(this, MainActivity.class);
- intent.setAction(MainActivity.ACTION_SHOW_VPN_FRAGMENT);
- startActivity(intent);
+ showMainActivity();
}
} else {
configureLeapProvider();
@@ -169,4 +168,25 @@ public class StartActivity extends Activity {
startActivityForResult(new Intent(this, ConfigurationWizard.class), REQUEST_CODE_CONFIGURE_LEAP);
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_CODE_CONFIGURE_LEAP) {
+ if (resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) {
+ Provider provider = data.getParcelableExtra(Provider.KEY);
+ provider.storeInPreferences(preferences);
+
+ showMainActivity();
+ } else if (resultCode == RESULT_CANCELED) {
+ finish();
+ }
+ }
+ }
+
+ private void showMainActivity() {
+ Intent intent = new Intent(this, MainActivity.class);
+ intent.setAction(MainActivity.ACTION_SHOW_VPN_FRAGMENT);
+ startActivity(intent);
+ finish();
+ }
+
}