1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Fix NullPointerExceptions introduced by conditionally inflating the crypto layout

This commit is contained in:
cketti 2015-02-01 00:21:52 +01:00
parent dc8fd39c7e
commit 474efa1831

View File

@ -979,6 +979,10 @@ public class MessageCompose extends K9Activity implements OnClickListener,
* Fill the encrypt layout with the latest data about signature key and encryption keys. * Fill the encrypt layout with the latest data about signature key and encryption keys.
*/ */
public void updateEncryptLayout() { public void updateEncryptLayout() {
if (!isCryptoProviderEnabled()) {
return;
}
if (!mPgpData.hasSignatureKey()) { if (!mPgpData.hasSignatureKey()) {
mCryptoSignatureCheckbox.setText(R.string.btn_crypto_sign); mCryptoSignatureCheckbox.setText(R.string.btn_crypto_sign);
mCryptoSignatureCheckbox.setChecked(false); mCryptoSignatureCheckbox.setChecked(false);
@ -1634,7 +1638,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
private void saveIfNeeded() { private void saveIfNeeded() {
if (!mDraftNeedsSaving || mPreventDraftSaving || mPgpData.hasEncryptionKeys() || if (!mDraftNeedsSaving || mPreventDraftSaving || mPgpData.hasEncryptionKeys() ||
mEncryptCheckbox.isChecked() || !mAccount.hasDraftsFolder()) { shouldEncrypt() || !mAccount.hasDraftsFolder()) {
return; return;
} }
@ -2350,7 +2354,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
onSend(); onSend();
break; break;
case R.id.save: case R.id.save:
if (mEncryptCheckbox.isChecked()) { if (shouldEncrypt()) {
showDialog(DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED); showDialog(DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED);
} else { } else {
onSave(); onSave();
@ -2400,7 +2404,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (mDraftNeedsSaving) { if (mDraftNeedsSaving) {
if (mEncryptCheckbox.isChecked()) { if (shouldEncrypt()) {
showDialog(DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED); showDialog(DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED);
} else if (!mAccount.hasDraftsFolder()) { } else if (!mAccount.hasDraftsFolder()) {
showDialog(DIALOG_CONFIRM_DISCARD_ON_BACK); showDialog(DIALOG_CONFIRM_DISCARD_ON_BACK);
@ -3847,7 +3851,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
// Right now we send a text/plain-only message when the quoted text was edited, no // Right now we send a text/plain-only message when the quoted text was edited, no
// matter what the user selected for the message format. // matter what the user selected for the message format.
messageFormat = SimpleMessageFormat.TEXT; messageFormat = SimpleMessageFormat.TEXT;
} else if (mEncryptCheckbox.isChecked() || mCryptoSignatureCheckbox.isChecked()) { } else if (shouldEncrypt() || shouldSign()) {
// Right now we only support PGP inline which doesn't play well with HTML. So force // Right now we only support PGP inline which doesn't play well with HTML. So force
// plain text in those cases. // plain text in those cases.
messageFormat = SimpleMessageFormat.TEXT; messageFormat = SimpleMessageFormat.TEXT;
@ -3893,6 +3897,18 @@ public class MessageCompose extends K9Activity implements OnClickListener,
} }
} }
private boolean isCryptoProviderEnabled() {
return mOpenPgpProvider != null;
}
private boolean shouldEncrypt() {
return isCryptoProviderEnabled() && mEncryptCheckbox.isChecked();
}
private boolean shouldSign() {
return isCryptoProviderEnabled() && mCryptoSignatureCheckbox.isChecked();
}
class DoLaunchOnClickListener implements OnClickListener { class DoLaunchOnClickListener implements OnClickListener {
private final int resultId; private final int resultId;