aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain
diff options
context:
space:
mode:
authorDaniel Ramos <hiperzone@gmail.com>2015-03-27 22:36:20 +0000
committerDaniel Ramos <hiperzone@gmail.com>2015-03-27 23:15:27 +0000
commit605c9ace5859fae10d60c04af3acee236ac6a669 (patch)
tree7fa7793ff47baf8d67c0e6e942e8d75a5047aea8 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain
parentd6368db5641f21c817f736913de75c1fc85f0fda (diff)
downloadopen-keychain-605c9ace5859fae10d60c04af3acee236ac6a669.tar.gz
open-keychain-605c9ace5859fae10d60c04af3acee236ac6a669.tar.bz2
open-keychain-605c9ace5859fae10d60c04af3acee236ac6a669.zip
-Fixed a situation where additional emails could be duplicated when creating a new key -If CreateKeyEmailFragment view is recreated, the array of additional emails won't be repopulated again if its not null, avoiding new reallocations. -if CreateKeyEmailFragment view is recreated, the email adapter wont be recreated if its not null, avoiding new reallocations.
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java48
1 files changed, 36 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);
}
}
};