1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Issue 854 - Fix reply after quote in HTML mode.

This commit is contained in:
Andrew Chen 2011-01-25 03:56:19 +00:00
parent e5b172b7bb
commit ba1709770e
2 changed files with 79 additions and 19 deletions

View File

@ -22,10 +22,15 @@ class InsertableHtmlContent implements Serializable
private StringBuilder quotedContent = new StringBuilder();
// User content (typically their reply or comments on a forward)
private StringBuilder userContent = new StringBuilder();
// Where to insert the content. Default to top posting.
private InsertionLocation insertionLocation = InsertionLocation.BEFORE_QUOTE;
public int getHeaderInsertionPoint()
/**
* Defines where user content should be inserted, either before or after quoted content.
*/
public enum InsertionLocation
{
return headerInsertionPoint;
BEFORE_QUOTE, AFTER_QUOTE
}
public void setHeaderInsertionPoint(int headerInsertionPoint)
@ -38,6 +43,10 @@ class InsertableHtmlContent implements Serializable
this.footerInsertionPoint = footerInsertionPoint;
}
/**
* Get the quoted content.
* @return Quoted content.
*/
public String getQuotedContent()
{
return quotedContent.toString();
@ -53,10 +62,13 @@ class InsertableHtmlContent implements Serializable
}
/**
* Insert something into the quoted content header. This is typically used for inserting
* <p>Insert something into the quoted content header. This is typically used for inserting
* reply/forward headers into the quoted content rather than inserting the user-generated reply
* content.
* @param content
* content.</p>
*
* <p>Subsequent calls to {@link #insertIntoQuotedHeader(String)} will <b>prepend</b> text onto any
* existing header and quoted content.</p>
* @param content Content to add.
*/
public void insertIntoQuotedHeader(final String content)
{
@ -66,13 +78,18 @@ class InsertableHtmlContent implements Serializable
}
/**
* Insert something into the quoted content footer. This is typically used for inserting closing
* tags of reply/forward headers rather than inserting the user-generated reply content.
* @param content
* <p>Insert something into the quoted content footer. This is typically used for inserting closing
* tags of reply/forward headers rather than inserting the user-generated reply content.</p>
*
* <p>Subsequent calls to {@link #insertIntoQuotedFooter(String)} will <b>append</b> text onto any
* existing footer and quoted content.</p>
* @param content Content to add.
*/
public void insertIntoQuotedFooter(final String content)
{
quotedContent.insert(footerInsertionPoint, content);
// Update the location of the footer insertion point to the end of the inserted content.
footerInsertionPoint += content.length();
}
/**
@ -95,6 +112,31 @@ class InsertableHtmlContent implements Serializable
userContent = new StringBuilder(content);
}
/**
* Configure where user content should be inserted, either before or after the quoted content.
* @param insertionLocation Where to insert user content.
*/
public void setInsertionLocation(final InsertionLocation insertionLocation)
{
this.insertionLocation = insertionLocation;
}
/**
* Fetch the insertion point based upon the quote style.
* @return Insertion point
*/
public int getInsertionPoint()
{
if (insertionLocation == InsertionLocation.BEFORE_QUOTE)
{
return headerInsertionPoint;
}
else
{
return footerInsertionPoint;
}
}
/**
* Build the composed string with the inserted and original content.
* @return Composed string.
@ -102,10 +144,11 @@ class InsertableHtmlContent implements Serializable
@Override
public String toString()
{
final int insertionPoint = getInsertionPoint();
// Inserting and deleting was twice as fast as instantiating a new StringBuilder and
// using substring() to build the new pieces.
String result = quotedContent.insert(headerInsertionPoint, userContent.toString()).toString();
quotedContent.delete(headerInsertionPoint, headerInsertionPoint + userContent.length());
String result = quotedContent.insert(insertionPoint, userContent.toString()).toString();
quotedContent.delete(insertionPoint, insertionPoint + userContent.length());
return result;
}
@ -118,6 +161,7 @@ class InsertableHtmlContent implements Serializable
return "InsertableHtmlContent{" +
"headerInsertionPoint=" + headerInsertionPoint +
", footerInsertionPoint=" + footerInsertionPoint +
", insertionLocation=" + insertionLocation +
", quotedContent=" + quotedContent +
", userContent=" + userContent +
", compiledResult=" + toString() +

View File

@ -859,7 +859,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mQuotedHtmlContent = (InsertableHtmlContent) savedInstanceState.getSerializable(STATE_KEY_HTML_QUOTE);
mQuotedTextBar.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
mQuotedHTML.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
if (mQuotedHtmlContent.getQuotedContent() != null)
if (mQuotedHtmlContent != null && mQuotedHtmlContent.getQuotedContent() != null)
{
mQuotedHTML.loadDataWithBaseURL("http://", mQuotedHtmlContent.getQuotedContent(), "text/html", "utf-8", null);
}
@ -967,19 +967,35 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mQuotedHtmlContent.clearQuotedContent();
}
// If we're building a message to be sent, add some extra separators between the
// composed message and the quoted message.
if (!isDraft)
{
text += "<br>";
}
mQuotedHtmlContent.setUserContent(text);
// Set the insertion location based upon our reply after quote setting. Reply after
// quote makes no sense for HEADER style replies. In addition, add some extra
// separators between the composed message and quoted message depending on the quote
// location. We only add the extra separators when we're sending, that way when we
// load a draft, we don't have to know the length of the separators to remove them
// before editing.
if (mAccount.getQuoteStyle() == QuoteStyle.PREFIX && replyAfterQuote)
{
mQuotedHtmlContent.setInsertionLocation(InsertableHtmlContent.InsertionLocation.AFTER_QUOTE);
if (!isDraft)
{
text = "<br><br>" + text;
}
}
else
{
mQuotedHtmlContent.setInsertionLocation(InsertableHtmlContent.InsertionLocation.BEFORE_QUOTE);
if (!isDraft)
{
text += "<br>";
}
}
// All done. Build the body.
TextBody body = new TextBody(mQuotedHtmlContent.toString());
// Save length of the body and its offset. This is used when thawing drafts.
body.setComposedMessageLength(text.length());
body.setComposedMessageOffset(mQuotedHtmlContent.getHeaderInsertionPoint());
body.setComposedMessageOffset(mQuotedHtmlContent.getInsertionPoint());
return body;
}
else