Further simplify logic, and fix menu behavior
This commit is contained in:
parent
495798b05a
commit
b5f2935a08
2 changed files with 44 additions and 63 deletions
|
@ -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:
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue