From 7d046fda66e8933b509b854077b7acfb3b3b7c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Mon, 26 Jan 2015 14:18:56 +0100 Subject: Don't reuse last session dialog. It was giving problems when trying to change the arguments. --- .../se/leap/bitmaskclient/ConfigurationWizard.java | 4 ++ .../java/se/leap/bitmaskclient/ProviderAPI.java | 22 +++--- .../leap/bitmaskclient/ProviderDetailFragment.java | 34 +++++----- .../main/java/se/leap/bitmaskclient/Dashboard.java | 11 +-- .../java/se/leap/bitmaskclient/SessionDialog.java | 78 ++++++++++++---------- .../java/se/leap/bitmaskclient/ProviderAPI.java | 22 +++--- 6 files changed, 92 insertions(+), 79 deletions(-) (limited to 'app') diff --git a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java index faf3779a..27984147 100644 --- a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java @@ -428,6 +428,10 @@ implements NewProviderDialogInterface, ProviderDetailFragmentInterface, Download return super.onOptionsItemSelected(item); } } + + public void showAllProviders() { + adapter.showAllProviders(); + } @Override public void login() { diff --git a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java index 1dbe11d3..0650f0ad 100644 --- a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java @@ -179,28 +179,28 @@ public class ProviderAPI extends IntentService { } private Bundle tryToRegister(Bundle task) { - Bundle session_id_bundle = new Bundle(); + Bundle result = new Bundle(); int progress = 0; - String username = (String) task.get(SessionDialog.USERNAME); - String password = (String) task.get(SessionDialog.PASSWORD); + String username = task.getString(SessionDialog.USERNAME); + String password = task.getString(SessionDialog.PASSWORD); if(validUserLoginData(username, password)) { - session_id_bundle = register(username, password); + result = register(username, password); broadcastProgress(progress++); } else { if(!wellFormedPassword(password)) { - session_id_bundle.putBoolean(RESULT_KEY, false); - session_id_bundle.putString(SessionDialog.USERNAME, username); - session_id_bundle.putBoolean(SessionDialog.PASSWORD_INVALID_LENGTH, true); + result.putBoolean(RESULT_KEY, false); + result.putString(SessionDialog.USERNAME, username); + result.putBoolean(SessionDialog.PASSWORD_INVALID_LENGTH, true); } - if(username.isEmpty()) { - session_id_bundle.putBoolean(RESULT_KEY, false); - session_id_bundle.putBoolean(SessionDialog.USERNAME_MISSING, true); + if(!validUsername(username)) { + result.putBoolean(RESULT_KEY, false); + result.putBoolean(SessionDialog.USERNAME_MISSING, true); } } - return session_id_bundle; + return result; } private Bundle register(String username, String password) { diff --git a/app/src/debug/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/debug/java/se/leap/bitmaskclient/ProviderDetailFragment.java index d6f482ca..4b46e48f 100644 --- a/app/src/debug/java/se/leap/bitmaskclient/ProviderDetailFragment.java +++ b/app/src/debug/java/se/leap/bitmaskclient/ProviderDetailFragment.java @@ -1,17 +1,17 @@ -package se.leap.bitmaskclient; - -import org.json.*; - -import se.leap.bitmaskclient.R; -import se.leap.bitmaskclient.eip.Constants; -import se.leap.bitmaskclient.ProviderListContent.ProviderItem; - -import android.app.*; -import android.content.*; -import android.os.Bundle; -import android.view.*; -import android.widget.TextView; - +package se.leap.bitmaskclient; + +import org.json.*; + +import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.eip.Constants; +import se.leap.bitmaskclient.ProviderListContent.ProviderItem; + +import android.app.*; +import android.content.*; +import android.os.Bundle; +import android.view.*; +import android.widget.TextView; + public class ProviderDetailFragment extends DialogFragment { final public static String TAG = "providerDetailFragment"; @@ -61,7 +61,7 @@ public class ProviderDetailFragment extends DialogFragment { private boolean anon_allowed(JSONObject provider_json) { try { JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(Constants.ALLOWED_ANON) && service_description.getBoolean(Constants.ALLOWED_ANON); + return service_description.has(Constants.ALLOWED_ANON) && service_description.getBoolean(Constants.ALLOWED_ANON); } catch (JSONException e) { return false; } @@ -80,8 +80,8 @@ public class ProviderDetailFragment extends DialogFragment { public void onCancel(DialogInterface dialog) { super.onCancel(dialog); SharedPreferences.Editor editor = getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); - editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit(); - interface_with_configuration_wizard.showAllProviders(); + editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit(); + interface_with_configuration_wizard.showAllProviders(); } public static DialogFragment newInstance() { diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index afe1a638..6d368e11 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -310,10 +310,10 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn private Bundle bundleParameters(String username, String password) { Bundle parameters = new Bundle(); - if(!username.isEmpty() && !password.isEmpty()) { + if(!username.isEmpty()) parameters.putString(SessionDialog.USERNAME, username); + if(!password.isEmpty()) parameters.putString(SessionDialog.PASSWORD, password); - } return parameters; } @@ -344,12 +344,13 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } public void sessionDialog(Bundle resultData) { + FragmentTransaction transaction = fragment_manager.removePreviousFragment(SessionDialog.TAG); - DialogFragment newFragment = SessionDialog.newInstance(); - if(resultData != null && !resultData.isEmpty() && fragment_manager.findFragmentByTag(SessionDialog.TAG) == null) { + DialogFragment newFragment = new SessionDialog(); + if(resultData != null && !resultData.isEmpty()) { newFragment.setArguments(resultData); - } + } newFragment.show(transaction, SessionDialog.TAG); } diff --git a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java index fd9ca851..9025564b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java @@ -26,6 +26,8 @@ import android.view.View; import android.widget.EditText; import android.widget.TextView; +import org.jetbrains.annotations.NotNull; + import butterknife.ButterKnife; import butterknife.InjectView; @@ -56,43 +58,29 @@ public class SessionDialog extends DialogFragment{ @InjectView(R.id.password_entered) EditText password_field; - private static SessionDialog dialog; - private static boolean is_eip_pending = false; + + public SessionDialog() { + setArguments(Bundle.EMPTY); + } public AlertDialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.session_dialog, null); ButterKnife.inject(this, view); - - if(!username_field.getText().toString().isEmpty() && password_field.isFocusable()) { - password_field.requestFocus(); - } Bundle arguments = getArguments(); - if (arguments != null) { - is_eip_pending = arguments.getBoolean(EipFragment.IS_PENDING, false); - if (arguments.containsKey(PASSWORD_INVALID_LENGTH)) - password_field.setError(getString(R.string.error_not_valid_password_user_message)); - if (arguments.containsKey(USERNAME)) { - String username = arguments.getString(USERNAME); - username_field.setText(username); - } - if (arguments.containsKey(USERNAME_MISSING)) { - username_field.setError(getString(R.string.username_ask)); - } - if(arguments.containsKey(getString(R.string.user_message))) - user_message.setText(arguments.getString(getString(R.string.user_message))); - else - user_message.setVisibility(View.GONE); + if (arguments != Bundle.EMPTY) { + setUp(arguments); } builder.setView(view) .setPositiveButton(R.string.login_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - String username = username_field.getText().toString(); - String password = password_field.getText().toString(); + String username = getEnteredUsername(); + String password = getEnteredPassword(); dialog.dismiss(); interface_with_Dashboard.logIn(username, password); } @@ -105,8 +93,9 @@ public class SessionDialog extends DialogFragment{ }) .setNeutralButton(R.string.signup_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - String username = username_field.getText().toString(); - String password = password_field.getText().toString(); + String username = getEnteredUsername(); + String password = getEnteredPassword(); + dialog.dismiss(); interface_with_Dashboard.signUp(username, password); } }); @@ -114,6 +103,35 @@ public class SessionDialog extends DialogFragment{ return builder.create(); } + private void setUp(Bundle arguments) { + is_eip_pending = arguments.getBoolean(EipFragment.IS_PENDING, false); + if (arguments.containsKey(PASSWORD_INVALID_LENGTH)) + password_field.setError(getString(R.string.error_not_valid_password_user_message)); + if (arguments.containsKey(USERNAME)) { + String username = arguments.getString(USERNAME); + username_field.setText(username); + } + if (arguments.containsKey(USERNAME_MISSING)) { + username_field.setError(getString(R.string.username_ask)); + } + if(arguments.containsKey(getString(R.string.user_message))) + user_message.setText(arguments.getString(getString(R.string.user_message))); + else + user_message.setVisibility(View.GONE); + + if(!username_field.getText().toString().isEmpty() && password_field.isFocusable()) + password_field.requestFocus(); + + } + + private String getEnteredUsername() { + return username_field.getText().toString(); + } + + private String getEnteredPassword() { + return password_field.getText().toString(); + } + /** * Interface used to communicate SessionDialog with Dashboard. @@ -128,16 +146,6 @@ public class SessionDialog extends DialogFragment{ } SessionDialogInterface interface_with_Dashboard; - - /** - * @return a new instance of this DialogFragment. - */ - public static DialogFragment newInstance() { - if(dialog == null) - dialog = new SessionDialog(); - - return dialog; - } @Override public void onAttach(Activity activity) { diff --git a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java index 334efaa9..c8efe0de 100644 --- a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java @@ -174,28 +174,28 @@ public class ProviderAPI extends IntentService { } private Bundle tryToRegister(Bundle task) { - Bundle session_id_bundle = new Bundle(); + Bundle result = new Bundle(); int progress = 0; - String username = (String) task.get(SessionDialog.USERNAME); - String password = (String) task.get(SessionDialog.PASSWORD); + String username = task.getString(SessionDialog.USERNAME); + String password = task.getString(SessionDialog.PASSWORD); if(validUserLoginData(username, password)) { - session_id_bundle = register(username, password); + result = register(username, password); broadcastProgress(progress++); } else { if(!wellFormedPassword(password)) { - session_id_bundle.putBoolean(RESULT_KEY, false); - session_id_bundle.putString(SessionDialog.USERNAME, username); - session_id_bundle.putBoolean(SessionDialog.PASSWORD_INVALID_LENGTH, true); + result.putBoolean(RESULT_KEY, false); + result.putString(SessionDialog.USERNAME, username); + result.putBoolean(SessionDialog.PASSWORD_INVALID_LENGTH, true); } - if(username.isEmpty()) { - session_id_bundle.putBoolean(RESULT_KEY, false); - session_id_bundle.putBoolean(SessionDialog.USERNAME_MISSING, true); + if(!validUsername(username)) { + result.putBoolean(RESULT_KEY, false); + result.putBoolean(SessionDialog.USERNAME_MISSING, true); } } - return session_id_bundle; + return result; } private Bundle register(String username, String password) { -- cgit v1.2.3