Skip to content

Commit

Permalink
Merge pull request #242 from ACRA/user_email_wiped_after_dialog
Browse files Browse the repository at this point in the history
User email wiped after dialog
  • Loading branch information
william-ferguson-au committed Feb 24, 2015
2 parents 3ee37a5 + 521903d commit 187cc78
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions src/main/java/org/acra/CrashReportDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ public class CrashReportDialog extends BaseCrashReportDialog implements DialogIn

private static final String STATE_EMAIL = "email";
private static final String STATE_COMMENT = "comment";
private SharedPreferences prefs;
private EditText userComment;
private EditText userEmail;
private EditText userCommentView;
private EditText userEmailView;

AlertDialog mDialog;

Expand Down Expand Up @@ -82,15 +81,15 @@ protected View buildCustomView(Bundle savedInstanceState) {
scrollable.addView(label, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));

userComment = new EditText(this);
userComment.setLines(2);
userCommentView = new EditText(this);
userCommentView.setLines(2);
if (savedInstanceState != null) {
String savedValue = savedInstanceState.getString(STATE_COMMENT);
if (savedValue != null) {
userComment.setText(savedValue);
userCommentView.setText(savedValue);
}
}
scrollable.addView(userComment);
scrollable.addView(userCommentView);
}

// Add an optional user email field
Expand All @@ -102,22 +101,21 @@ protected View buildCustomView(Bundle savedInstanceState) {
label.setPadding(label.getPaddingLeft(), 10, label.getPaddingRight(), label.getPaddingBottom());
scrollable.addView(label);

userEmail = new EditText(this);
userEmail.setSingleLine();
userEmail.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
userEmailView = new EditText(this);
userEmailView.setSingleLine();
userEmailView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);

prefs = getSharedPreferences(ACRA.getConfig().sharedPreferencesName(), ACRA.getConfig()
.sharedPreferencesMode());
String savedValue = null;
if (savedInstanceState != null) {
savedValue = savedInstanceState.getString(STATE_EMAIL);
}
if (savedValue != null) {
userEmail.setText(savedValue);
userEmailView.setText(savedValue);
} else {
userEmail.setText(prefs.getString(ACRA.PREF_USER_EMAIL_ADDRESS, ""));
final SharedPreferences prefs = ACRA.getACRASharedPreferences();
userEmailView.setText(prefs.getString(ACRA.PREF_USER_EMAIL_ADDRESS, ""));
}
scrollable.addView(userEmail);
scrollable.addView(userEmailView);
}

return root;
Expand All @@ -127,19 +125,20 @@ protected View buildCustomView(Bundle savedInstanceState) {
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
// Retrieve user comment
final String comment = userComment != null ? userComment.getText().toString() : "";
final String comment = userCommentView != null ? userCommentView.getText().toString() : "";

// Store the user email
final String usrEmail;
if (prefs != null && userEmail != null) {
usrEmail = userEmail.getText().toString();
final String userEmail;
final SharedPreferences prefs = ACRA.getACRASharedPreferences();
if (userEmailView != null) {
userEmail = userEmailView.getText().toString();
final SharedPreferences.Editor prefEditor = prefs.edit();
prefEditor.putString(ACRA.PREF_USER_EMAIL_ADDRESS, usrEmail);
prefEditor.putString(ACRA.PREF_USER_EMAIL_ADDRESS, userEmail);
prefEditor.commit();
} else {
usrEmail = "";
userEmail = prefs.getString(ACRA.PREF_USER_EMAIL_ADDRESS, "");
}
sendCrash(comment, usrEmail);
sendCrash(comment, userEmail);
} else {
cancelReports();
}
Expand All @@ -161,11 +160,11 @@ public void onDismiss(DialogInterface dialog) {
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (userComment != null && userComment.getText() != null) {
outState.putString(STATE_COMMENT, userComment.getText().toString());
if (userCommentView != null && userCommentView.getText() != null) {
outState.putString(STATE_COMMENT, userCommentView.getText().toString());
}
if (userEmail != null && userEmail.getText() != null) {
outState.putString(STATE_EMAIL, userEmail.getText().toString());
if (userEmailView != null && userEmailView.getText() != null) {
outState.putString(STATE_EMAIL, userEmailView.getText().toString());
}
}
}

0 comments on commit 187cc78

Please sign in to comment.