mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -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.DecryptStreamParser;
|
||||||
import com.fsck.k9.mailstore.LocalMessage;
|
import com.fsck.k9.mailstore.LocalMessage;
|
||||||
import com.fsck.k9.mailstore.OpenPgpResultAnnotation;
|
import com.fsck.k9.mailstore.OpenPgpResultAnnotation;
|
||||||
|
import com.fsck.k9.ui.crypto.MessageCryptoCallback;
|
||||||
import org.openintents.openpgp.IOpenPgpService;
|
import org.openintents.openpgp.IOpenPgpService;
|
||||||
import org.openintents.openpgp.OpenPgpError;
|
import org.openintents.openpgp.OpenPgpError;
|
||||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||||
@ -50,7 +51,8 @@ import org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound;
|
|||||||
public class MessageCryptoHelper {
|
public class MessageCryptoHelper {
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final MessageViewFragment fragment;
|
private final Activity activity;
|
||||||
|
private final MessageCryptoCallback callback;
|
||||||
private final Account account;
|
private final Account account;
|
||||||
private LocalMessage message;
|
private LocalMessage message;
|
||||||
|
|
||||||
@ -63,9 +65,10 @@ public class MessageCryptoHelper {
|
|||||||
|
|
||||||
private static final int INVALID_OPENPGP_RESULT_CODE = -1;
|
private static final int INVALID_OPENPGP_RESULT_CODE = -1;
|
||||||
|
|
||||||
public MessageCryptoHelper(Context context, MessageViewFragment fragment, Account account) {
|
public MessageCryptoHelper(Activity activity, Account account, MessageCryptoCallback callback) {
|
||||||
this.context = context;
|
this.context = activity.getApplicationContext();
|
||||||
this.fragment = fragment;
|
this.activity = activity;
|
||||||
|
this.callback = callback;
|
||||||
this.account = account;
|
this.account = account;
|
||||||
|
|
||||||
this.messageAnnotations = new MessageCryptoAnnotations();
|
this.messageAnnotations = new MessageCryptoAnnotations();
|
||||||
@ -133,11 +136,11 @@ public class MessageCryptoHelper {
|
|||||||
|
|
||||||
private void connectToCryptoProviderService() {
|
private void connectToCryptoProviderService() {
|
||||||
String openPgpProvider = account.getOpenPgpProvider();
|
String openPgpProvider = account.getOpenPgpProvider();
|
||||||
new OpenPgpServiceConnection(fragment.getContext(), openPgpProvider,
|
new OpenPgpServiceConnection(context, openPgpProvider,
|
||||||
new OnBound() {
|
new OnBound() {
|
||||||
@Override
|
@Override
|
||||||
public void onBound(IOpenPgpService service) {
|
public void onBound(IOpenPgpService service) {
|
||||||
openPgpApi = new OpenPgpApi(fragment.getContext(), service);
|
openPgpApi = new OpenPgpApi(context, service);
|
||||||
|
|
||||||
decryptOrVerifyNextPart();
|
decryptOrVerifyNextPart();
|
||||||
}
|
}
|
||||||
@ -342,7 +345,7 @@ public class MessageCryptoHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fragment.getActivity().startIntentSenderForResult(pendingIntent.getIntentSender(),
|
activity.startIntentSenderForResult(pendingIntent.getIntentSender(),
|
||||||
MessageList.REQUEST_CODE_CRYPTO, null, 0, 0, 0);
|
MessageList.REQUEST_CODE_CRYPTO, null, 0, 0, 0);
|
||||||
} catch (SendIntentException e) {
|
} catch (SendIntentException e) {
|
||||||
Log.e(K9.LOG_TAG, "Internal error on starting pendingintent!", e);
|
Log.e(K9.LOG_TAG, "Internal error on starting pendingintent!", e);
|
||||||
@ -416,7 +419,7 @@ public class MessageCryptoHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void returnResultToFragment() {
|
private void returnResultToFragment() {
|
||||||
fragment.startExtractingTextAndAttachments(messageAnnotations);
|
callback.onCryptoOperationsFinished(messageAnnotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MessageCryptoAnnotations {
|
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.AttachmentViewInfo;
|
||||||
import com.fsck.k9.mailstore.LocalMessage;
|
import com.fsck.k9.mailstore.LocalMessage;
|
||||||
import com.fsck.k9.mailstore.MessageViewInfo;
|
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.DecodeMessageLoader;
|
||||||
import com.fsck.k9.ui.message.LocalMessageLoader;
|
import com.fsck.k9.ui.message.LocalMessageLoader;
|
||||||
import com.fsck.k9.ui.messageview.MessageCryptoHelper.MessageCryptoAnnotations;
|
import com.fsck.k9.ui.messageview.MessageCryptoHelper.MessageCryptoAnnotations;
|
||||||
import com.fsck.k9.view.MessageHeader;
|
import com.fsck.k9.view.MessageHeader;
|
||||||
|
|
||||||
public class MessageViewFragment extends Fragment implements ConfirmationDialogFragmentListener,
|
public class MessageViewFragment extends Fragment implements ConfirmationDialogFragmentListener,
|
||||||
AttachmentViewCallback, OpenPgpHeaderViewCallback {
|
AttachmentViewCallback, OpenPgpHeaderViewCallback, MessageCryptoCallback {
|
||||||
|
|
||||||
private static final String ARG_REFERENCE = "reference";
|
private static final String ARG_REFERENCE = "reference";
|
||||||
|
|
||||||
@ -197,7 +198,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
|||||||
|
|
||||||
Context appContext = getActivity().getApplicationContext();
|
Context appContext = getActivity().getApplicationContext();
|
||||||
mAccount = Preferences.getPreferences(appContext).getAccount(mMessageReference.accountUuid);
|
mAccount = Preferences.getPreferences(appContext).getAccount(mMessageReference.accountUuid);
|
||||||
messageCryptoHelper = new MessageCryptoHelper(mContext, this, mAccount);
|
messageCryptoHelper = new MessageCryptoHelper(getActivity(), mAccount, this);
|
||||||
|
|
||||||
if (resetPgpData) {
|
if (resetPgpData) {
|
||||||
// start with fresh, empty PGP data
|
// 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();
|
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;
|
this.messageAnnotations = annotations;
|
||||||
getLoaderManager().initLoader(DECODE_MESSAGE_LOADER_ID, null, decodeMessageLoaderCallback);
|
getLoaderManager().initLoader(DECODE_MESSAGE_LOADER_ID, null, decodeMessageLoaderCallback);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user