diff --git a/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java b/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java index cb26c25b9..fbb0a2dfd 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java @@ -966,11 +966,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, recipientPresenter.onMenuAddFromContacts(); break; case R.id.openpgp_encrypt_disable: - recipientPresenter.onMenuSetEnableEncryption(false); + recipientPresenter.onMenuToggleEncryption(); updateMessageFormat(); break; case R.id.openpgp_encrypt_enable: - recipientPresenter.onMenuSetEnableEncryption(true); + recipientPresenter.onMenuToggleEncryption(); updateMessageFormat(); break; case R.id.openpgp_inline_enable: diff --git a/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java b/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java index 6493aa47b..13acfb9bc 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java @@ -618,57 +618,58 @@ public class RecipientPresenter { Timber.e("click on crypto status while unconfigured - this should not really happen?!"); return; case OK: - ComposeCryptoStatus currentCryptoStatus = getCurrentCachedCryptoStatus(); - if (currentCryptoStatus == null) { - Timber.e("click on crypto status while crypto status not available - should not really happen?!"); - return; - } - - if (currentCryptoStatus.isEncryptionEnabled() && !currentCryptoStatus.allRecipientsCanEncrypt()) { - recipientMvpView.showOpenPgpEnabledErrorDialog(false); - return; - } - - if (currentCryptoMode == CryptoMode.SIGN_ONLY) { - recipientMvpView.showErrorIsSignOnly(); - return; - } - - if (currentCryptoMode == CryptoMode.NO_CHOICE) { - if (currentCryptoStatus.hasAutocryptPendingIntent()) { - recipientMvpView.launchUserInteractionPendingIntent( - currentCryptoStatus.getAutocryptPendingIntent(), REQUEST_CODE_AUTOCRYPT); - } else if (currentCryptoStatus.canEncryptAndIsMutualDefault()) { - onCryptoModeChanged(CryptoMode.CHOICE_DISABLED); - } else if (currentCryptoStatus.isReplyToEncrypted()) { - // TODO warning dialog - onCryptoModeChanged(CryptoMode.CHOICE_DISABLED); - } else { - onCryptoModeChanged(CryptoMode.CHOICE_ENABLED); - } - return; - } - - if (currentCryptoMode == CryptoMode.CHOICE_DISABLED && !currentCryptoStatus.canEncryptAndIsMutualDefault()) { - onCryptoModeChanged(CryptoMode.CHOICE_ENABLED); - return; - } - - onCryptoModeChanged(CryptoMode.NO_CHOICE); + toggleEncryptionState(false); return; - case UI_REQUIRED: // TODO show openpgp settings PendingIntent pendingIntent = openPgpApiManager.getUserInteractionPendingIntent(); recipientMvpView.launchUserInteractionPendingIntent(pendingIntent, OPENPGP_USER_INTERACTION); break; - case UNINITIALIZED: case ERROR: openPgpApiManager.refreshConnection(); } } + private void toggleEncryptionState(boolean showGotIt) { + ComposeCryptoStatus currentCryptoStatus = getCurrentCachedCryptoStatus(); + if (currentCryptoStatus == null) { + Timber.e("click on crypto status while crypto status not available - should not really happen?!"); + return; + } + + if (currentCryptoStatus.isEncryptionEnabled() && !currentCryptoStatus.allRecipientsCanEncrypt()) { + recipientMvpView.showOpenPgpEnabledErrorDialog(false); + return; + } + + if (currentCryptoMode == CryptoMode.SIGN_ONLY) { + recipientMvpView.showErrorIsSignOnly(); + return; + } + + boolean isEncryptOnNoChoice = currentCryptoStatus.canEncryptAndIsMutualDefault() || + currentCryptoStatus.isReplyToEncrypted(); + if (currentCryptoMode == CryptoMode.NO_CHOICE) { + if (currentCryptoStatus.hasAutocryptPendingIntent()) { + recipientMvpView.launchUserInteractionPendingIntent( + currentCryptoStatus.getAutocryptPendingIntent(), REQUEST_CODE_AUTOCRYPT); + } else if (isEncryptOnNoChoice) { + // TODO warning dialog if we override, especially from reply! + onCryptoModeChanged(CryptoMode.CHOICE_DISABLED); + } else { + onCryptoModeChanged(CryptoMode.CHOICE_ENABLED); + if (showGotIt) { + recipientMvpView.showOpenPgpEncryptExplanationDialog(); + } + } + } else if (currentCryptoMode == CryptoMode.CHOICE_DISABLED && !isEncryptOnNoChoice) { + onCryptoModeChanged(CryptoMode.CHOICE_ENABLED); + } else { + onCryptoModeChanged(CryptoMode.NO_CHOICE); + } + } + /** * Does the device actually have a Contacts application suitable for * picking a contact. As hard as it is to believe, some vendors ship @@ -755,28 +756,8 @@ public class RecipientPresenter { } } - public void onMenuSetEnableEncryption(boolean enableEncryption) { - if (cachedCryptoStatus == null) { - Timber.e("Received crypto button press while status wasn't initialized?"); - return; - } - if (enableEncryption) { - if (!cachedCryptoStatus.allRecipientsCanEncrypt()) { - onCryptoModeChanged(CryptoMode.CHOICE_ENABLED); - recipientMvpView.showOpenPgpEnabledErrorDialog(true); - } else if (cachedCryptoStatus.canEncryptAndIsMutualDefault()) { - onCryptoModeChanged(CryptoMode.NO_CHOICE); - } else { - recipientMvpView.showOpenPgpEncryptExplanationDialog(); - onCryptoModeChanged(CryptoMode.CHOICE_ENABLED); - } - } else { - if (cachedCryptoStatus.canEncryptAndIsMutualDefault()) { - onCryptoModeChanged(CryptoMode.CHOICE_DISABLED); - } else { - onCryptoModeChanged(CryptoMode.NO_CHOICE); - } - } + public void onMenuToggleEncryption() { + toggleEncryptionState(true); } public void onCryptoPgpClickDisable() {