From 3a527cbcf6ef981e03c2868b5987841159ef9a40 Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 9 Feb 2015 19:05:01 +0100 Subject: [PATCH] Decouple MessageCryptoHelper from MessageViewFragment --- .../k9/ui/crypto/MessageCryptoCallback.java | 9 +++++++++ .../ui/messageview/MessageCryptoHelper.java | 19 +++++++++++-------- .../ui/messageview/MessageViewFragment.java | 12 +++++++++--- 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoCallback.java diff --git a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoCallback.java b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoCallback.java new file mode 100644 index 000000000..f5ff35b1e --- /dev/null +++ b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoCallback.java @@ -0,0 +1,9 @@ +package com.fsck.k9.ui.crypto; + + +import com.fsck.k9.ui.messageview.MessageCryptoHelper.MessageCryptoAnnotations; + + +public interface MessageCryptoCallback { + void onCryptoOperationsFinished(MessageCryptoAnnotations annotations); +} diff --git a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageCryptoHelper.java b/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageCryptoHelper.java index 7a61e8bd3..1b1314ee6 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageCryptoHelper.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageCryptoHelper.java @@ -38,6 +38,7 @@ import com.fsck.k9.mail.internet.TextBody; import com.fsck.k9.mailstore.DecryptStreamParser; import com.fsck.k9.mailstore.LocalMessage; import com.fsck.k9.mailstore.OpenPgpResultAnnotation; +import com.fsck.k9.ui.crypto.MessageCryptoCallback; import org.openintents.openpgp.IOpenPgpService; import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.OpenPgpSignatureResult; @@ -50,7 +51,8 @@ import org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound; public class MessageCryptoHelper { private final Context context; - private final MessageViewFragment fragment; + private final Activity activity; + private final MessageCryptoCallback callback; private final Account account; private LocalMessage message; @@ -63,9 +65,10 @@ public class MessageCryptoHelper { private static final int INVALID_OPENPGP_RESULT_CODE = -1; - public MessageCryptoHelper(Context context, MessageViewFragment fragment, Account account) { - this.context = context; - this.fragment = fragment; + public MessageCryptoHelper(Activity activity, Account account, MessageCryptoCallback callback) { + this.context = activity.getApplicationContext(); + this.activity = activity; + this.callback = callback; this.account = account; this.messageAnnotations = new MessageCryptoAnnotations(); @@ -133,11 +136,11 @@ public class MessageCryptoHelper { private void connectToCryptoProviderService() { String openPgpProvider = account.getOpenPgpProvider(); - new OpenPgpServiceConnection(fragment.getContext(), openPgpProvider, + new OpenPgpServiceConnection(context, openPgpProvider, new OnBound() { @Override public void onBound(IOpenPgpService service) { - openPgpApi = new OpenPgpApi(fragment.getContext(), service); + openPgpApi = new OpenPgpApi(context, service); decryptOrVerifyNextPart(); } @@ -342,7 +345,7 @@ public class MessageCryptoHelper { } try { - fragment.getActivity().startIntentSenderForResult(pendingIntent.getIntentSender(), + activity.startIntentSenderForResult(pendingIntent.getIntentSender(), MessageList.REQUEST_CODE_CRYPTO, null, 0, 0, 0); } catch (SendIntentException e) { Log.e(K9.LOG_TAG, "Internal error on starting pendingintent!", e); @@ -416,7 +419,7 @@ public class MessageCryptoHelper { } private void returnResultToFragment() { - fragment.startExtractingTextAndAttachments(messageAnnotations); + callback.onCryptoOperationsFinished(messageAnnotations); } public static class MessageCryptoAnnotations { diff --git a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java b/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java index 084ae5b41..d32a59bd6 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java @@ -46,13 +46,14 @@ import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mailstore.AttachmentViewInfo; import com.fsck.k9.mailstore.LocalMessage; import com.fsck.k9.mailstore.MessageViewInfo; +import com.fsck.k9.ui.crypto.MessageCryptoCallback; import com.fsck.k9.ui.message.DecodeMessageLoader; import com.fsck.k9.ui.message.LocalMessageLoader; import com.fsck.k9.ui.messageview.MessageCryptoHelper.MessageCryptoAnnotations; import com.fsck.k9.view.MessageHeader; public class MessageViewFragment extends Fragment implements ConfirmationDialogFragmentListener, - AttachmentViewCallback, OpenPgpHeaderViewCallback { + AttachmentViewCallback, OpenPgpHeaderViewCallback, MessageCryptoCallback { private static final String ARG_REFERENCE = "reference"; @@ -197,7 +198,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF Context appContext = getActivity().getApplicationContext(); mAccount = Preferences.getPreferences(appContext).getAccount(mMessageReference.accountUuid); - messageCryptoHelper = new MessageCryptoHelper(mContext, this, mAccount); + messageCryptoHelper = new MessageCryptoHelper(getActivity(), mAccount, this); if (resetPgpData) { // start with fresh, empty PGP data @@ -260,7 +261,12 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF Toast.makeText(mContext, errorMessage, Toast.LENGTH_LONG).show(); } - void startExtractingTextAndAttachments(MessageCryptoAnnotations annotations) { + @Override + public void onCryptoOperationsFinished(MessageCryptoAnnotations annotations) { + startExtractingTextAndAttachments(annotations); + } + + private void startExtractingTextAndAttachments(MessageCryptoAnnotations annotations) { this.messageAnnotations = annotations; getLoaderManager().initLoader(DECODE_MESSAGE_LOADER_ID, null, decodeMessageLoaderCallback); }