diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-03-28 18:10:32 +0100 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-03-28 18:10:32 +0100 |
commit | 73bccd6c58adb411a906532bed3d1387da1a4fc9 (patch) | |
tree | 7fa7793ff47baf8d67c0e6e942e8d75a5047aea8 /OpenKeychain/src | |
parent | d6368db5641f21c817f736913de75c1fc85f0fda (diff) | |
parent | 605c9ace5859fae10d60c04af3acee236ac6a669 (diff) | |
download | open-keychain-73bccd6c58adb411a906532bed3d1387da1a4fc9.tar.gz open-keychain-73bccd6c58adb411a906532bed3d1387da1a4fc9.tar.bz2 open-keychain-73bccd6c58adb411a906532bed3d1387da1a4fc9.zip |
Merge pull request #1187 from Hiperzone/development
-Fixed a situation where additional emails could be duplicated when crea...
Diffstat (limited to 'OpenKeychain/src')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java | 48 | ||||
-rw-r--r-- | OpenKeychain/src/main/res/values/strings.xml | 1 |
2 files changed, 37 insertions, 12 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java index 2e8a1f370..7e2e1c31c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java @@ -39,6 +39,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; import org.sufficientlysecure.keychain.ui.dialog.AddEmailDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment; +import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.widget.EmailEditText; import java.util.ArrayList; @@ -122,16 +123,22 @@ public class CreateKeyEmailFragment extends Fragment { mEmailsRecyclerView.setItemAnimator(new DefaultItemAnimator()); // initial values - mAdditionalEmailModels = new ArrayList<>(); - if (mCreateKeyActivity.mAdditionalEmails != null) { - setAdditionalEmails(mCreateKeyActivity.mAdditionalEmails); - } - mEmailAdapter = new EmailAdapter(mAdditionalEmailModels, new View.OnClickListener() { - @Override - public void onClick(View v) { - addEmail(); + if (mAdditionalEmailModels == null) { + mAdditionalEmailModels = new ArrayList<>(); + if (mCreateKeyActivity.mAdditionalEmails != null) { + setAdditionalEmails(mCreateKeyActivity.mAdditionalEmails); } - }); + } + + if (mEmailAdapter == null) { + mEmailAdapter = new EmailAdapter(mAdditionalEmailModels, new View.OnClickListener() { + @Override + public void onClick(View v) { + addEmail(); + } + }); + } + mEmailsRecyclerView.setAdapter(mEmailAdapter); return view; @@ -144,10 +151,27 @@ public class CreateKeyEmailFragment extends Fragment { if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) { Bundle data = message.getData(); + String email = data.getString(AddEmailDialogFragment.MESSAGE_DATA_EMAIL); + + if (email.length() > 0 && mEmailEdit.getText().length() > 0 && + email.equals(mEmailEdit.getText().toString())) { + Notify.create(getActivity(), + getString(R.string.create_key_email_already_exists_text), + Notify.LENGTH_LONG, Notify.Style.ERROR).show(); + return; + } + //check for duplicated emails inside the adapter + for (EmailAdapter.ViewModel model : mAdditionalEmailModels) { + if (email.equals(model.email)) { + Notify.create(getActivity(), + getString(R.string.create_key_email_already_exists_text), + Notify.LENGTH_LONG, Notify.Style.ERROR).show(); + return; + } + } + // add new user id - mEmailAdapter.add( - data.getString(AddEmailDialogFragment.MESSAGE_DATA_EMAIL) - ); + mEmailAdapter.add(email); } } }; diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index 8c4fe2a33..6ee30887b 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -629,6 +629,7 @@ <string name="create_key_edit">"Change key configuration"</string> <string name="create_key_add_email">"Add email address"</string> <string name="create_key_add_email_text">"Additional email addresses are also associated to this key and can be used for secure communication."</string> + <string name="create_key_email_already_exists_text">"Email has already been added"</string> <!-- View key --> <string name="view_key_revoked">"Revoked: Key must not be used anymore!"</string> |