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

Commit 5b6d74e8 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #2608 from k9mail/autocrypt-compose

Autocrypt Compose
parents 66b5154b 99a17257
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 49.999997 99.999998" height="100" width="50" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
 <metadata>
  <rdf:RDF>
   <cc:Work rdf:about="">
    <dc:format>image/svg+xml</dc:format>
    <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
    <dc:title/>
   </cc:Work>
  </rdf:RDF>
 </metadata>
 <path d="m0 0h50v50z" fill-rule="evenodd" stroke="#000" stroke-width="1px"/>
</svg>
+4 −0
Original line number Diff line number Diff line
@@ -247,6 +247,10 @@
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
            </intent-filter>
            <intent-filter>
                <action android:name="org.autocrypt.PEER_ACTION"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

        <!-- Search Activity - searchable -->
+31 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ public class AlternateRecipientAdapter extends BaseAdapter {
    private final AlternateRecipientListener listener;
    private List<Recipient> recipients;
    private Recipient currentRecipient;
    private boolean showAdvancedInfo;


    public AlternateRecipientAdapter(Context context, AlternateRecipientListener listener) {
@@ -167,6 +168,14 @@ public class AlternateRecipientAdapter extends BaseAdapter {
    }

    private void configureCryptoStatusView(RecipientTokenHolder holder, Recipient recipient) {
        if (showAdvancedInfo) {
            configureCryptoStatusViewAdvanced(holder, recipient);
        } else {
            bindCryptoSimple(holder, recipient);
        }
    }

    private void configureCryptoStatusViewAdvanced(RecipientTokenHolder holder, Recipient recipient) {
        switch (recipient.getCryptoStatus()) {
            case AVAILABLE_TRUSTED: {
                setCryptoStatusView(holder, R.drawable.status_lock_dots_3, R.attr.openpgp_green);
@@ -202,6 +211,25 @@ public class AlternateRecipientAdapter extends BaseAdapter {
        holder.itemCryptoStatus.setVisibility(View.VISIBLE);
    }

    private void bindCryptoSimple(RecipientTokenHolder holder, Recipient recipient) {
        holder.itemCryptoStatus.setVisibility(View.GONE);
        switch (recipient.getCryptoStatus()) {
            case AVAILABLE_TRUSTED:
            case AVAILABLE_UNTRUSTED: {
                holder.itemCryptoStatusSimple.setVisibility(View.VISIBLE);
                break;
            }
            case UNAVAILABLE:
            case UNDEFINED: {
                holder.itemCryptoStatusSimple.setVisibility(View.GONE);
                break;
            }
        }
    }

    public void setShowAdvancedInfo(boolean showAdvancedInfo) {
        this.showAdvancedInfo = showAdvancedInfo;
    }

    private static class RecipientTokenHolder {
        public final View layoutHeader, layoutItem;
@@ -213,6 +241,7 @@ public class AlternateRecipientAdapter extends BaseAdapter {
        public final TextView itemAddressLabel;
        public final View itemCryptoStatus;
        public final ImageView itemCryptoStatusIcon;
        public final ImageView itemCryptoStatusSimple;


        public RecipientTokenHolder(View view) {
@@ -228,6 +257,8 @@ public class AlternateRecipientAdapter extends BaseAdapter {
            itemAddressLabel = (TextView) view.findViewById(R.id.alternate_address_label);
            itemCryptoStatus = view.findViewById(R.id.alternate_crypto_status);
            itemCryptoStatusIcon = (ImageView) view.findViewById(R.id.alternate_crypto_status_icon);

            itemCryptoStatusSimple = (ImageView) view.findViewById(R.id.alternate_crypto_status_simple);
        }

        public void setShowAsHeader(boolean isHeader) {
+44 −23
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.text.TextUtils;
import android.text.TextWatcher;
import timber.log.Timber;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
@@ -56,24 +55,22 @@ import com.fsck.k9.activity.compose.AttachmentPresenter.AttachmentMvpView;
import com.fsck.k9.activity.compose.AttachmentPresenter.WaitingAction;
import com.fsck.k9.activity.compose.ComposeCryptoStatus;
import com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState;
import com.fsck.k9.activity.compose.CryptoSettingsDialog.OnCryptoModeChangedListener;
import com.fsck.k9.activity.compose.IdentityAdapter;
import com.fsck.k9.activity.compose.IdentityAdapter.IdentityContainer;
import com.fsck.k9.activity.compose.PgpEnabledErrorDialog.OnOpenPgpDisableListener;
import com.fsck.k9.activity.compose.PgpInlineDialog.OnOpenPgpInlineChangeListener;
import com.fsck.k9.activity.compose.PgpSignOnlyDialog.OnOpenPgpSignOnlyChangeListener;
import com.fsck.k9.activity.compose.RecipientMvpView;
import com.fsck.k9.activity.compose.RecipientPresenter;
import com.fsck.k9.activity.compose.RecipientPresenter.CryptoMode;
import com.fsck.k9.activity.compose.SaveMessageTask;
import com.fsck.k9.activity.misc.Attachment;
import com.fsck.k9.controller.MessagingController;
import com.fsck.k9.controller.MessagingListener;
import com.fsck.k9.controller.SimpleMessagingListener;
import com.fsck.k9.fragment.AttachmentDownloadDialogFragment;
import com.fsck.k9.fragment.AttachmentDownloadDialogFragment.AttachmentDownloadCancelListener;
import com.fsck.k9.fragment.ProgressDialogFragment;
import com.fsck.k9.fragment.ProgressDialogFragment.CancelListener;
import com.fsck.k9.fragment.AttachmentDownloadDialogFragment;
import com.fsck.k9.fragment.AttachmentDownloadDialogFragment.AttachmentDownloadCancelListener;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.helper.IdentityHelper;
import com.fsck.k9.helper.MailTo;
@@ -88,6 +85,8 @@ import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.internet.MimeMessage;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.MessageViewInfo;
import com.fsck.k9.message.AutocryptStatusInteractor;
import com.fsck.k9.message.ComposePgpEnableByDefaultDecider;
import com.fsck.k9.message.ComposePgpInlineDecider;
import com.fsck.k9.message.IdentityField;
import com.fsck.k9.message.IdentityHeaderParser;
@@ -100,13 +99,16 @@ import com.fsck.k9.search.LocalSearch;
import com.fsck.k9.ui.EolConvertingEditText;
import com.fsck.k9.ui.compose.QuotedMessageMvpView;
import com.fsck.k9.ui.compose.QuotedMessagePresenter;
import org.openintents.openpgp.util.OpenPgpApi;
import timber.log.Timber;


@SuppressWarnings("deprecation") // TODO get rid of activity dialogs and indeterminate progress bars
public class MessageCompose extends K9Activity implements OnClickListener,
        CancelListener, AttachmentDownloadCancelListener, OnFocusChangeListener, OnCryptoModeChangedListener,
        CancelListener, AttachmentDownloadCancelListener, OnFocusChangeListener,
        OnOpenPgpInlineChangeListener, OnOpenPgpSignOnlyChangeListener, MessageBuilder.Callback,
        AttachmentPresenter.AttachmentsChangedListener, RecipientPresenter.RecipientsChangedListener {
        AttachmentPresenter.AttachmentsChangedListener, RecipientPresenter.RecipientsChangedListener,
        OnOpenPgpDisableListener {

    private static final int DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE = 1;
    private static final int DIALOG_CONFIRM_DISCARD_ON_BACK = 2;
@@ -120,6 +122,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
    public static final String ACTION_REPLY_ALL = "com.fsck.k9.intent.action.REPLY_ALL";
    public static final String ACTION_FORWARD = "com.fsck.k9.intent.action.FORWARD";
    public static final String ACTION_EDIT_DRAFT = "com.fsck.k9.intent.action.EDIT_DRAFT";
    private static final String ACTION_AUTOCRYPT_PEER = "org.autocrypt.PEER_ACTION";

    public static final String EXTRA_ACCOUNT = "account";
    public static final String EXTRA_MESSAGE_REFERENCE = "message_reference";
@@ -277,9 +280,11 @@ public class MessageCompose extends K9Activity implements OnClickListener,

        RecipientMvpView recipientMvpView = new RecipientMvpView(this);
        ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider();
        recipientPresenter = new RecipientPresenter(getApplicationContext(), getLoaderManager(), recipientMvpView,
                account, composePgpInlineDecider, new ReplyToParser(), this);
        recipientPresenter.updateCryptoStatus();
        ComposePgpEnableByDefaultDecider composePgpEnableByDefaultDecider = new ComposePgpEnableByDefaultDecider();
        recipientPresenter = new RecipientPresenter(getApplicationContext(), getLoaderManager(),
                recipientMvpView, account, composePgpInlineDecider, composePgpEnableByDefaultDecider,
                AutocryptStatusInteractor.getInstance(), new ReplyToParser(), this);
        recipientPresenter.asyncUpdateCryptoStatus();


        subjectView = (EditText) findViewById(R.id.subject);
@@ -534,7 +539,14 @@ public class MessageCompose extends K9Activity implements OnClickListener,
            }

            recipientPresenter.initFromSendOrViewIntent(intent);
        }

        if (ACTION_AUTOCRYPT_PEER.equals(action)) {
            String trustId = intent.getStringExtra(OpenPgpApi.EXTRA_AUTOCRYPT_PEER_ID);
            if (trustId != null) {
                recipientPresenter.initFromTrustIdAction(trustId);
                startedByExternalIntent = true;
            }
        }

        return startedByExternalIntent;
@@ -630,8 +642,11 @@ public class MessageCompose extends K9Activity implements OnClickListener,
    private MessageBuilder createMessageBuilder(boolean isDraft) {
        MessageBuilder builder;

        recipientPresenter.updateCryptoStatus();
        ComposeCryptoStatus cryptoStatus = recipientPresenter.getCurrentCryptoStatus();
        ComposeCryptoStatus cryptoStatus = recipientPresenter.getCurrentCachedCryptoStatus();
        if (cryptoStatus == null) {
            return null;
        }

        // TODO encrypt drafts for storage
        if (!isDraft && cryptoStatus.shouldUsePgpMessageBuilder()) {
            SendErrorState maybeSendErrorState = cryptoStatus.getSendErrorStateOrNull();
@@ -641,18 +656,16 @@ public class MessageCompose extends K9Activity implements OnClickListener,
            }

            PgpMessageBuilder pgpBuilder = PgpMessageBuilder.newInstance();
            recipientPresenter.builderSetProperties(pgpBuilder);
            recipientPresenter.builderSetProperties(pgpBuilder, cryptoStatus);
            builder = pgpBuilder;
        } else {
            builder = SimpleMessageBuilder.newInstance();
            recipientPresenter.builderSetProperties(builder);
        }

        builder.setSubject(Utility.stripNewLines(subjectView.getText().toString()))
                .setSentDate(new Date())
                .setHideTimeZone(K9.hideTimeZone())
                .setTo(recipientPresenter.getToAddresses())
                .setCc(recipientPresenter.getCcAddresses())
                .setBcc(recipientPresenter.getBccAddresses())
                .setInReplyTo(repliedToMessageId)
                .setReferences(referencedMessageIds)
                .setRequestReadReceipt(requestReadReceipt)
@@ -884,11 +897,6 @@ public class MessageCompose extends K9Activity implements OnClickListener,
        }
    }

    @Override
    public void onCryptoModeChanged(CryptoMode cryptoMode) {
        recipientPresenter.onCryptoModeChanged(cryptoMode);
    }

    @Override
    public void onOpenPgpInlineChange(boolean enabled) {
        recipientPresenter.onCryptoPgpInlineChanged(enabled);
@@ -898,6 +906,12 @@ public class MessageCompose extends K9Activity implements OnClickListener,
    public void onOpenPgpSignOnlyChange(boolean enabled) {
        recipientPresenter.onCryptoPgpSignOnlyDisabled();
    }

    @Override
    public void onOpenPgpClickDisable() {
        recipientPresenter.onCryptoPgpClickDisable();
    }

    @Override
    public void onAttachmentAdded() {
        changesMadeSinceLastSave = true;
@@ -948,6 +962,14 @@ public class MessageCompose extends K9Activity implements OnClickListener,
            case R.id.add_from_contacts:
                recipientPresenter.onMenuAddFromContacts();
                break;
            case R.id.openpgp_encrypt_disable:
                recipientPresenter.onMenuSetEnableEncryption(false);
                updateMessageFormat();
                break;
            case R.id.openpgp_encrypt_enable:
                recipientPresenter.onMenuSetEnableEncryption(true);
                updateMessageFormat();
                break;
            case R.id.openpgp_inline_enable:
                recipientPresenter.onMenuSetPgpInline(true);
                updateMessageFormat();
@@ -1485,8 +1507,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
                message.setUid(relatedMessageReference.getUid());
            }

            // TODO more appropriate logic here? not sure
            boolean saveRemotely = !recipientPresenter.getCurrentCryptoStatus().shouldUsePgpMessageBuilder();
            boolean saveRemotely = recipientPresenter.shouldSaveRemotely();
            new SaveMessageTask(getApplicationContext(), account, contacts, internalMessageHandler,
                    message, draftId, saveRemotely).execute();
            if (finishAfterDraftSaved) {
+6 −2
Original line number Diff line number Diff line
@@ -116,8 +116,12 @@ public class AttachmentPresenter {
    }

    public void onClickAddAttachment(RecipientPresenter recipientPresenter) {
        AttachErrorState maybeAttachErrorState =
                recipientPresenter.getCurrentCryptoStatus().getAttachErrorStateOrNull();
        ComposeCryptoStatus currentCachedCryptoStatus = recipientPresenter.getCurrentCachedCryptoStatus();
        if (currentCachedCryptoStatus == null) {
            return;
        }

        AttachErrorState maybeAttachErrorState = currentCachedCryptoStatus.getAttachErrorStateOrNull();
        if (maybeAttachErrorState != null) {
            recipientPresenter.showPgpAttachError(maybeAttachErrorState);
            return;
Loading