Use setter for quoted text like signature

This commit is contained in:
Koji Arai 2014-05-02 09:43:14 +09:00
parent 71e766999c
commit 68850b1dc9
3 changed files with 47 additions and 11 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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));