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

Commit 2c4f6981 authored by Vincent Breitmoser's avatar Vincent Breitmoser
Browse files

split up displayHtmlContentWithInlineAttachments into set, clear and refresh methods

parent c2bb16a7
Loading
Loading
Loading
Loading
+24 −12
Original line number Diff line number Diff line
@@ -73,9 +73,11 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
    private View mAttachmentsContainer;
    private SavedState mSavedState;
    private ClipboardManager mClipboardManager;
    private String mText;
    private Map<AttachmentViewInfo, AttachmentView> attachments = new HashMap<AttachmentViewInfo, AttachmentView>();

    private String currentHtmlText;
    private AttachmentResolver currentAttachmentResolver;


    @Override
    public void onFinishInflate() {
@@ -379,7 +381,7 @@ public class MessageContainerView extends LinearLayout implements OnClickListene

    public void showPictures() {
        setLoadPictures(true);
        displayHtmlContentWithInlineAttachments(mText, null);
        refreshDisplayedContent();
    }

    public void enableAttachmentButtons() {
@@ -424,9 +426,9 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
            mSavedState = null;
        }

        mText = getTextToDisplay(messageViewContainer);
        if (mText != null && lookForImages) {
            if (Utility.hasExternalImages(mText) && !isShowingPictures()) {
        String textToDisplay = getTextToDisplay(messageViewContainer);
        if (textToDisplay != null && lookForImages) {
            if (Utility.hasExternalImages(textToDisplay) && !isShowingPictures()) {
                if (automaticallyLoadPictures) {
                    setLoadPictures(true);
                } else {
@@ -447,14 +449,11 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
            mSidebar.setVisibility(View.GONE);
        }

        String text;
        if (mText != null) {
            text = mText;
        } else {
            text = wrapStatusMessage(getContext().getString(R.string.webview_empty_message));
        if (textToDisplay == null) {
            textToDisplay = wrapStatusMessage(getContext().getString(R.string.webview_empty_message));
        }

        displayHtmlContentWithInlineAttachments(text, messageViewContainer.attachmentResolver);
        displayHtmlContentWithInlineAttachments(textToDisplay, messageViewContainer.attachmentResolver);
    }

    private String getTextToDisplay(MessageViewContainer messageViewContainer) {
@@ -486,9 +485,19 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
    }

    private void displayHtmlContentWithInlineAttachments(String htmlText, AttachmentResolver attachmentResolver) {
        currentHtmlText = htmlText;
        currentAttachmentResolver = attachmentResolver;
        mMessageContentView.displayHtmlContentWithInlineAttachments(htmlText, attachmentResolver);
    }

    private void refreshDisplayedContent() {
        mMessageContentView.displayHtmlContentWithInlineAttachments(currentHtmlText, currentAttachmentResolver);
    }

    private void clearDisplayedContent() {
        mMessageContentView.displayHtmlContentWithInlineAttachments("", null);
    }

    public void renderAttachments(MessageViewContainer messageContainer) throws MessagingException {
        for (AttachmentViewInfo attachment : messageContainer.attachments) {
            ViewGroup parent = attachment.firstClassAttachment ? mAttachments : mHiddenAttachments;
@@ -518,6 +527,9 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
        mAttachments.removeAllViews();
        mHiddenAttachments.removeAllViews();

        currentHtmlText = null;
        currentAttachmentResolver = null;

        /*
         * Clear the WebView content
         *
@@ -525,7 +537,7 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
         * its size because the button to download the complete message was previously shown and
         * is now hidden.
         */
        displayHtmlContentWithInlineAttachments("", null);
        clearDisplayedContent();
    }

    @Override
+8 −2
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.provider.Browser;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebResourceRequest;
@@ -32,10 +33,11 @@ abstract class K9WebViewClient extends WebViewClient {
    private static final WebResourceResponse RESULT_DUMMY_RESPONSE = new WebResourceResponse(null, null, null);


    @Nullable
    private final AttachmentResolver attachmentResolver;


    public static K9WebViewClient newInstance(AttachmentResolver attachmentResolver) {
    public static K9WebViewClient newInstance(@Nullable AttachmentResolver attachmentResolver) {
        if (Build.VERSION.SDK_INT < 21) {
            return new PreLollipopWebViewClient(attachmentResolver);
        }
@@ -44,7 +46,7 @@ abstract class K9WebViewClient extends WebViewClient {
    }


    private K9WebViewClient(AttachmentResolver attachmentResolver) {
    private K9WebViewClient(@Nullable AttachmentResolver attachmentResolver) {
        this.attachmentResolver = attachmentResolver;
    }

@@ -85,6 +87,10 @@ abstract class K9WebViewClient extends WebViewClient {
            return RESULT_DO_NOT_INTERCEPT;
        }

        if (attachmentResolver == null) {
            return RESULT_DUMMY_RESPONSE;
        }

        String cid = uri.getSchemeSpecificPart();
        if (TextUtils.isEmpty(cid)) {
            return RESULT_DUMMY_RESPONSE;
+6 −3
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@ package com.fsck.k9.view;

import android.content.Context;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
@@ -104,17 +106,18 @@ public class MessageWebView extends RigidWebView {
        getSettings().setDisplayZoomControls(!supportsMultiTouch);
    }

    public void displayHtmlContentWithInlineAttachments(String htmlText, AttachmentResolver attachmentResolver) {
    public void displayHtmlContentWithInlineAttachments(@NonNull String htmlText,
            @Nullable AttachmentResolver attachmentResolver) {
        setAttachmentResolverWebViewClient(attachmentResolver);
        setHtmlContent(htmlText);
    }

    private void setAttachmentResolverWebViewClient(AttachmentResolver attachmentResolver) {
    private void setAttachmentResolverWebViewClient(@Nullable AttachmentResolver attachmentResolver) {
        K9WebViewClient webViewClient = K9WebViewClient.newInstance(attachmentResolver);
        setWebViewClient(webViewClient);
    }

    private void setHtmlContent(String htmlText) {
    private void setHtmlContent(@NonNull String htmlText) {
        // Include a meta tag so the WebView will not use a fixed viewport width of 980 px
        String content = "<html><head><meta name=\"viewport\" content=\"width=device-width\"/>";
        if (K9.getK9MessageViewTheme() == K9.Theme.DARK)  {