diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-06-06 23:17:42 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-06-06 23:17:42 +0200 |
commit | 074b6633b015aba84f8f60a05878a93d4b8ec9b2 (patch) | |
tree | b7d11a8df2bc0ff93b245fbc67d7c7ba6bf9dd18 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java | |
parent | 7cfc0d80d0b4318ce1ae027536d70c2cda4c8605 (diff) | |
download | open-keychain-074b6633b015aba84f8f60a05878a93d4b8ec9b2.tar.gz open-keychain-074b6633b015aba84f8f60a05878a93d4b8ec9b2.tar.bz2 open-keychain-074b6633b015aba84f8f60a05878a93d4b8ec9b2.zip |
eventbus: initial attempt, replace messenger hack with eventbus communication
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java | 145 |
1 files changed, 53 insertions, 92 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java index ddfdecca3..ba626cf11 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java @@ -49,6 +49,7 @@ import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.PgpConstants; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; +import org.sufficientlysecure.keychain.service.KeychainNewService; import org.sufficientlysecure.keychain.service.KeychainService; import org.sufficientlysecure.keychain.service.ServiceProgressHandler; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -72,7 +73,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -public class EncryptFilesFragment extends CachingCryptoOperationFragment<SignEncryptParcel> { +public class EncryptFilesFragment + extends CachingCryptoOperationFragment<SignEncryptParcel, SignEncryptResult> { public static final String ARG_DELETE_AFTER_ENCRYPT = "delete_after_encrypt"; public static final String ARG_ENCRYPT_FILENAMES = "encrypt_filenames"; @@ -272,11 +274,13 @@ public class EncryptFilesFragment extends CachingCryptoOperationFragment<SignEnc public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.encrypt_save: { - cryptoOperation(false); + mShareAfterEncrypt = false; + cryptoOperation(); break; } case R.id.encrypt_share: { - cryptoOperation(true); + mShareAfterEncrypt = true; + cryptoOperation(); break; } case R.id.check_use_armor: { @@ -374,7 +378,9 @@ public class EncryptFilesFragment extends CachingCryptoOperationFragment<SignEnc } - public void onEncryptSuccess(final SignEncryptResult result) { + @Override + protected void onCryptoOperationSuccess(final SignEncryptResult result) { + if (mDeleteAfterEncrypt) { DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(mFilesAdapter.getAsArrayList()); @@ -402,6 +408,7 @@ public class EncryptFilesFragment extends CachingCryptoOperationFragment<SignEnc result.createNotify(getActivity()).show(); } } + } // prepares mOutputUris, either directly and returns false, or indirectly @@ -441,7 +448,46 @@ public class EncryptFilesFragment extends CachingCryptoOperationFragment<SignEnc } } - protected SignEncryptParcel createIncompleteEncryptBundle() { + protected SignEncryptParcel createOperationInput() { + + SignEncryptParcel actionsParcel = getCachedActionsParcel(); + + // we have three cases here: nothing cached, cached except output, fully cached + if (actionsParcel == null) { + + // clear output uris for now, they will be created by prepareOutputStreams later + mOutputUris = null; + + actionsParcel = createIncompleteCryptoInput(); + // this is null if invalid, just return in that case + if (actionsParcel == null) { + return null; + } + + cacheActionsParcel(actionsParcel); + + } + + // if it's incomplete, prepare output streams + if (actionsParcel.isIncomplete()) { + // if this is still null, prepare output streams again + if (mOutputUris == null) { + // this may interrupt the flow, and call us again from onActivityResult + if (prepareOutputStreams(mShareAfterEncrypt)) { + return null; + } + } + + actionsParcel.addOutputUris(mOutputUris); + cacheActionsParcel(actionsParcel); + + } + + return actionsParcel; + + } + + protected SignEncryptParcel createIncompleteCryptoInput() { // fill values for this action SignEncryptParcel data = new SignEncryptParcel(); @@ -546,92 +592,6 @@ public class EncryptFilesFragment extends CachingCryptoOperationFragment<SignEnc return sendIntent; } - public void cryptoOperation(boolean share) { - mShareAfterEncrypt = share; - cryptoOperation(); - } - - @Override - protected void cryptoOperation(CryptoInputParcel cryptoInput, SignEncryptParcel actionsParcel) { - - // we have three cases here: nothing cached, cached except output, fully cached - if (actionsParcel == null) { - - // clear output uris for now, they will be created by prepareOutputStreams later - mOutputUris = null; - - actionsParcel = createIncompleteEncryptBundle(); - // this is null if invalid, just return in that case - if (actionsParcel == null) { - // Notify was created by createEncryptBundle. - return; - } - - cacheActionsParcel(actionsParcel); - } - - // if it's incomplete, prepare output streams - if (actionsParcel.isIncomplete()) { - // if this is still null, prepare output streams again - if (mOutputUris == null) { - // this may interrupt the flow, and call us again from onActivityResult - if (prepareOutputStreams(mShareAfterEncrypt)) { - return; - } - } - - actionsParcel.addOutputUris(mOutputUris); - cacheActionsParcel(actionsParcel); - } - - // Send all information needed to service to edit key in other thread - Intent intent = new Intent(getActivity(), KeychainService.class); - intent.setAction(KeychainService.ACTION_SIGN_ENCRYPT); - - Bundle data = new Bundle(); - data.putParcelable(KeychainService.SIGN_ENCRYPT_PARCEL, actionsParcel); - data.putParcelable(KeychainService.EXTRA_CRYPTO_INPUT, cryptoInput); - intent.putExtra(KeychainService.EXTRA_DATA, data); - - // Message is received after encrypting is done in KeychainService - ServiceProgressHandler serviceHandler = new ServiceProgressHandler( - getActivity(), - getString(R.string.progress_encrypting), - ProgressDialog.STYLE_HORIZONTAL, - true - ) { - @Override - public void handleMessage(Message message) { - // handle messages by standard KeychainIntentServiceHandler first - super.handleMessage(message); - - // handle pending messages - if (handlePendingMessage(message)) { - return; - } - - if (message.arg1 == MessageStatus.OKAY.ordinal()) { - SignEncryptResult result = - message.getData().getParcelable(SignEncryptResult.EXTRA_RESULT); - if (result.success()) { - onEncryptSuccess(result); - } else { - result.createNotify(getActivity()).show(); - } - } - } - }; - // Create a new Messenger for the communication back - Messenger messenger = new Messenger(serviceHandler); - intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger); - - // show progress dialog - serviceHandler.showProgressDialog(getActivity()); - - // start service with intent - getActivity().startService(intent); - } - @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { @@ -646,7 +606,8 @@ public class EncryptFilesFragment extends CachingCryptoOperationFragment<SignEnc if (resultCode == Activity.RESULT_OK && data != null) { mOutputUris = new ArrayList<>(1); mOutputUris.add(data.getData()); - cryptoOperation(false); + mShareAfterEncrypt = false; + cryptoOperation(); } return; } |