edit ui knows it it has been changed

This commit is contained in:
Ashley Hughes 2014-02-05 21:36:11 +00:00
parent 8d7cc67553
commit 262425c6ad
2 changed files with 21 additions and 6 deletions

View File

@ -273,10 +273,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
UserIdEditor view = (UserIdEditor) mInflater.inflate(R.layout.edit_key_user_id_item, UserIdEditor view = (UserIdEditor) mInflater.inflate(R.layout.edit_key_user_id_item,
mEditors, false); mEditors, false);
view.setEditorListener(this); view.setEditorListener(this);
view.setValue(userId); view.setValue(userId, mEditors.getChildCount() == 0);
if (mEditors.getChildCount() == 0) {
view.setIsMainUserId(true);
}
view.setCanEdit(canEdit); view.setCanEdit(canEdit);
mEditors.addView(view); mEditors.addView(view);
} }

View File

@ -38,8 +38,12 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
private BootstrapButton mDeleteButton; private BootstrapButton mDeleteButton;
private RadioButton mIsMainUserId; private RadioButton mIsMainUserId;
private EditText mName; private EditText mName;
private String mOriginalName;
private EditText mEmail; private EditText mEmail;
private String mOriginalEmail;
private EditText mComment; private EditText mComment;
private String mOriginalComment;
private boolean mOriginallyMainUserID;
// see http://www.regular-expressions.info/email.html // see http://www.regular-expressions.info/email.html
// RFC 2822 if we omit the syntax using double quotes and square brackets // RFC 2822 if we omit the syntax using double quotes and square brackets
@ -108,17 +112,22 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
super.onFinishInflate(); super.onFinishInflate();
} }
public void setValue(String userId) { public void setValue(String userId, boolean isMainID) {
mName.setText(""); mName.setText("");
mComment.setText(""); mComment.setText("");
mEmail.setText(""); mEmail.setText("");
//TODO: update this file for blank email/name?
Pattern withComment = Pattern.compile("^(.*) [(](.*)[)] <(.*)>$"); Pattern withComment = Pattern.compile("^(.*) [(](.*)[)] <(.*)>$");
Matcher matcher = withComment.matcher(userId); Matcher matcher = withComment.matcher(userId);
if (matcher.matches()) { if (matcher.matches()) {
mName.setText(matcher.group(1)); mName.setText(matcher.group(1));
mOriginalName = matcher.group(1);
mComment.setText(matcher.group(2)); mComment.setText(matcher.group(2));
mOriginalComment = matcher.group(2);
mEmail.setText(matcher.group(3)); mEmail.setText(matcher.group(3));
mOriginalEmail = matcher.group(3);
return; return;
} }
@ -126,9 +135,14 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
matcher = withoutComment.matcher(userId); matcher = withoutComment.matcher(userId);
if (matcher.matches()) { if (matcher.matches()) {
mName.setText(matcher.group(1)); mName.setText(matcher.group(1));
mOriginalName = matcher.group(1);
mEmail.setText(matcher.group(2)); mEmail.setText(matcher.group(2));
mOriginalEmail = matcher.group(2);
mOriginalComment = "";
return; return;
} }
mOriginallyMainUserID = isMainID;
setIsMainUserId(isMainID);
} }
public String getValue() throws NoNameException, NoEmailException, InvalidEmailException { public String getValue() throws NoNameException, NoEmailException, InvalidEmailException {
@ -207,6 +221,10 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
@Override @Override
public boolean needsSaving() { public boolean needsSaving() {
return false; boolean retval = (mOriginallyMainUserID != isMainUserId());
retval |= (mOriginalName.equals( ("" + mName.getText()).trim() ) );
retval |= (mOriginalEmail.equals( ("" + mEmail.getText()).trim() ) );
retval |= (mOriginalComment.equals( ("" + mComment.getText()).trim() ) );
return retval;
} }
} }