Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5f2935a authored by Vincent Breitmoser's avatar Vincent Breitmoser
Browse files

Further simplify logic, and fix menu behavior

parent 495798b0
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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:
+42 −61
Original line number Diff line number Diff line
@@ -618,6 +618,20 @@ public class RecipientPresenter {
                Timber.e("click on crypto status while unconfigured - this should not really happen?!");
                return;
            case OK:
                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?!");
@@ -634,38 +648,25 @@ public class RecipientPresenter {
            return;
        }

        boolean isEncryptOnNoChoice = currentCryptoStatus.canEncryptAndIsMutualDefault() ||
                currentCryptoStatus.isReplyToEncrypted();
        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
            } 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();
                }
                    return;
            }

                if (currentCryptoMode == CryptoMode.CHOICE_DISABLED && !currentCryptoStatus.canEncryptAndIsMutualDefault()) {
        } else if (currentCryptoMode == CryptoMode.CHOICE_DISABLED && !isEncryptOnNoChoice) {
            onCryptoModeChanged(CryptoMode.CHOICE_ENABLED);
                    return;
                }

        } else {
            onCryptoModeChanged(CryptoMode.NO_CHOICE);
                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();
        }
    }

@@ -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() {