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,
mEditors, false);
view.setEditorListener(this);
view.setValue(userId);
if (mEditors.getChildCount() == 0) {
view.setIsMainUserId(true);
}
view.setValue(userId, mEditors.getChildCount() == 0);
view.setCanEdit(canEdit);
mEditors.addView(view);
}

View File

@ -38,8 +38,12 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
private BootstrapButton mDeleteButton;
private RadioButton mIsMainUserId;
private EditText mName;
private String mOriginalName;
private EditText mEmail;
private String mOriginalEmail;
private EditText mComment;
private String mOriginalComment;
private boolean mOriginallyMainUserID;
// see http://www.regular-expressions.info/email.html
// 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();
}
public void setValue(String userId) {
public void setValue(String userId, boolean isMainID) {
mName.setText("");
mComment.setText("");
mEmail.setText("");
//TODO: update this file for blank email/name?
Pattern withComment = Pattern.compile("^(.*) [(](.*)[)] <(.*)>$");
Matcher matcher = withComment.matcher(userId);
if (matcher.matches()) {
mName.setText(matcher.group(1));
mOriginalName = matcher.group(1);
mComment.setText(matcher.group(2));
mOriginalComment = matcher.group(2);
mEmail.setText(matcher.group(3));
mOriginalEmail = matcher.group(3);
return;
}
@ -126,9 +135,14 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
matcher = withoutComment.matcher(userId);
if (matcher.matches()) {
mName.setText(matcher.group(1));
mOriginalName = matcher.group(1);
mEmail.setText(matcher.group(2));
mOriginalEmail = matcher.group(2);
mOriginalComment = "";
return;
}
mOriginallyMainUserID = isMainID;
setIsMainUserId(isMainID);
}
public String getValue() throws NoNameException, NoEmailException, InvalidEmailException {
@ -207,6 +221,10 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
@Override
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;
}
}