From 68850b1dc94ddcd94d499d3b98e3d7237dae7096 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 09:43:14 +0900 Subject: [PATCH] Use setter for quoted text like signature --- src/com/fsck/k9/activity/MessageCompose.java | 12 +++++-- .../k9/mail/internet/TextBodyBuilder.java | 33 ++++++++++++++++--- .../k9/mail/internet/TextBodyBuilderTest.java | 13 +++++--- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index b804710ce..9e8e4bdb5 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -1382,13 +1382,19 @@ public class MessageCompose extends K9Activity implements OnClickListener, textBodyBuilder.setAppendSignature(false); } - TextBody body; if (messageFormat == SimpleMessageFormat.HTML) { - body = textBodyBuilder.buildTextHtml(mQuotedHtmlContent); + if (mQuotedHtmlContent == null) { + textBodyBuilder.setIncludeQuotedText(false); + } + else { + textBodyBuilder.setQuotedTextHtml(mQuotedHtmlContent); + } + body = textBodyBuilder.buildTextHtml(); } else { - body = textBodyBuilder.buildTextPlain(mQuotedText.getText().toString()); + textBodyBuilder.setQuotedText(mQuotedText.getText().toString()); + body = textBodyBuilder.buildTextPlain(); } return body; } diff --git a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java index dd3a3c90e..38d71fcdf 100644 --- a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java +++ b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java @@ -19,6 +19,8 @@ public class TextBodyBuilder { // message parts private String mMessageContent; private String mSignature; + private String mQuotedText; + private InsertableHtmlContent mQuotedTextHtml; public TextBodyBuilder(String messageContent) { mMessageContent = messageContent; @@ -36,7 +38,7 @@ public class TextBodyBuilder { * @return {@link TextBody} instance that contains the entered text and * possibly the quoted original message. */ - public TextBody buildTextHtml(InsertableHtmlContent quotedHtmlContent) { + public TextBody buildTextHtml() { // The length of the formatted version of the user-supplied text/reply int composedMessageLength; @@ -47,7 +49,9 @@ public class TextBodyBuilder { String text = mMessageContent; // Do we have to modify an existing message to include our reply? - if (mIncludeQuotedText && quotedHtmlContent != null) { + if (mIncludeQuotedText) { + InsertableHtmlContent quotedHtmlContent = getQuotedTextHtml(); + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "insertable: " + quotedHtmlContent.toDebugString()); } @@ -134,7 +138,7 @@ public class TextBodyBuilder { * @return {@link TextBody} instance that contains the entered text and * possibly the quoted original message. */ - public TextBody buildTextPlain(String quotedText) { + public TextBody buildTextPlain() { // The length of the formatted version of the user-supplied text/reply int composedMessageLength; @@ -149,7 +153,8 @@ public class TextBodyBuilder { composedMessageOffset = 0; // Do we have to modify an existing message to include our reply? - if (mIncludeQuotedText && !StringUtils.isNullOrEmpty(quotedText)) { + if (mIncludeQuotedText) { + String quotedText = getQuotedText(); if (mAppendSignature) { // Append signature to the text/reply @@ -209,6 +214,18 @@ public class TextBodyBuilder { return signature; } + private String getQuotedText() { + String quotedText = ""; + if (!StringUtils.isNullOrEmpty(mQuotedText)) { + quotedText = mQuotedText; + } + return quotedText; + } + + private InsertableHtmlContent getQuotedTextHtml() { + return mQuotedTextHtml; + } + public String textToHtmlFragment(String text) { return HtmlConverter.textToHtmlFragment(text); } @@ -223,6 +240,14 @@ public class TextBodyBuilder { mIncludeQuotedText = includeQuotedText; } + public void setQuotedText(String quotedText) { + mQuotedText = quotedText; + } + + public void setQuotedTextHtml(InsertableHtmlContent quotedTextHtml) { + mQuotedTextHtml = quotedTextHtml; + } + public void setInsertSeparator(boolean insertSeparator) { mInsertSeparator = insertSeparator; } diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java index a813580ba..a3daafae4 100644 --- a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java @@ -136,7 +136,7 @@ public class TextBodyBuilderTest { String messageContent = "message content"; String signature = "signature"; - TextBody textBody = new TestingTextBodyBuilder( + TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder( includeQuotedText, isDraft, quoteStyle, @@ -145,7 +145,9 @@ public class TextBodyBuilderTest { isSignatureUse, messageContent, signature - ).buildTextPlain(quotedText); + ); + textBodyBuilder.setQuotedText(quotedText); + TextBody textBody = textBodyBuilder.buildTextPlain(); assertThat(textBody, instanceOf(TextBody.class)); assertThat(textBody.getText(), is(expectedText)); @@ -314,7 +316,8 @@ public class TextBodyBuilderTest { insertableHtmlContent.setQuotedContent(new StringBuilder(quotedText)); String messageContent = "message content"; String signature = "signature"; - TextBody textBody = new TestingTextBodyBuilder( + + TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder( includeQuotedText, isDraft, quoteStyle, @@ -323,7 +326,9 @@ public class TextBodyBuilderTest { isSignatureUse, messageContent, signature - ).buildTextHtml(insertableHtmlContent); + ); + textBodyBuilder.setQuotedTextHtml(insertableHtmlContent); + TextBody textBody = textBodyBuilder.buildTextHtml(); assertThat(textBody, instanceOf(TextBody.class)); assertThat(textBody.getText(), is(expectedText));