mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-04 16:45:09 -05:00
Decouple MessageCryptoHelper from MessageViewFragment
This commit is contained in:
parent
948cb971ad
commit
3a527cbcf6
@ -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);
|
||||
}
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user