From 262425c6ad7cfa6509dc53150e592b3f6fd366c1 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Wed, 5 Feb 2014 21:36:11 +0000 Subject: [PATCH] edit ui knows it it has been changed --- .../keychain/ui/widget/SectionView.java | 5 +---- .../keychain/ui/widget/UserIdEditor.java | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 19926abd3..bf8a3f96b 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -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); } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index a56340582..4cd1392c2 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -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; } }