summaryrefslogtreecommitdiff
path: root/app/src/main/java/se
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2015-01-26 14:18:56 +0100
committerParménides GV <parmegv@sdf.org>2015-01-30 11:59:06 +0100
commit7d046fda66e8933b509b854077b7acfb3b3b7c40 (patch)
tree77565f7d76bfc2b1bd734bd2e216169f2d657547 /app/src/main/java/se
parent1ad87b35085616d645fdae18bb03cbead03bd6c9 (diff)
Don't reuse last session dialog.
It was giving problems when trying to change the arguments.
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java11
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/SessionDialog.java78
2 files changed, 49 insertions, 40 deletions
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) {