display sign-only as a special mode like pgp/inline
This commit is contained in:
parent
3d434786af
commit
b72a3ce8a0
5 changed files with 97 additions and 35 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -47,17 +47,37 @@
|
|||
style="@style/ComposeEditText"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
<com.fsck.k9.view.ToolableViewAnimator
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:id="@+id/pgp_inline_indicator"
|
||||
android:src="@drawable/compatibility"
|
||||
android:tint="@color/light_black"
|
||||
android:padding="8dp"
|
||||
android:id="@+id/crypto_special_mode"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
/>
|
||||
android:inAnimation="@anim/fade_in"
|
||||
android:outAnimation="@anim/fade_out"
|
||||
custom:previewInitialChild="0">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:src="@drawable/compatibility"
|
||||
android:tint="@color/light_black"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/status_signature_verified_cutout"
|
||||
android:tint="?attr/openpgp_blue"
|
||||
/>
|
||||
|
||||
</com.fsck.k9.view.ToolableViewAnimator>
|
||||
|
||||
|
||||
<com.fsck.k9.view.ToolableViewAnimator
|
||||
|
@ -205,14 +225,6 @@
|
|||
|
||||
</FrameLayout>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/status_signature_verified_cutout"
|
||||
android:tint="?attr/openpgp_blue"
|
||||
/>
|
||||
|
||||
</com.fsck.k9.view.ToolableViewAnimator>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -1229,5 +1229,6 @@ Please submit bug reports, contribute new features and ask questions at
|
|||
<string name="recipient_error_non_ascii">Special characters are currently not supported!</string>
|
||||
<string name="recipient_error_parse_failed">Error parsing address!</string>
|
||||
<string name="account_settings_crypto_support_sign_only">Support signing of unencrypted messages</string>
|
||||
<string name="error_sign_only_no_encryption">Encryption unavailable in sign-only mode!</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue