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

Commit 0a43b36a authored by Vincent Breitmoser's avatar Vincent Breitmoser
Browse files

compose: use attachment info from loaded AttachmentViewInfo

parent 62361da1
Loading
Loading
Loading
Loading
+7 −13
Original line number Diff line number Diff line
@@ -133,7 +133,6 @@ public class MessageCompose extends K9Activity implements OnClickListener,

    private static final int MSG_PROGRESS_ON = 1;
    private static final int MSG_PROGRESS_OFF = 2;
    private static final int MSG_SKIPPED_ATTACHMENTS = 3;
    public static final int MSG_SAVED_DRAFT = 4;
    private static final int MSG_DISCARDED_DRAFT = 5;

@@ -278,12 +277,6 @@ public class MessageCompose extends K9Activity implements OnClickListener,
                case MSG_PROGRESS_OFF:
                    setProgressBarIndeterminateVisibility(false);
                    break;
                case MSG_SKIPPED_ATTACHMENTS:
                    Toast.makeText(
                        MessageCompose.this,
                        getString(R.string.message_compose_attachments_skipped_toast),
                        Toast.LENGTH_LONG).show();
                    break;
                case MSG_SAVED_DRAFT:
                    mDraftId = (Long) msg.obj;
                    Toast.makeText(
@@ -1260,12 +1253,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,

        // Quote the message and setup the UI.
        quotedMessagePresenter.processMessageToForward(messageViewInfo);

        if (!mSourceMessageProcessed) {
            if (message.isSet(Flag.X_DOWNLOADED_PARTIAL) || !attachmentPresenter.loadAttachments(message, 0)) {
                mHandler.sendEmptyMessage(MSG_SKIPPED_ATTACHMENTS);
            }
        }
        attachmentPresenter.processMessageToForward(messageViewInfo);
    }

    private void processDraftMessage(MessageViewInfo messageViewInfo) throws MessagingException {
@@ -1738,6 +1726,12 @@ public class MessageCompose extends K9Activity implements OnClickListener,
        public void performSaveAfterChecks() {
            MessageCompose.this.performSaveAfterChecks();
        }

        @Override
        public void showMissingAttachmentsPartialMessageWarning() {
            Toast.makeText(MessageCompose.this,
                    getString(R.string.message_compose_attachments_skipped_toast), Toast.LENGTH_LONG).show();
        }
    };

}
+52 −5
Original line number Diff line number Diff line
@@ -21,11 +21,14 @@ import com.fsck.k9.activity.loader.AttachmentContentLoader;
import com.fsck.k9.activity.loader.AttachmentInfoLoader;
import com.fsck.k9.activity.misc.Attachment;
import com.fsck.k9.activity.misc.Attachment.LoadingState;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Multipart;
import com.fsck.k9.mail.Part;
import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mailstore.AttachmentViewInfo;
import com.fsck.k9.mailstore.LocalBodyPart;
import com.fsck.k9.mailstore.MessageViewInfo;
import com.fsck.k9.provider.AttachmentProvider;


@@ -130,31 +133,74 @@ public class AttachmentPresenter {
        addAttachment(uri, null);
    }

    public void addAttachment(AttachmentViewInfo attachmentViewInfo) {
        if (attachments.containsKey(attachmentViewInfo.uri)) {
            throw new IllegalStateException("Received the same attachmentViewInfo twice!");
        }

        int loaderId = getNextFreeLoaderId();
        Attachment attachment = Attachment.createAttachment(
                attachmentViewInfo.uri, loaderId, attachmentViewInfo.mimeType);
        attachment = attachment.deriveWithMetadataLoaded(
                attachmentViewInfo.mimeType, attachmentViewInfo.displayName, attachmentViewInfo.size);

        addAttachmentAndStartLoader(attachment);
    }

    public void addAttachment(Uri uri, String contentType) {
        if (attachments.containsKey(uri)) {
            return;
        }

        int loaderId = getNextFreeLoaderId();
        Attachment attachment = Attachment.createAttachment(uri, loaderId, contentType);

        if (attachments.containsKey(uri)) {
        addAttachmentAndStartLoader(attachment);
    }

    public void processMessageToForward(MessageViewInfo messageViewInfo) {
        if (messageViewInfo.message.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
            attachmentMvpView.showMissingAttachmentsPartialMessageWarning();
            return;
        }

        attachments.put(uri, attachment);
        for (AttachmentViewInfo attachmentViewInfo : messageViewInfo.attachments) {
            if (attachmentViewInfo.firstClassAttachment) {
                addAttachment(attachmentViewInfo);
            }
        }
    }

    private void addAttachmentAndStartLoader(Attachment attachment) {
        attachments.put(attachment.uri, attachment);
        attachmentMvpView.addAttachmentView(attachment);

        if (attachment.state == LoadingState.URI_ONLY) {
            initAttachmentInfoLoader(attachment);
        } else if (attachment.state == LoadingState.METADATA) {
            initAttachmentContentLoader(attachment);
        } else {
            throw new IllegalStateException("Attachment can only be added in URI_ONLY or METADATA state!");
        }
    }

    private void initAttachmentInfoLoader(Attachment attachment) {
        if (attachment.state != LoadingState.URI_ONLY) {
            throw new IllegalStateException("initAttachmentInfoLoader can only be called for URI_ONLY state!");
        }

        Bundle bundle = new Bundle();
        bundle.putParcelable(LOADER_ARG_ATTACHMENT, attachment.uri);

        loaderManager.initLoader(attachment.loaderId, bundle, mAttachmentInfoLoaderCallback);
    }

    private void initAttachmentContentLoader(Attachment attachment) {
        if (attachment.state != LoadingState.METADATA) {
            throw new IllegalStateException("initAttachmentContentLoader can only be called for METADATA state!");
        }

        Bundle bundle = new Bundle();
        bundle.putParcelable(LOADER_ARG_ATTACHMENT, attachment.uri);

        loaderManager.initLoader(attachment.loaderId, bundle, mAttachmentContentLoaderCallback);
    }

@@ -364,5 +410,6 @@ public class AttachmentPresenter {
        void performSendAfterChecks();
        void performSaveAfterChecks();

        void showMissingAttachmentsPartialMessageWarning();
    }
}
+2 −3
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import com.fsck.k9.mail.Part;
import com.fsck.k9.mail.internet.MessageExtractor;
import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mailstore.AttachmentResolver;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.MessageViewInfo;
import com.fsck.k9.message.IdentityField;
import com.fsck.k9.message.InsertableHtmlContent;
@@ -134,7 +133,7 @@ public class QuotedMessagePresenter {

            // Load the message with the reply header. TODO replace with MessageViewInfo data
            view.setQuotedHtml(quotedHtmlContent.getQuotedContent(),
                    AttachmentResolver.createFromPart(sourceMessage));
                    AttachmentResolver.createFromPart(messageViewInfo.rootPart));

            // TODO: Also strip the signature from the text/plain part
            view.setQuotedText(QuotedMessageHelper.quoteOriginalTextMessage(resources, messageViewInfo.message,
@@ -299,7 +298,7 @@ public class QuotedMessagePresenter {
                    }
                    // TODO replace with MessageViewInfo data
                    view.setQuotedHtml(quotedHtmlContent.getQuotedContent(),
                            AttachmentResolver.createFromPart(message));
                            AttachmentResolver.createFromPart(messageViewInfo.rootPart));
                }
            }
            if (bodyPlainOffset != null && bodyPlainLength != null) {