diff options
Diffstat (limited to 'app/src')
23 files changed, 513 insertions, 345 deletions
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java index 13ca4431..a41a1acf 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java @@ -97,7 +97,7 @@ public class testDashboardIntegration extends ActivityInstrumentationTestCase2<D } }; solo.waitForCondition(condition, max_seconds_until_connected * 1000); - solo.sleep(2 * 1000); + sleepSeconds(2); } private void assertInProgress() { @@ -124,7 +124,7 @@ public class testDashboardIntegration extends ActivityInstrumentationTestCase2<D } }; solo.waitForCondition(condition, max_seconds_until_connected * 1000); - solo.sleep(2 * 1000); + sleepSeconds(2); } private void okToBrowserWarning() { @@ -160,15 +160,26 @@ public class testDashboardIntegration extends ActivityInstrumentationTestCase2<D } public void testLogInAndOut() { - long milliseconds_to_log_in = 40 * 1000; - solo.clickOnActionBarItem(R.id.login_button); + changeProvider("demo.bitmask.net"); + clickUserSessionButton(); + assertLoggedOut(); + clickUserSessionButton(); logIn("parmegvtest1", " S_Zw3'-"); - solo.waitForDialogToClose(milliseconds_to_log_in); - assertSuccessfulLogin(); + assertLoggedIn(); logOut(); } + private void clickUserSessionButton() { + solo.clickOnView(getUserSessionButton()); + } + + private View getUserSessionButton() { + View view = solo.getView(R.id.user_status_button); + assertTrue(view != null); + return view; + } + private void logIn(String username, String password) { solo.enterText(0, username); solo.enterText(1, password); @@ -176,11 +187,20 @@ public class testDashboardIntegration extends ActivityInstrumentationTestCase2<D solo.waitForDialogToClose(); } - private void assertSuccessfulLogin() { - assertTrue(solo.waitForText(solo.getString(R.string.logged_in_user_status))); + private void assertLoggedIn() { + String log_out = solo.getString(R.string.logout_button); + solo.waitForText(log_out); + } + + private void assertLoggedOut() { + String log_in = solo.getString(R.string.login_button); + solo.waitForText(log_in); } private void logOut() { + assertLoggedIn(); + clickUserSessionButton(); + solo.clickOnActionBarItem(R.string.logout_button); assertTrue(solo.waitForDialogToClose()); } @@ -218,20 +238,17 @@ public class testDashboardIntegration extends ActivityInstrumentationTestCase2<D private void changeAndTestProvider(String provider) { changeProvider(provider); - sleep(1); + sleepSeconds(1); clickVpnButton(); turningEipOn(); clickVpnButton(); turningEipOff(); } - private void sleep(int seconds) { - try { - Thread.sleep(seconds * 1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } + private void sleepSeconds(int seconds) { + solo.sleep(seconds * 1000); } + private void changeProvider(String provider) { tapSwitchProvider(); solo.clickOnText(provider); @@ -241,7 +258,8 @@ public class testDashboardIntegration extends ActivityInstrumentationTestCase2<D private void useRegistered() { String text = solo.getString(R.string.signup_or_login_button); clickAndWaitForDashboard(text); - login(); + logIn("parmegvtest10", "holahola2"); + assertLoggedIn(); } private void clickAndWaitForDashboard(String click_text) { @@ -249,12 +267,6 @@ public class testDashboardIntegration extends ActivityInstrumentationTestCase2<D assertTrue(solo.waitForActivity(Dashboard.class, 5000)); } - private void login() { - long milliseconds_to_log_in = 40 * 1000; - logIn("parmegvtest10", "holahola2"); - solo.waitForDialogToClose(milliseconds_to_log_in); - assertSuccessfulLogin(); - } public void testVpnIconIsDisplayed() { assertTrue(isShownWithinConfinesOfVisibleScreen(getVpnImage())); } diff --git a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java index 12a2b239..2505d37b 100644 --- a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java @@ -40,6 +40,7 @@ import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver; import se.leap.bitmaskclient.ProviderDetailFragment.ProviderDetailFragmentInterface; import se.leap.bitmaskclient.ProviderListContent.ProviderItem; import se.leap.bitmaskclient.eip.*; +import se.leap.bitmaskclient.userstatus.SessionDialog; /** * Activity that builds and shows the list of known available providers. @@ -164,8 +165,7 @@ public class ConfigurationWizard extends Activity } private void setUpProviderAPIResultReceiver() { - providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); - providerAPI_result_receiver.setReceiver(this); + providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), this); providerAPI_broadcast_receiver_update = new ProviderAPIBroadcastReceiver_Update(); IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_PROGRESSBAR); @@ -201,8 +201,6 @@ public class ConfigurationWizard extends Activity preferences.edit().remove(Provider.KEY).apply(); setting_up_provider = false; - setResult(RESULT_CANCELED, mConfigState); - String reason_to_fail = resultData.getString(ProviderAPI.ERRORS); showDownloadFailedDialog(reason_to_fail); } else if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) { @@ -214,7 +212,6 @@ public class ConfigurationWizard extends Activity hideProgressBar(); cancelSettingUpProvider(); Toast.makeText(getApplicationContext(), R.string.provider_problem, Toast.LENGTH_LONG).show(); - setResult(RESULT_CANCELED, mConfigState); } else if (resultCode == AboutActivity.VIEWED) { // Do nothing, right now // I need this for CW to wait for the About activity to end before going back to Dashboard. diff --git a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java index 5d94d180..2d7e13fe 100644 --- a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java @@ -38,6 +38,9 @@ import javax.net.ssl.*; import se.leap.bitmaskclient.ProviderListContent.*; import se.leap.bitmaskclient.eip.*; +import se.leap.bitmaskclient.userstatus.SessionDialog; +import se.leap.bitmaskclient.userstatus.User; +import se.leap.bitmaskclient.userstatus.UserStatus; /** * Implements HTTP api methods used to manage communications with the provider server. @@ -145,7 +148,7 @@ public class ProviderAPI extends IntentService { receiver.send(PROVIDER_NOK, result); } } else if (action.equalsIgnoreCase(SIGN_UP)) { - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.SIGNING_UP, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.SIGNING_UP, resources); Bundle result = tryToRegister(parameters); if (result.getBoolean(RESULT_KEY)) { receiver.send(SUCCESSFUL_SIGNUP, result); @@ -153,23 +156,24 @@ public class ProviderAPI extends IntentService { receiver.send(FAILED_SIGNUP, result); } } else if (action.equalsIgnoreCase(LOG_IN)) { - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGING_IN, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.LOGGING_IN, resources); Bundle result = tryToAuthenticate(parameters); if (result.getBoolean(RESULT_KEY)) { receiver.send(SUCCESSFUL_LOGIN, result); - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGED_IN, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.LOGGED_IN, resources); } else { receiver.send(FAILED_LOGIN, result); - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.NOT_LOGGED_IN, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.NOT_LOGGED_IN, resources); } } else if (action.equalsIgnoreCase(LOG_OUT)) { - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGING_OUT, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.LOGGING_OUT, resources); if (logOut()) { receiver.send(SUCCESSFUL_LOGOUT, Bundle.EMPTY); - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGED_OUT, resources); + android.util.Log.d(TAG, "Logged out, notifying user status"); + UserStatus.updateStatus(UserStatus.SessionStatus.LOGGED_OUT, resources); } else { receiver.send(LOGOUT_FAILED, Bundle.EMPTY); - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.DIDNT_LOG_OUT, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.DIDNT_LOG_OUT, resources); } } else if (action.equalsIgnoreCase(DOWNLOAD_CERTIFICATE)) { if (updateVpnCertificate()) { diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index afc6b131..bf35d6c3 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -29,11 +29,10 @@ import org.jetbrains.annotations.*; import org.json.*; import java.net.*; -import java.util.*; import butterknife.*; -import de.blinkt.openvpn.activities.*; import se.leap.bitmaskclient.eip.*; +import se.leap.bitmaskclient.userstatus.*; /** * The main user facing Activity of Bitmask Android, consisting of status, controls, @@ -42,7 +41,7 @@ import se.leap.bitmaskclient.eip.*; * @author Sean Leonard <meanderingcode@aetherislands.net> * @author parmegv */ -public class Dashboard extends Activity implements SessionDialog.SessionDialogInterface, ProviderAPIResultReceiver.Receiver, Observer { +public class Dashboard extends Activity implements ProviderAPIResultReceiver.Receiver { protected static final int CONFIGURE_LEAP = 0; protected static final int SWITCH_PROVIDER = 1; @@ -62,14 +61,10 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn @InjectView(R.id.providerName) TextView provider_name; - @InjectView(R.id.user_session_status) - TextView user_session_status_text_view; - @InjectView(R.id.user_session_status_progress) - ProgressBar user_session_status_progress_bar; EipFragment eip_fragment; - private Provider provider = new Provider(); - private UserSessionStatus user_session_status; + UserStatusFragment user_status_fragment; + private static Provider provider = new Provider(); public ProviderAPIResultReceiver providerAPI_result_receiver; private boolean switching_provider; @@ -78,22 +73,23 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn super.onCreate(savedInstanceState); app = this; - user_session_status = UserSessionStatus.getInstance(getResources()); - user_session_status.addObserver(this); PRNGFixes.apply(); preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); fragment_manager = new FragmentManagerEnhanced(getFragmentManager()); handleVersion(); - User.init(); + User.init(getString(R.string.default_username)); + + ProviderAPICommand.initialize(this); + providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), this); restoreProvider(savedInstanceState); if (!provider.isConfigured()) startActivityForResult(new Intent(this, ConfigurationWizard.class), CONFIGURE_LEAP); else { buildDashboard(getIntent().getBooleanExtra(ON_BOOT, false)); - restoreSessionStatus(savedInstanceState); + user_status_fragment.restoreSessionStatus(savedInstanceState); } } @@ -106,20 +102,9 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn provider = getSavedProviderFromSharedPreferences(); } - private void restoreSessionStatus(Bundle savedInstanceState) { - if (savedInstanceState != null) - if (savedInstanceState.containsKey(UserSessionStatus.TAG)) { - UserSessionStatus.SessionStatus status = (UserSessionStatus.SessionStatus) savedInstanceState.getSerializable(UserSessionStatus.TAG); - user_session_status.updateStatus(status, getResources()); - } - } - @Override protected void onSaveInstanceState(@NotNull Bundle outState) { outState.putParcelable(Provider.KEY, provider); - if (user_session_status_text_view != null && user_session_status_text_view.getVisibility() == TextView.VISIBLE) - outState.putSerializable(UserSessionStatus.TAG, user_session_status.sessionStatus()); - super.onSaveInstanceState(outState); } @@ -166,7 +151,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn sessionDialog(Bundle.EMPTY); } - } else if (resultCode == RESULT_CANCELED && data.hasExtra(ACTION_QUIT)) { + } else if (resultCode == RESULT_CANCELED && data != null && data.hasExtra(ACTION_QUIT)) { finish(); } else configErrorDialog(); @@ -213,6 +198,13 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn ButterKnife.inject(this); provider_name.setText(provider.getDomain()); + + user_status_fragment = new UserStatusFragment(); + Bundle bundle = new Bundle(); + bundle.putBoolean(Provider.ALLOW_REGISTRATION, provider.allowsRegistration()); + user_status_fragment.setArguments(bundle); + fragment_manager.replace(R.id.user_status_fragment, user_status_fragment, UserStatusFragment.TAG); + if (provider.hasEIP()) { fragment_manager.removePreviousFragment(EipFragment.TAG); eip_fragment = new EipFragment(); @@ -229,17 +221,12 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn onBackPressed(); } } - handleNewUserSessionStatus(user_session_status); } @Override public boolean onPrepareOptionsMenu(Menu menu) { if (provider.allowsRegistration()) { menu.findItem(R.id.signup_button).setVisible(true); - - boolean logged_in = User.loggedIn(); - menu.findItem(R.id.login_button).setVisible(!logged_in); - menu.findItem(R.id.logout_button).setVisible(logged_in); } return true; } @@ -261,15 +248,9 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn return true; case R.id.switch_provider: switching_provider = true; - if (LeapSRPSession.loggedIn()) logOut(); + if (User.loggedIn()) user_status_fragment.logOut(); else switchProvider(); return true; - case R.id.login_button: - sessionDialog(Bundle.EMPTY); - return true; - case R.id.logout_button: - logOut(); - return true; case R.id.signup_button: sessionDialog(Bundle.EMPTY); return true; @@ -288,122 +269,18 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn log_window_wrapper.showLog(); } - @Override - public void signUp(String username, String password) { - User.setUserName(username); - Bundle parameters = bundlePassword(password); - providerApiCommand(parameters, 0, ProviderAPI.SIGN_UP); - } - - @Override - public void logIn(String username, String password) { - User.setUserName(username); - Bundle parameters = bundlePassword(password); - providerApiCommand(parameters, 0, ProviderAPI.LOG_IN); - } - - public void logOut() { - providerApiCommand(Bundle.EMPTY, 0, ProviderAPI.LOG_OUT); - } - - @Override - public void update(Observable observable, Object data) { - if (observable instanceof UserSessionStatus) { - UserSessionStatus status = (UserSessionStatus) observable; - handleNewUserSessionStatus(status); - } - } - - private void handleNewUserSessionStatus(UserSessionStatus status) { - user_session_status = status; - if (provider.allowsRegistration()) { - if (user_session_status.inProgress()) - showUserSessionProgressBar(); - else - hideUserSessionProgressBar(); - changeSessionStatusMessage(user_session_status.toString()); - invalidateOptionsMenuOnUiThread(); - } - } - - private void changeSessionStatusMessage(final String message) { - runOnUiThread(new Runnable() { - @Override - public void run() { - user_session_status_text_view.setText(message); - } - }); - } - - private void showUserSessionProgressBar() { - runOnUiThread(new Runnable() { - @Override - public void run() { - user_session_status_progress_bar.setVisibility(ProgressBar.VISIBLE); - } - }); - } - - private void hideUserSessionProgressBar() { - runOnUiThread(new Runnable() { - @Override - public void run() { - user_session_status_progress_bar.setVisibility(ProgressBar.GONE); - } - }); - } - - protected void downloadVpnCertificate() { - boolean is_authenticated = LeapSRPSession.loggedIn(); + public void downloadVpnCertificate() { + boolean is_authenticated = User.loggedIn(); boolean allowed_anon = preferences.getBoolean(Constants.ALLOWED_ANON, false); if (allowed_anon || is_authenticated) - providerApiCommand(Bundle.EMPTY, R.string.downloading_certificate_message, ProviderAPI.DOWNLOAD_CERTIFICATE); + ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.DOWNLOAD_CERTIFICATE, providerAPI_result_receiver); else sessionDialog(Bundle.EMPTY); - - } - - private Bundle bundlePassword(String password) { - Bundle parameters = new Bundle(); - if (!password.isEmpty()) - parameters.putString(SessionDialog.PASSWORD, password); - return parameters; - } - - protected void providerApiCommand(Bundle parameters, int progressbar_message_resId, String providerApi_action) { - Intent command = prepareProviderAPICommand(parameters, providerApi_action); - startService(command); - } - - private Intent prepareProviderAPICommand(Bundle parameters, String action) { - providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); - providerAPI_result_receiver.setReceiver(this); - - Intent command = new Intent(this, ProviderAPI.class); - - command.putExtra(ProviderAPI.PARAMETERS, parameters); - command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver); - command.setAction(action); - return command; - } - - public void cancelLoginOrSignup() { - EipStatus.getInstance().setConnectedOrDisconnected(); } public void sessionDialog(Bundle resultData) { - FragmentTransaction transaction = fragment_manager.removePreviousFragment(SessionDialog.TAG); - - DialogFragment newFragment = new SessionDialog(); - if (provider.getName().equalsIgnoreCase("riseup")) { - resultData = resultData == Bundle.EMPTY ? new Bundle() : resultData; - resultData.putBoolean(SessionDialog.ERRORS.RISEUP_WARNING.toString(), true); - } - if (resultData != null && !resultData.isEmpty()) { - newFragment.setArguments(resultData); - } - newFragment.show(transaction, SessionDialog.TAG); + SessionDialog.getInstance(provider, resultData).show(transaction, SessionDialog.TAG); } private void switchProvider() { @@ -419,7 +296,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn if (resultCode == ProviderAPI.SUCCESSFUL_SIGNUP) { String username = resultData.getString(SessionDialog.USERNAME); String password = resultData.getString(SessionDialog.PASSWORD); - logIn(username, password); + user_status_fragment.logIn(username, password); } else if (resultCode == ProviderAPI.FAILED_SIGNUP) { sessionDialog(resultData); } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { @@ -447,6 +324,8 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn return app; } + public static Provider getProvider() { return provider; } + @Override public void startActivityForResult(Intent intent, int requestCode) { intent.putExtra(Dashboard.REQUEST_CODE, requestCode); diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 30147f65..5a7b2ced 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -35,7 +35,7 @@ public class EipFragment extends Fragment implements Observer { public static String TAG = EipFragment.class.getSimpleName(); - protected static final String IS_PENDING = TAG + ".is_pending"; + public static final String IS_PENDING = TAG + ".is_pending"; protected static final String IS_CONNECTED = TAG + ".is_connected"; public static final String START_ON_BOOT = "start on boot"; @@ -45,7 +45,7 @@ public class EipFragment extends Fragment implements Observer { Button main_button; private static Dashboard dashboard; - private static EIPReceiver mEIPReceiver; + private static EIPReceiver eip_receiver; private static EipStatus eip_status; private boolean wants_to_connect; @@ -53,7 +53,10 @@ public class EipFragment extends Fragment implements Observer { super.onAttach(activity); dashboard = (Dashboard) activity; - dashboard.providerApiCommand(Bundle.EMPTY, 0, ProviderAPI.DOWNLOAD_EIP_SERVICE); + ProviderAPIResultReceiver provider_api_receiver = new ProviderAPIResultReceiver(new Handler(), dashboard); + + if(eip_receiver != null) + ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.DOWNLOAD_EIP_SERVICE, provider_api_receiver); } @Override @@ -61,7 +64,7 @@ public class EipFragment extends Fragment implements Observer { super.onCreate(savedInstanceState); eip_status = EipStatus.getInstance(); eip_status.addObserver(this); - mEIPReceiver = new EIPReceiver(new Handler()); + eip_receiver = new EIPReceiver(new Handler()); } @Override @@ -219,7 +222,7 @@ public class EipFragment extends Fragment implements Observer { // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class); vpn_intent.setAction(action); - vpn_intent.putExtra(Constants.RECEIVER_TAG, mEIPReceiver); + vpn_intent.putExtra(Constants.RECEIVER_TAG, eip_receiver); dashboard.startService(vpn_intent); } @@ -335,6 +338,6 @@ public class EipFragment extends Fragment implements Observer { public static EIPReceiver getReceiver() { - return mEIPReceiver; + return eip_receiver; } } diff --git a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java index 1ced6d60..49cf3774 100644 --- a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java +++ b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java @@ -337,7 +337,7 @@ public class LeapSRPSession { return token; } - protected static boolean loggedIn() { + public static boolean loggedIn() { return !token.isEmpty(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index a66d53e7..559b47d1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -118,7 +118,7 @@ public final class Provider implements Parcelable { protected String certificatePin() { return certificate_pin; } - protected String getName() { + public String getName() { // Should we pass the locale in, or query the system here? String lang = Locale.getDefault().getLanguage(); String name = ""; diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java b/app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java new file mode 100644 index 00000000..0e4cfe8a --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java @@ -0,0 +1,45 @@ +package se.leap.bitmaskclient; + +import android.content.*; +import android.os.*; + +import org.jetbrains.annotations.*; + +public class ProviderAPICommand { + private static Context context; + + private static String action; + private static Bundle parameters; + private static ResultReceiver result_receiver; + + public static void initialize(Context context) { + ProviderAPICommand.context = context; + } + + private static boolean isInitialized() { + return context != null; + } + + public static void execute(Bundle parameters, @NotNull String action, @NotNull ResultReceiver result_receiver) throws IllegalStateException { + if(!isInitialized()) throw new IllegalStateException(); + + ProviderAPICommand.action = action; + ProviderAPICommand.parameters = parameters; + ProviderAPICommand.result_receiver = result_receiver; + + Intent intent = setUpIntent(); + context.startService(intent); + } + + private static Intent setUpIntent() { + Intent command = new Intent(context, ProviderAPI.class); + + command.setAction(action); + command.putExtra(ProviderAPI.PARAMETERS, parameters); + command.putExtra(ProviderAPI.RECEIVER_KEY, result_receiver); + + return command; + } + + +} diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java b/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java index 533e5caf..9b880f89 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java @@ -26,8 +26,9 @@ import android.os.*; public class ProviderAPIResultReceiver extends ResultReceiver {
private Receiver mReceiver;
- public ProviderAPIResultReceiver(Handler handler) {
+ public ProviderAPIResultReceiver(Handler handler, Receiver receiver) {
super(handler);
+ setReceiver(receiver);
// TODO Auto-generated constructor stub
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java index 30344ff2..f89418ba 100644 --- a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package se.leap.bitmaskclient; +package se.leap.bitmaskclient.userstatus; import android.app.*; import android.content.*; @@ -23,6 +23,9 @@ import android.view.*; import android.widget.*; import butterknife.*; +import se.leap.bitmaskclient.EipFragment; +import se.leap.bitmaskclient.Provider; +import se.leap.bitmaskclient.R; /** * Implements the log in dialog, currently without progress dialog. @@ -56,8 +59,18 @@ public class SessionDialog extends DialogFragment { private static boolean is_eip_pending = false; - public SessionDialog() { - setArguments(Bundle.EMPTY); + public static SessionDialog getInstance(Provider provider, Bundle arguments) { + SessionDialog dialog = new SessionDialog(); + if (provider.getName().equalsIgnoreCase("riseup")) { + arguments = + arguments == Bundle.EMPTY ? + new Bundle() : arguments; + arguments.putBoolean(SessionDialog.ERRORS.RISEUP_WARNING.toString(), true); + } + if (arguments != null && !arguments.isEmpty()) { + dialog.setArguments(arguments); + } + return dialog; } public AlertDialog onCreateDialog(Bundle savedInstanceState) { @@ -68,7 +81,7 @@ public class SessionDialog extends DialogFragment { ButterKnife.inject(this, view); Bundle arguments = getArguments(); - if (arguments != Bundle.EMPTY) { + if (arguments != Bundle.EMPTY && arguments != null) { setUp(arguments); } @@ -152,8 +165,9 @@ public class SessionDialog extends DialogFragment { @Override public void onAttach(Activity activity) { super.onAttach(activity); + try { - interface_with_Dashboard = (SessionDialogInterface) activity; + interface_with_Dashboard = (SessionDialogInterface) activity.getFragmentManager().findFragmentById(R.id.user_status_fragment);; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement LogInDialogListener"); diff --git a/app/src/main/java/se/leap/bitmaskclient/User.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/User.java index f3d3b8b1..64ce0629 100644 --- a/app/src/main/java/se/leap/bitmaskclient/User.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/User.java @@ -14,16 +14,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package se.leap.bitmaskclient; +package se.leap.bitmaskclient.userstatus; + +import se.leap.bitmaskclient.LeapSRPSession; public class User { - private static String user_name = ""; + private static String user_name; private static User user; - public static int DEFAULT_CONJUGATION_PERSON = 1; - public static User init() { + public static User init(String default_username) { if (user == null) { user = new User(); + user.setUserName(default_username); } return user; } diff --git a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java index 28c7ecc7..edfed8d6 100644 --- a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java @@ -14,15 +14,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package se.leap.bitmaskclient; +package se.leap.bitmaskclient.userstatus; import android.content.res.*; import java.util.*; -public class UserSessionStatus extends Observable { - public static String TAG = UserSessionStatus.class.getSimpleName(); - private static UserSessionStatus current_status; +import se.leap.bitmaskclient.R; + +public class UserStatus extends Observable { + public static String TAG = UserStatus.class.getSimpleName(); + private static UserStatus current_status; private static Resources resources; public enum SessionStatus { @@ -56,17 +58,17 @@ public class UserSessionStatus extends Observable { } } - private static SessionStatus session_status = SessionStatus.NOT_LOGGED_IN; + private static SessionStatus session_status = SessionStatus.LOGGED_OUT; - public static UserSessionStatus getInstance(Resources resources) { + public static UserStatus getInstance(Resources resources) { if (current_status == null) { - current_status = new UserSessionStatus(resources); + current_status = new UserStatus(resources); } return current_status; } - private UserSessionStatus(Resources resources) { - UserSessionStatus.resources = resources; + private UserStatus(Resources resources) { + UserStatus.resources = resources; } private void sessionStatus(SessionStatus session_status) { @@ -82,6 +84,14 @@ public class UserSessionStatus extends Observable { || session_status == SessionStatus.LOGGING_OUT; } + public boolean isLoggedIn() { + return session_status == SessionStatus.LOGGED_IN; + } + + public boolean isLoggedOut() { + return session_status == SessionStatus.LOGGED_OUT; + } + public static void updateStatus(SessionStatus session_status, Resources resources) { current_status = getInstance(resources); current_status.sessionStatus(session_status); @@ -93,7 +103,7 @@ public class UserSessionStatus extends Observable { public String toString() { String user_session_status = User.userName(); - String default_username = resources.getString(R.string.default_user, ""); + String default_username = resources.getString(R.string.default_username, ""); if(user_session_status.isEmpty() && !default_username.equalsIgnoreCase("null")) user_session_status = default_username; user_session_status += " " + session_status.toString(); diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java new file mode 100644 index 00000000..f0f4a8fa --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java @@ -0,0 +1,169 @@ +package se.leap.bitmaskclient.userstatus; + +import android.app.*; +import android.os.*; +import android.view.*; +import android.widget.*; + +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +import butterknife.*; +import mbanje.kurt.fabbutton.FabButton; +import se.leap.bitmaskclient.*; +import se.leap.bitmaskclient.eip.EipStatus; + +public class UserStatusFragment extends Fragment implements Observer, SessionDialog.SessionDialogInterface { + + public static String TAG = UserStatusFragment.class.getSimpleName(); + private static Dashboard dashboard; + private ProviderAPIResultReceiver providerAPI_result_receiver; + + @InjectView(R.id.user_status_username) + TextView username; + @InjectView(R.id.user_status_icon) + FabButton icon; + @InjectView(R.id.user_status_button) + Button button; + + private UserStatus status; + private boolean allows_registration = false; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + status = UserStatus.getInstance(getResources()); + status.addObserver(this); + } + + @Override + public void onSaveInstanceState(@NotNull Bundle outState) { + if (username != null && username.getVisibility() == TextView.VISIBLE) + outState.putSerializable(UserStatus.TAG, status.sessionStatus()); + + super.onSaveInstanceState(outState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + View view = inflater.inflate(R.layout.fragment_user_session, container, false); + ButterKnife.inject(this, view); + + Bundle arguments = getArguments(); + allows_registration = arguments.getBoolean(Provider.ALLOW_REGISTRATION); + handleNewStatus(status); + + return view; + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + dashboard = (Dashboard) activity; + + providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), dashboard); + } + + public void restoreSessionStatus(Bundle savedInstanceState) { + if (savedInstanceState != null) + if (savedInstanceState.containsKey(UserStatus.TAG)) { + UserStatus.SessionStatus status = (UserStatus.SessionStatus) savedInstanceState.getSerializable(UserStatus.TAG); + this.status.updateStatus(status, getResources()); + } + } + + @OnClick(R.id.user_status_button) + public void handleButton() { + android.util.Log.d(TAG, status.toString()); + if(status.isLoggedIn()) + logOut(); + else if(status.isLoggedOut()) + dashboard.sessionDialog(Bundle.EMPTY); + else if(status.inProgress()) + cancelLoginOrSignup(); + } + + @Override + public void update(Observable observable, Object data) { + if (observable instanceof UserStatus) { + final UserStatus status = (UserStatus) observable; + dashboard.runOnUiThread(new Runnable() { + @Override + public void run() { + handleNewStatus(status); + } + }); + } + } + + private void handleNewStatus(UserStatus status) { + this.status = status; + if (allows_registration) { + if (this.status.inProgress()) + showUserSessionProgressBar(); + else + hideUserSessionProgressBar(); + changeMessage(); + updateButton(); + } + } + + private void showUserSessionProgressBar() { + icon.showProgress(true); + } + + private void hideUserSessionProgressBar() { + icon.showProgress(false); + } + + private void changeMessage() { + final String message = User.userName(); + username.setText(message); + } + + private void updateButton() { + if(status.isLoggedIn()) + button.setText(dashboard.getString(R.string.logout_button)); + else if(allows_registration) { + if (status.isLoggedOut()) + button.setText(dashboard.getString(R.string.login_button)); + else if (status.inProgress()) + button.setText(dashboard.getString(android.R.string.cancel)); + } + } + + + @Override + public void signUp(String username, String password) { + User.setUserName(username); + Bundle parameters = bundlePassword(password); + ProviderAPICommand.execute(parameters, ProviderAPI.SIGN_UP, providerAPI_result_receiver); + } + + @Override + public void logIn(String username, String password) { + User.setUserName(username); + Bundle parameters = bundlePassword(password); + ProviderAPICommand.execute(parameters, ProviderAPI.LOG_IN, providerAPI_result_receiver); + } + + public void logOut() { + android.util.Log.d(TAG, "Log out"); + ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.LOG_OUT, providerAPI_result_receiver); + } + + public void cancelLoginOrSignup() { + EipStatus.getInstance().setConnectedOrDisconnected(); + } + + private Bundle bundlePassword(String password) { + Bundle parameters = new Bundle(); + if (!password.isEmpty()) + parameters.putString(SessionDialog.PASSWORD, password); + return parameters; + } +} diff --git a/app/src/main/res/layout-xlarge/dashboard.xml b/app/src/main/res/layout-xlarge/dashboard.xml index 268bd3f9..3c93a04c 100644 --- a/app/src/main/res/layout-xlarge/dashboard.xml +++ b/app/src/main/res/layout-xlarge/dashboard.xml @@ -5,80 +5,45 @@ android:layout_height="match_parent" android:orientation="vertical" android:layout_marginLeft="10sp" + android:layout_marginStart="10sp" android:layout_marginTop="10sp" tools:context=".Dashboard" > - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="42dp" - android:background="?android:attr/selectableItemBackground" > - - <LinearLayout - android:layout_width="wrap_content" - android:layout_height="match_parent" - android:gravity="center_vertical" - android:orientation="vertical" - android:paddingLeft="10dp" > - - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:ellipsize="marquee" - android:fadingEdge="horizontal" - android:singleLine="true" - android:text="@string/provider_label" - android:textAppearance="?android:attr/textAppearanceMedium" - android:textSize="32sp" /> - - </LinearLayout> - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="match_parent" - android:gravity="center_vertical" - android:orientation="vertical" - android:paddingLeft="32dp" > - <TextView - android:id="@+id/providerName" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:ellipsize="marquee" - android:fadingEdge="horizontal" - android:singleLine="true" - android:text="@string/provider_label_none" - android:textAppearance="?android:attr/textAppearanceMedium" /> - - </LinearLayout> - </LinearLayout> + <TextView + android:id="@+id/providerName" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginLeft="32dp" + android:layout_marginStart="32dp" + android:textSize="48sp" + android:ellipsize="marquee" + android:gravity="center_vertical" + android:text="@string/provider_label_none" + android:textAppearance="?android:attr/textAppearanceMedium" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingLeft="32dp"> - <ProgressBar - android:id="@+id/user_session_status_progress" - android:layout_width="wrap_content" - android:layout_height="fill_parent" - android:indeterminate="true" - android:visibility="gone"/> - <TextView - android:id="@+id/user_session_status" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:textSize="18sp" - android:layout_marginLeft="10dp" - android:ellipsize="marquee" - android:singleLine="true" - android:textAppearance="?android:attr/textAppearanceMedium" - /> + android:layout_marginLeft="32dp" + android:layout_marginStart="32dp"> + <ProgressBar + android:id="@+id/user_session_status_progress" + android:layout_width="wrap_content" + android:layout_height="fill_parent" + android:indeterminate="true" + android:visibility="gone"/> + <TextView + android:id="@+id/user_session_status" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textSize="18sp" + android:layout_marginLeft="10dp" + android:layout_marginStart="10dp" + android:ellipsize="marquee" + android:singleLine="true" + android:textAppearance="?android:attr/textAppearanceMedium" + /> </LinearLayout> - - <View - android:layout_width="wrap_content" - android:layout_height="1dp" - android:layout_marginBottom="7dp" - android:background="@android:drawable/divider_horizontal_bright" /> <LinearLayout android:id="@+id/servicesCollection" diff --git a/app/src/main/res/layout-xlarge/fragment_user_session.xml b/app/src/main/res/layout-xlarge/fragment_user_session.xml new file mode 100644 index 00000000..30969219 --- /dev/null +++ b/app/src/main/res/layout-xlarge/fragment_user_session.xml @@ -0,0 +1,55 @@ +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="30dp" + android:layout_marginLeft="60dp" + android:layout_marginStart="60dp" + android:orientation="vertical" + tools:context="se.leap.bitmaskclient.userstatus.UserStatusFragment"> + + <TextView + android:id="@+id/user.status.username" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="30dp" + android:layout_marginRight="60dp" + android:layout_marginEnd="60dp" + android:layout_gravity="center" + android:textSize="46sp" + android:text="@string/default_username" + android:textAppearance="?android:attr/textAppearanceMedium"/> + + <LinearLayout + android:id="@+id/user.status.buttonAndIcon" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center"> + + <Button + android:id="@+id/user.status.button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textSize="24sp" + /> + + <view + android:id="@+id/user.status.icon" + android:layout_width="56dp" + android:layout_height="56dp" + android:layout_marginLeft="26dp" + android:layout_marginStart="26dp" + android:background="@android:color/transparent" + android:color="@android:color/holo_blue_dark" + class="mbanje.kurt.fabbutton.FabButton" + android:layout_gravity="center" + android:visibility="visible" + android:indeterminate="true" + android:max="100" + fbb_autoStart="true" + fbb_progressColor="#ff170aff" + fbb_progressWidthRatio="0.3" + /> + + </LinearLayout> +</LinearLayout> diff --git a/app/src/main/res/layout/dashboard.xml b/app/src/main/res/layout/dashboard.xml index f4269fe2..6a9bbe97 100644 --- a/app/src/main/res/layout/dashboard.xml +++ b/app/src/main/res/layout/dashboard.xml @@ -5,61 +5,30 @@ android:layout_height="match_parent" android:orientation="vertical" tools:context=".Dashboard" > - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="40dp" - android:background="?android:attr/selectableItemBackground" > - - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginLeft="5dp" - android:ellipsize="marquee" - android:singleLine="true" - android:text="@string/provider_label" - android:textAppearance="?android:attr/textAppearanceMedium" /> - - <TextView - android:id="@+id/providerName" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:textSize="28sp" - android:layout_marginLeft="10dp" - android:ellipsize="marquee" - android:singleLine="true" - android:text="@string/provider_label_none" - android:textAppearance="?android:attr/textAppearanceMedium" /> - </LinearLayout> + <TextView + android:id="@+id/providerName" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginLeft="10dp" + android:layout_marginStart="10dp" + android:textSize="26sp" + android:ellipsize="marquee" + android:gravity="center_vertical" + android:singleLine="true" + android:text="@string/provider_label_none" + android:textAppearance="?android:attr/textAppearanceMedium" /> <LinearLayout + android:id="@+id/user.status.fragment" android:layout_width="match_parent" - android:layout_height="wrap_content"> - <ProgressBar - android:id="@+id/user_session_status_progress" - android:layout_width="wrap_content" - android:layout_height="fill_parent" - android:indeterminate="true" - android:visibility="gone"/> - <TextView - android:id="@+id/user_session_status" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:textSize="18sp" - android:layout_marginLeft="10dp" - android:ellipsize="marquee" - android:singleLine="true" - android:textAppearance="?android:attr/textAppearanceMedium" - /> - </LinearLayout> - + android:layout_height="wrap_content" + android:orientation="horizontal"/> + <LinearLayout android:id="@+id/servicesCollection" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.11" - android:orientation="vertical" > - </LinearLayout> - + android:orientation="vertical" /> </LinearLayout> diff --git a/app/src/main/res/layout/eip_service_fragment.xml b/app/src/main/res/layout/eip_service_fragment.xml index 1360b8e0..06b514d3 100644 --- a/app/src/main/res/layout/eip_service_fragment.xml +++ b/app/src/main/res/layout/eip_service_fragment.xml @@ -40,7 +40,6 @@ class="mbanje.kurt.fabbutton.FabButton" android:layout_gravity="center" android:visibility="visible" - android:layout_centerInParent="true" android:indeterminate="true" android:max="100" fbb_autoStart="true" diff --git a/app/src/main/res/layout/fragment_user_session.xml b/app/src/main/res/layout/fragment_user_session.xml new file mode 100644 index 00000000..5194e495 --- /dev/null +++ b/app/src/main/res/layout/fragment_user_session.xml @@ -0,0 +1,52 @@ +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:layout_marginLeft="20dp" + android:layout_marginStart="20dp" + tools:context="se.leap.bitmaskclient.userstatus.UserStatusFragment"> + + <TextView + android:id="@+id/user.status.username" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="10dp" + android:layout_marginRight="20dp" + android:layout_marginEnd="20dp" + android:textSize="20sp" + android:text="@string/default_username" + android:textAppearance="?android:attr/textAppearanceMedium"/> + + <LinearLayout + android:id="@+id/user.status.buttonAndIcon" + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + + <Button + android:id="@+id/user.status.button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textSize="14sp" + /> + + <view + android:id="@+id/user.status.icon" + android:layout_width="32dp" + android:layout_height="32dp" + android:layout_marginLeft="9dp" + android:layout_marginStart="9dp" + android:background="@android:color/transparent" + android:color="@android:color/holo_blue_dark" + class="mbanje.kurt.fabbutton.FabButton" + android:layout_gravity="center" + android:visibility="visible" + android:indeterminate="true" + android:max="100" + fbb_autoStart="true" + fbb_progressColor="#ff170aff" + fbb_progressWidthRatio="0.1" + /> + + </LinearLayout> +</LinearLayout> diff --git a/app/src/main/res/menu/client_dashboard.xml b/app/src/main/res/menu/client_dashboard.xml index 9bc39d7b..e0336cc0 100644 --- a/app/src/main/res/menu/client_dashboard.xml +++ b/app/src/main/res/menu/client_dashboard.xml @@ -15,15 +15,5 @@ android:id="@+id/signup_button" android:title="@string/signup_button" android:visible="false"/> - <item - android:id="@+id/login_button" - android:showAsAction="ifRoom" - android:title="@string/login_button" - android:visible="false"/> - <item - android:id="@+id/logout_button" - android:showAsAction="ifRoom" - android:title="@string/logout_button" - android:visible="false"/> </menu> diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index acf002bc..7f0670b8 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -69,7 +69,7 @@ <string name="eip_state_connected">Conexión protegida.</string> <string name="provider_problem">Parece que hay un problema con el proveedor.</string> <string name="try_another_provider">Prueba con otro proveedor, o contacta con este.</string> - <string name="default_user"></string> + <string name="default_username">Anónimo</string> <string name="logged_in_user_status">inició sesión.</string> <string name="logged_out_user_status">cerró la sesión.</string> <string name="didnt_log_out_user_status">no cerró la sesión.</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6856b713..7746795e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -67,7 +67,7 @@ <string name="eip_state_connected">Connection Secure.</string> <string name="provider_problem">It seems there is a problem with the provider.</string> <string name="try_another_provider">Please try another provider, or contact yours.</string> - <string name="default_user">You</string> + <string name="default_username">Anonymous</string> <string name="logged_in_user_status">is logged in.</string> <string name="logged_out_user_status">logged out.</string> <string name="didnt_log_out_user_status">didn\'t log out. Try later, it may be a problem in the network or in the provider. If the problem persists, then wipe Bitmask data from the Android settings</string> diff --git a/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java index eed9413b..61c6b7cf 100644 --- a/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java @@ -39,6 +39,7 @@ import se.leap.bitmaskclient.NewProviderDialog.NewProviderDialogInterface; import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver; import se.leap.bitmaskclient.ProviderDetailFragment.ProviderDetailFragmentInterface; import se.leap.bitmaskclient.eip.Constants; +import se.leap.bitmaskclient.userstatus.SessionDialog; /** * Activity that builds and shows the list of known available providers. @@ -164,8 +165,7 @@ public class ConfigurationWizard extends Activity } private void setUpProviderAPIResultReceiver() { - providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); - providerAPI_result_receiver.setReceiver(this); + providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), this); providerAPI_broadcast_receiver_update = new ProviderAPIBroadcastReceiver_Update(); IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_PROGRESSBAR); diff --git a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java index a96556bc..a3f7db6a 100644 --- a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java @@ -36,8 +36,10 @@ import org.apache.http.client.*; import org.json.*; import org.thoughtcrime.ssl.pinning.util.*; -import se.leap.bitmaskclient.ProviderListContent.ProviderItem; import se.leap.bitmaskclient.eip.*; +import se.leap.bitmaskclient.userstatus.SessionDialog; +import se.leap.bitmaskclient.userstatus.User; +import se.leap.bitmaskclient.userstatus.UserStatus; /** * Implements HTTP api methods used to manage communications with the provider server. @@ -141,7 +143,7 @@ public class ProviderAPI extends IntentService { } } } else if (action.equalsIgnoreCase(SIGN_UP)) { - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.SIGNING_UP, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.SIGNING_UP, resources); Bundle result = tryToRegister(parameters); if (result.getBoolean(RESULT_KEY)) { receiver.send(SUCCESSFUL_SIGNUP, result); @@ -149,23 +151,23 @@ public class ProviderAPI extends IntentService { receiver.send(FAILED_SIGNUP, result); } } else if (action.equalsIgnoreCase(LOG_IN)) { - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGING_IN, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.LOGGING_IN, resources); Bundle result = tryToAuthenticate(parameters); if (result.getBoolean(RESULT_KEY)) { receiver.send(SUCCESSFUL_LOGIN, result); - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGED_IN, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.LOGGED_IN, resources); } else { receiver.send(FAILED_LOGIN, result); - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.NOT_LOGGED_IN, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.NOT_LOGGED_IN, resources); } } else if (action.equalsIgnoreCase(LOG_OUT)) { - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGING_OUT, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.LOGGING_OUT, resources); if (logOut()) { receiver.send(SUCCESSFUL_LOGOUT, Bundle.EMPTY); - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGED_OUT, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.LOGGED_OUT, resources); } else { receiver.send(LOGOUT_FAILED, Bundle.EMPTY); - UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.DIDNT_LOG_OUT, resources); + UserStatus.updateStatus(UserStatus.SessionStatus.DIDNT_LOG_OUT, resources); } } else if (action.equalsIgnoreCase(DOWNLOAD_CERTIFICATE)) { if (updateVpnCertificate()) { |