diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-09-28 18:05:09 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-09-28 18:05:09 +0200 |
commit | b65a23f2d46f905160b47e044de12cf9177dfd51 (patch) | |
tree | 70729ee7087a4727b4c3b97f29c56f49729b2b61 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/BackupCodeEntryFragment.java | |
parent | 97b2178a29db00258d90d59d6c05a517afc4124f (diff) | |
download | open-keychain-b65a23f2d46f905160b47e044de12cf9177dfd51.tar.gz open-keychain-b65a23f2d46f905160b47e044de12cf9177dfd51.tar.bz2 open-keychain-b65a23f2d46f905160b47e044de12cf9177dfd51.zip |
enc-export: easier mechanism to get backup code from edittexts
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/BackupCodeEntryFragment.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/BackupCodeEntryFragment.java | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/BackupCodeEntryFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/BackupCodeEntryFragment.java index db9001930..fdf875563 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/BackupCodeEntryFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/BackupCodeEntryFragment.java @@ -96,7 +96,6 @@ public class BackupCodeEntryFragment extends CryptoOperationFragment<ExportKeyri STATE_UNINITIALIZED, STATE_DISPLAY, STATE_INPUT, STATE_INPUT_ERROR, STATE_OK } - StringBuilder mCurrentCodeInput = new StringBuilder("---------------------------"); BackupCodeState mCurrentState = BackupCodeState.STATE_UNINITIALIZED; void switchState(BackupCodeState state) { @@ -245,7 +244,6 @@ public class BackupCodeEntryFragment extends CryptoOperationFragment<ExportKeyri private void setupEditTextSuccessListener(final EditText[] backupCodes) { for (int i = 0; i < backupCodes.length; i++) { - final int index = i*7; backupCodes[i].addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -264,12 +262,11 @@ public class BackupCodeEntryFragment extends CryptoOperationFragment<ExportKeyri boolean inInputState = mCurrentState == BackupCodeState.STATE_INPUT || mCurrentState == BackupCodeState.STATE_INPUT_ERROR; - if (!inInputState) { + boolean partIsComplete = s.length() == 6; + if (!inInputState || !partIsComplete) { return; } - // we could do this in better granularity in onTextChanged, but it's not worth it - mCurrentCodeInput.replace(index, index +s.length(), s.toString()); checkIfCodeIsCorrect(); } }); @@ -279,19 +276,23 @@ public class BackupCodeEntryFragment extends CryptoOperationFragment<ExportKeyri private void checkIfCodeIsCorrect() { + StringBuilder backupCodeInput = new StringBuilder(26); for (EditText editText : mCodeEditText) { if (editText.getText().length() < 6) { return; } + backupCodeInput.append(editText.getText()); + backupCodeInput.append('-'); } + backupCodeInput.deleteCharAt(backupCodeInput.length() -1); // if they don't match, do nothing - if (mCurrentCodeInput.toString().equals(mBackupCode)) { + if (backupCodeInput.toString().equals(mBackupCode)) { switchState(BackupCodeState.STATE_OK); return; } - if (mCurrentCodeInput.toString().startsWith("ABC")) { + if (backupCodeInput.toString().startsWith("ABC")) { switchState(BackupCodeState.STATE_OK); return; } |