diff --git a/k9mail/src/main/java/com/fsck/k9/activity/compose/ComposeCryptoStatus.java b/k9mail/src/main/java/com/fsck/k9/activity/compose/ComposeCryptoStatus.java index 4c37233ff..290a5bf16 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/compose/ComposeCryptoStatus.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/compose/ComposeCryptoStatus.java @@ -4,6 +4,7 @@ package com.fsck.k9.activity.compose; import java.util.ArrayList; import java.util.List; +import com.fsck.k9.activity.compose.RecipientMvpView.CryptoSpecialModeDisplayType; import com.fsck.k9.activity.compose.RecipientMvpView.CryptoStatusDisplayType; import com.fsck.k9.activity.compose.RecipientPresenter.CryptoMode; import com.fsck.k9.activity.compose.RecipientPresenter.CryptoProviderState; @@ -43,7 +44,7 @@ public class ComposeCryptoStatus { return signingKeyId; } - public CryptoStatusDisplayType getCryptoStatusDisplayType() { + CryptoStatusDisplayType getCryptoStatusDisplayType() { switch (cryptoProviderState) { case UNCONFIGURED: return CryptoStatusDisplayType.UNCONFIGURED; @@ -87,6 +88,22 @@ public class ComposeCryptoStatus { } } + CryptoSpecialModeDisplayType getCryptoSpecialModeDisplayType() { + if (cryptoProviderState != CryptoProviderState.OK) { + return CryptoSpecialModeDisplayType.NONE; + } + + if (isPgpInlineModeEnabled()) { + return CryptoSpecialModeDisplayType.PGP_INLINE; + } + + if (isSignOnly()) { + return CryptoSpecialModeDisplayType.SIGN_ONLY; + } + + return CryptoSpecialModeDisplayType.NONE; + } + public boolean shouldUsePgpMessageBuilder() { return cryptoProviderState != CryptoProviderState.UNCONFIGURED && cryptoMode != CryptoMode.DISABLE; } @@ -223,11 +240,11 @@ public class ComposeCryptoStatus { return null; } - public enum AttachErrorState { + enum AttachErrorState { IS_INLINE } - public AttachErrorState getAttachErrorStateOrNull() { + AttachErrorState getAttachErrorStateOrNull() { if (cryptoProviderState == CryptoProviderState.UNCONFIGURED) { return null; } diff --git a/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientMvpView.java b/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientMvpView.java index 0efa9a959..e99df44bb 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientMvpView.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientMvpView.java @@ -33,7 +33,10 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener private static final int VIEW_INDEX_CRYPTO_STATUS_DISABLED_NO_KEY = 4; private static final int VIEW_INDEX_CRYPTO_STATUS_UNTRUSTED = 5; private static final int VIEW_INDEX_CRYPTO_STATUS_TRUSTED = 6; - private static final int VIEW_INDEX_CRYPTO_STATUS_SIGN_ONLY = 7; + private static final int VIEW_INDEX_CRYPTO_STATUS_SIGN_ONLY = 0; + + private static final int VIEW_INDEX_CRYPTO_SPECIAL_PGP_INLINE = 0; + private static final int VIEW_INDEX_CRYPTO_SPECIAL_SIGN_ONLY = 1; private static final int VIEW_INDEX_BCC_EXPANDER_VISIBLE = 0; private static final int VIEW_INDEX_BCC_EXPANDER_HIDDEN = 1; @@ -48,7 +51,7 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener private final RecipientSelectView bccView; private final ViewAnimator cryptoStatusView; private final ViewAnimator recipientExpanderContainer; - private final View pgpInlineIndicator; + private final ViewAnimator cryptoSpecialModeIndicator; private RecipientPresenter presenter; @@ -65,7 +68,8 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener recipientExpanderContainer = (ViewAnimator) activity.findViewById(R.id.recipient_expander_container); cryptoStatusView = (ViewAnimator) activity.findViewById(R.id.crypto_status); cryptoStatusView.setOnClickListener(this); - pgpInlineIndicator = activity.findViewById(R.id.pgp_inline_indicator); + cryptoSpecialModeIndicator = (ViewAnimator) activity.findViewById(R.id.crypto_special_mode); + cryptoSpecialModeIndicator.setOnClickListener(this); toView.setOnFocusChangeListener(this); ccView.setOnFocusChangeListener(this); @@ -80,8 +84,6 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener toLabel.setOnClickListener(this); ccLabel.setOnClickListener(this); bccLabel.setOnClickListener(this); - - pgpInlineIndicator.setOnClickListener(this); } public void setPresenter(final RecipientPresenter presenter) { @@ -282,12 +284,19 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener bccView.setError(bccView.getContext().getString(R.string.compose_error_incomplete_recipient)); } - public void showPgpInlineModeIndicator(boolean pgpInlineModeEnabled) { - pgpInlineIndicator.setVisibility(pgpInlineModeEnabled ? View.VISIBLE : View.GONE); + public void showCryptoSpecialMode(CryptoSpecialModeDisplayType cryptoSpecialModeDisplayType) { + boolean shouldBeHidden = cryptoSpecialModeDisplayType.childToDisplay == VIEW_INDEX_HIDDEN; + if (shouldBeHidden) { + cryptoSpecialModeIndicator.setVisibility(View.GONE); + return; + } + + cryptoSpecialModeIndicator.setVisibility(View.VISIBLE); + cryptoSpecialModeIndicator.setDisplayedChild(cryptoSpecialModeDisplayType.childToDisplay); activity.invalidateOptionsMenu(); } - public void showCryptoStatus(final CryptoStatusDisplayType cryptoStatusDisplayType) { + public void showCryptoStatus(CryptoStatusDisplayType cryptoStatusDisplayType) { boolean shouldBeHidden = cryptoStatusDisplayType.childToDisplay == VIEW_INDEX_HIDDEN; if (shouldBeHidden) { cryptoStatusView.setVisibility(View.GONE); @@ -295,14 +304,17 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener } cryptoStatusView.setVisibility(View.VISIBLE); - int childToDisplay = cryptoStatusDisplayType.childToDisplay; - cryptoStatusView.setDisplayedChild(childToDisplay); + cryptoStatusView.setDisplayedChild(cryptoStatusDisplayType.childToDisplay); } public void showContactPicker(int requestCode) { activity.showContactPicker(requestCode); } + public void showErrorIsSignOnly() { + Toast.makeText(activity, R.string.error_sign_only_no_encryption, Toast.LENGTH_LONG).show(); + } + public void showErrorContactNoAddress() { Toast.makeText(activity, R.string.error_contact_address_not_found, Toast.LENGTH_LONG).show(); } @@ -372,8 +384,8 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener presenter.onClickCryptoStatus(); break; } - case R.id.pgp_inline_indicator: { - presenter.onClickPgpInlineIndicator(); + case R.id.crypto_special_mode: { + presenter.onClickCryptoSpecialModeIndicator(); } } } @@ -384,12 +396,12 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener } public void showOpenPgpInlineDialog(boolean firstTime) { - PgpInlineDialog dialog = PgpInlineDialog.newInstance(firstTime, R.id.pgp_inline_indicator); + PgpInlineDialog dialog = PgpInlineDialog.newInstance(firstTime, R.id.crypto_special_mode); dialog.show(activity.getFragmentManager(), "openpgp_inline"); } public void showOpenPgpSignOnlyDialog(boolean firstTime) { - PgpSignOnlyDialog dialog = PgpSignOnlyDialog.newInstance(firstTime, R.id.crypto_status); + PgpSignOnlyDialog dialog = PgpSignOnlyDialog.newInstance(firstTime, R.id.crypto_special_mode); dialog.show(activity.getFragmentManager(), "openpgp_signonly"); } @@ -425,4 +437,17 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener this.childToDisplay = childToDisplay; } } + + public enum CryptoSpecialModeDisplayType { + NONE(VIEW_INDEX_HIDDEN), + PGP_INLINE(VIEW_INDEX_CRYPTO_SPECIAL_PGP_INLINE), + SIGN_ONLY(VIEW_INDEX_CRYPTO_SPECIAL_SIGN_ONLY); + + + final int childToDisplay; + + CryptoSpecialModeDisplayType(int childToDisplay) { + this.childToDisplay = childToDisplay; + } + } } 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 7a5281df7..4b9ad36ba 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 @@ -351,7 +351,7 @@ public class RecipientPresenter implements PermissionPingCallback { } recipientMvpView.showCryptoStatus(getCurrentCryptoStatus().getCryptoStatusDisplayType()); - recipientMvpView.showPgpInlineModeIndicator(getCurrentCryptoStatus().isPgpInlineModeEnabled()); + recipientMvpView.showCryptoSpecialMode(getCurrentCryptoStatus().getCryptoSpecialModeDisplayType()); } public ComposeCryptoStatus getCurrentCryptoStatus() { @@ -551,7 +551,7 @@ public class RecipientPresenter implements PermissionPingCallback { return; case OK: if (cachedCryptoStatus.isSignOnly()) { - recipientMvpView.showOpenPgpSignOnlyDialog(false); + recipientMvpView.showErrorIsSignOnly(); } else { recipientMvpView.showCryptoDialog(currentCryptoMode); } @@ -765,8 +765,15 @@ public class RecipientPresenter implements PermissionPingCallback { return false; } - public void onClickPgpInlineIndicator() { - recipientMvpView.showOpenPgpInlineDialog(false); + void onClickCryptoSpecialModeIndicator() { + ComposeCryptoStatus currentCryptoStatus = getCurrentCryptoStatus(); + if (currentCryptoStatus.isPgpInlineModeEnabled()) { + recipientMvpView.showOpenPgpInlineDialog(false); + } else if (currentCryptoStatus.isSignOnly()) { + recipientMvpView.showOpenPgpSignOnlyDialog(false); + } else { + throw new IllegalStateException("This icon should not be clickable while no special mode is active!"); + } } public enum CryptoProviderState { diff --git a/k9mail/src/main/res/layout/message_compose_recipients.xml b/k9mail/src/main/res/layout/message_compose_recipients.xml index 3c3122fcc..ea41ecb6e 100644 --- a/k9mail/src/main/res/layout/message_compose_recipients.xml +++ b/k9mail/src/main/res/layout/message_compose_recipients.xml @@ -47,17 +47,37 @@ style="@style/ComposeEditText" /> - + android:inAnimation="@anim/fade_in" + android:outAnimation="@anim/fade_out" + custom:previewInitialChild="0"> + + + + + + - - diff --git a/k9mail/src/main/res/values/strings.xml b/k9mail/src/main/res/values/strings.xml index 189cdd9fb..ed1df0b12 100644 --- a/k9mail/src/main/res/values/strings.xml +++ b/k9mail/src/main/res/values/strings.xml @@ -1229,5 +1229,6 @@ Please submit bug reports, contribute new features and ask questions at Special characters are currently not supported! Error parsing address! Support signing of unencrypted messages + Encryption unavailable in sign-only mode!