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

Commit 548b8e07 authored by Joe Steele's avatar Joe Steele
Browse files

Refactor code for MessageWebView.setText()

The MIME type for the supplied text was always text/html,
so there is no need to pass that as a parameter.
Furthermore, we are relying on it being text/html because
we are wrapping it with HTML code.

Likewise, change/simplify/rename AccessibleWebView.loadDataWithBaseURL().
parent 6a844a25
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1126,7 +1126,7 @@ public class MessageCompose extends K9Activity implements OnClickListener {
        mQuotedHtmlContent =
                (InsertableHtmlContent) savedInstanceState.getSerializable(STATE_KEY_HTML_QUOTE);
        if (mQuotedHtmlContent != null && mQuotedHtmlContent.getQuotedContent() != null) {
            mQuotedHTML.setText(mQuotedHtmlContent.getQuotedContent(), "text/html");
            mQuotedHTML.setText(mQuotedHtmlContent.getQuotedContent());
        }

        mDraftId = savedInstanceState.getLong(STATE_KEY_DRAFT_ID);
@@ -2815,7 +2815,7 @@ public class MessageCompose extends K9Activity implements OnClickListener {
                    } else {
                        mQuotedHtmlContent.setFooterInsertionPoint(bodyOffset);
                    }
                    mQuotedHTML.setText(mQuotedHtmlContent.getQuotedContent(), "text/html");
                    mQuotedHTML.setText(mQuotedHtmlContent.getQuotedContent());
                }
            }
            if (bodyPlainOffset != null && bodyPlainLength != null) {
@@ -2999,7 +2999,7 @@ public class MessageCompose extends K9Activity implements OnClickListener {
            mQuotedHtmlContent = quoteOriginalHtmlMessage(mSourceMessage, content, mQuoteStyle);

            // Load the message with the reply header.
            mQuotedHTML.setText(mQuotedHtmlContent.getQuotedContent(), "text/html");
            mQuotedHTML.setText(mQuotedHtmlContent.getQuotedContent());

            // TODO: Also strip the signature from the text/plain part
            mQuotedText.setText(quoteOriginalTextMessage(mSourceMessage,
+6 −2
Original line number Diff line number Diff line
@@ -133,7 +133,9 @@ public class HtmlConverter {
     * This method avoids using regular expressions on the entire message body to save memory.
     * </p>
     * <p>
     * No HTML headers or footers are added to the result.
     * No HTML headers or footers are added to the result.  Headers and footers
     * are added at display time in
     * {@link com.fsck.k9.view#MessageWebView.setText(String) MessageWebView.setText()}
     * </p>
     *
     * @param text
@@ -187,7 +189,9 @@ public class HtmlConverter {
     * Attempts to do smart replacement for large documents to prevent OOM
     * errors.
     * <p>
     * No HTML headers or footers are added to the result.
     * No HTML headers or footers are added to the result.  Headers and footers
     * are added at display time in
     * {@link com.fsck.k9.view#MessageWebView.setText(String) MessageWebView.setText()}
     * </p>
     * <p>
     * To convert to a fragment, use {@link #textToHtmlFragment(String)} .
+2 −4
Original line number Diff line number Diff line
@@ -68,10 +68,8 @@ public class AccessibleWebView extends TextView {
        return mDummyWebView.getSettings();
    }

    public void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding,
                                    String historyUrl) {
        mHtmlSource = data;
        this.setText(Html.fromHtml(mHtmlSource, null, null));
    public void setText(String text) {
        this.setText(Html.fromHtml(text, null, null));

        // Let everyone know that loading has finished.
        if (mListeners != null) {
+14 −2
Original line number Diff line number Diff line
@@ -151,7 +151,19 @@ public class MessageWebView extends TitleBarWebView {
        }
    }

    public void setText(String text, String contentType) {
    /**
     * Load a message body into a {@code MessageWebView}
     *
     * <p>
     * Before loading, the text is wrapped in an HTML header and footer
     * so that it displays properly.
     * </p>
     *
     * @param text
     *      The message body to display.  Assumed to be MIME type text/html.
     */
    public void setText(String text) {
     // 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)  {
            content += "<style type=\"text/css\">" +
@@ -160,7 +172,7 @@ public class MessageWebView extends TitleBarWebView {
                   ":visited, :visited * { color: #551A8B !important }</style> ";
        }
        content += "</head><body>" + text + "</body></html>";
        loadDataWithBaseURL("http://", content, contentType, "utf-8", null);
        loadDataWithBaseURL("http://", content, "text/html", "utf-8", null);
    }

    /*
+7 −7
Original line number Diff line number Diff line
@@ -400,7 +400,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
                // Allow network access first...
                setLoadPictures(true);
                // ...then re-populate the WebView with the message text
                loadBodyFromText(mText, "text/html");
                loadBodyFromText(mText);
                break;
            }
        }
@@ -611,7 +611,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
        }

        if (text != null) {
            loadBodyFromText(text, "text/html");
            loadBodyFromText(text);
            updateCryptoLayout(account.getCryptoProvider(), pgpData, message);
        } else {
            showStatusMessage(getContext().getString(R.string.webview_empty_message));
@@ -622,15 +622,15 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
        String text = "<html><body><div style=\"text-align:center; color: grey;\">" +
                status +
                "</div></body></html>";
        loadBodyFromText(text, "text/html");
        loadBodyFromText(text);
        mCryptoView.hide();
    }

    private void loadBodyFromText(String emailText, String contentType) {
    private void loadBodyFromText(String emailText) {
        if (mScreenReaderEnabled) {
            mAccessibleMessageContentView.loadDataWithBaseURL("http://", emailText, contentType, "utf-8", null);
            mAccessibleMessageContentView.setText(emailText);
        } else {
            mMessageContentView.setText(emailText, contentType);
            mMessageContentView.setText(emailText);
        }

    }
@@ -734,7 +734,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
         * its size because the button to download the complete message was previously shown and
         * is now hidden.
         */
        loadBodyFromText("", "text/plain");
        loadBodyFromText("");
    }

    public void resetHeaderView() {