possible to toggle to display the quoted message to send.

This commit is contained in:
Koji Arai 2011-05-11 00:54:17 +09:00
parent e6d4299c23
commit 5d6df85aac
2 changed files with 160 additions and 127 deletions

View File

@ -237,6 +237,16 @@
android:textColor="@android:color/primary_text_light"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageButton
android:id="@+id/quoted_text_show"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:visibility="gone"
android:background="@drawable/btn_dialog" />
<!-- Quoted text bar -->
<RelativeLayout
android:id="@+id/quoted_text_bar"

View File

@ -1,6 +1,6 @@
package com.fsck.k9.activity;
import java.io.File;
import java.io.Serializable;
import java.util.*;
@ -89,8 +89,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
"com.fsck.k9.activity.MessageCompose.ccShown";
private static final String STATE_KEY_BCC_SHOWN =
"com.fsck.k9.activity.MessageCompose.bccShown";
private static final String STATE_KEY_QUOTED_TEXT_SHOWN =
"com.fsck.k9.activity.MessageCompose.quotedTextShown";
private static final String STATE_KEY_QUOTED_TEXT_MODE =
"com.fsck.k9.activity.MessageCompose.QuotedTextShown";
private static final String STATE_KEY_SOURCE_MESSAGE_PROCED =
"com.fsck.k9.activity.MessageCompose.stateKeySourceMessageProced";
private static final String STATE_KEY_DRAFT_UID =
@ -161,6 +161,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
*/
private boolean mSourceMessageProcessed = false;
private enum QuotedTextMode {
NONE,
SHOW,
HIDE
};
private QuotedTextMode mQuotedTextMode = QuotedTextMode.NONE;
private TextView mFromView;
private LinearLayout mCcWrapper;
@ -172,6 +179,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
private EditText mSignatureView;
private EditText mMessageContentView;
private LinearLayout mAttachments;
private ImageButton mQuotedTextShow;
private View mQuotedTextBar;
private ImageButton mQuotedTextEdit;
private ImageButton mQuotedTextDelete;
@ -391,6 +399,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mMessageContentView = (EditText)findViewById(R.id.message_content);
mMessageContentView.getInputExtras(true).putBoolean("allowEmoji", true);
mAttachments = (LinearLayout)findViewById(R.id.attachments);
mQuotedTextShow = (ImageButton)findViewById(R.id.quoted_text_show);
mQuotedTextBar = findViewById(R.id.quoted_text_bar);
mQuotedTextEdit = (ImageButton)findViewById(R.id.quoted_text_edit);
mQuotedTextDelete = (ImageButton)findViewById(R.id.quoted_text_delete);
@ -467,11 +476,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* We set this to invisible by default. Other methods will turn it back on if it's
* needed.
*/
mQuotedTextBar.setVisibility(View.GONE);
mQuotedText.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.GONE);
mQuotedTextEdit.setVisibility(View.GONE);
showOrHideQuotedText(QuotedTextMode.NONE);
mQuotedTextShow.setOnClickListener(this);
mQuotedTextEdit.setOnClickListener(this);
mQuotedTextDelete.setOnClickListener(this);
@ -801,7 +809,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
outState.putParcelableArrayList(STATE_KEY_ATTACHMENTS, attachments);
outState.putBoolean(STATE_KEY_CC_SHOWN, mCcView.getVisibility() == View.VISIBLE);
outState.putBoolean(STATE_KEY_BCC_SHOWN, mBccView.getVisibility() == View.VISIBLE);
outState.putBoolean(STATE_KEY_QUOTED_TEXT_SHOWN, mQuotedTextBar.getVisibility() == View.VISIBLE);
outState.putSerializable(STATE_KEY_QUOTED_TEXT_MODE, mQuotedTextMode);
outState.putBoolean(STATE_KEY_SOURCE_MESSAGE_PROCED, mSourceMessageProcessed);
outState.putString(STATE_KEY_DRAFT_UID, mDraftUid);
outState.putSerializable(STATE_IDENTITY, mIdentity);
@ -829,17 +837,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
: View.GONE);
mBccWrapper.setVisibility(savedInstanceState
.getBoolean(STATE_KEY_BCC_SHOWN) ? View.VISIBLE : View.GONE);
if (mMessageFormat == MessageFormat.HTML) {
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 != null && mQuotedHtmlContent.getQuotedContent() != null) {
mQuotedHTML.loadDataWithBaseURL("http://", mQuotedHtmlContent.getQuotedContent(), "text/html", "utf-8", null);
mQuotedTextEdit.setVisibility(View.VISIBLE);
showOrHideQuotedText((QuotedTextMode)savedInstanceState.getSerializable(STATE_KEY_QUOTED_TEXT_MODE));
if (mQuotedTextMode != QuotedTextMode.NONE) {
if (mMessageFormat == MessageFormat.HTML) {
mQuotedHtmlContent = (InsertableHtmlContent) savedInstanceState.getSerializable(STATE_KEY_HTML_QUOTE);
if (mQuotedHtmlContent != null && mQuotedHtmlContent.getQuotedContent() != null) {
mQuotedHTML.loadDataWithBaseURL("http://", mQuotedHtmlContent.getQuotedContent(), "text/html", "utf-8", null);
mQuotedTextEdit.setVisibility(View.VISIBLE);
}
}
} else {
mQuotedTextBar.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
mQuotedText.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
}
mDraftUid = savedInstanceState.getString(STATE_KEY_DRAFT_UID);
mIdentity = (Identity)savedInstanceState.getSerializable(STATE_IDENTITY);
@ -904,10 +911,27 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
String text = mMessageContentView.getText().toString();
boolean discardQuotedText = false;
if (!isDraft && !mQuotedTextMode.equals(QuotedTextMode.SHOW)) {
discardQuotedText = true;
}
if (discardQuotedText) {
if (!isDraft) {
text = appendSignature(text);
}
// Build the body.
TextBody body = new TextBody(text);
body.setComposedMessageLength(text.length());
body.setComposedMessageOffset(0);
return body;
}
// Handle HTML separate from the rest of the text content. HTML mode doesn't allow signature after the quoted
// text, nor does it allow reply after quote. Users who want that functionality will need to stick with text
// mode.
if (mMessageFormat == MessageFormat.HTML) {
else if (mMessageFormat == MessageFormat.HTML) {
// Add the signature.
if (!isDraft) {
text = appendSignature(text);
@ -917,10 +941,6 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
if (K9.DEBUG && mQuotedHtmlContent != null)
Log.d(K9.LOG_TAG, "insertable: " + mQuotedHtmlContent.toDebugString());
if (mQuotedHtmlContent != null) {
// Remove the quoted part if it's no longer visible.
if (mQuotedTextBar.getVisibility() != View.VISIBLE) {
mQuotedHtmlContent.clearQuotedContent();
}
// 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
@ -965,7 +985,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
text = appendSignature(text);
}
if (mQuotedTextBar.getVisibility() == View.VISIBLE) {
if (mQuotedTextMode != QuotedTextMode.NONE) {
if (replyAfterQuote) {
composedMessageOffset = mQuotedText.getText().toString().length() + "\n".length();
text = mQuotedText.getText().toString() + "\n" + text;
@ -1140,7 +1160,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
EMAIL("e"),
// TODO - store a reference to the message being replied so we can mark it at the time of send.
ORIGINAL_MESSAGE("m"),
CURSOR_POSITION("p"); // Where in the message your cursor was when you saved.
CURSOR_POSITION("p"), // Where in the message your cursor was when you saved.
QUOTED_TEXT_MODE("q");
private final String value;
@ -1205,6 +1226,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
uri.appendQueryParameter(IdentityField.CURSOR_POSITION.value(), Integer.toString(mMessageContentView.getSelectionStart()));
uri.appendQueryParameter(IdentityField.QUOTED_TEXT_MODE.value(), mQuotedTextMode.name());
String k9identity = IDENTITY_VERSION_1 + uri.build().getEncodedQuery();
if (K9.DEBUG) {
@ -1279,6 +1302,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
if (tokens.hasMoreTokens()) {
identity.put(IdentityField.EMAIL, Utility.base64Decode(tokens.nextToken()));
}
if (tokens.hasMoreTokens()) {
identity.put(IdentityField.QUOTED_TEXT_MODE, Utility.base64Decode(tokens.nextToken()));
}
}
return identity;
@ -1655,8 +1681,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mAttachments.removeView((View) view.getTag());
mDraftNeedsSaving = true;
break;
case R.id.quoted_text_show:
showOrHideQuotedText(QuotedTextMode.SHOW);
mDraftNeedsSaving = true;
break;
case R.id.quoted_text_delete:
deleteQuotedText();
showOrHideQuotedText(QuotedTextMode.HIDE);
mDraftNeedsSaving = true;
break;
case R.id.quoted_text_edit:
@ -1673,15 +1703,40 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
}
/**
* Delete the quoted text.
/*
* Show or Hide the quoted text according to mQuotedTextMode.
*/
private void deleteQuotedText() {
mQuotedTextBar.setVisibility(View.GONE);
mQuotedText.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.GONE);
if (mQuotedHtmlContent != null) {
mQuotedHtmlContent.clearQuotedContent();
private void showOrHideQuotedText(QuotedTextMode mode) {
mQuotedTextMode = mode;
if (mQuotedTextMode == QuotedTextMode.NONE) {
mQuotedTextShow.setVisibility(View.GONE);
mQuotedTextBar.setVisibility(View.GONE);
mQuotedText.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.GONE);
mQuotedTextEdit.setVisibility(View.GONE);
}
else if (mQuotedTextMode == QuotedTextMode.SHOW) {
mQuotedTextShow.setVisibility(View.GONE);
mQuotedTextBar.setVisibility(View.VISIBLE);
if (mMessageFormat == MessageFormat.HTML){
mQuotedText.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.VISIBLE);
mQuotedTextEdit.setVisibility(View.VISIBLE);
}
else {
mQuotedText.setVisibility(View.VISIBLE);
mQuotedHTML.setVisibility(View.GONE);
mQuotedTextEdit.setVisibility(View.GONE);
}
}
else if (mQuotedTextMode == QuotedTextMode.HIDE) {
mQuotedTextShow.setVisibility(View.VISIBLE);
mQuotedTextBar.setVisibility(View.GONE);
mQuotedText.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.GONE);
mQuotedTextEdit.setVisibility(View.GONE);
}
}
@ -1974,6 +2029,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
}
} else if (ACTION_EDIT_DRAFT.equals(action)) {
String showQuotedTextMode = "NONE";
mDraftUid = message.getUid();
mSubjectView.setText(message.getSubject());
addAddresses(mToView, message.getRecipients(RecipientType.TO));
@ -2059,6 +2116,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
}
if (k9identity.containsKey(IdentityField.QUOTED_TEXT_MODE)) {
showQuotedTextMode = k9identity.get(IdentityField.QUOTED_TEXT_MODE);
}
mIdentity = newIdentity;
updateSignature();
@ -2073,95 +2134,62 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// Always respect the user's current composition format preference, even if the
// draft was saved in a different format.
// TODO - The current implementation doesn't allow a user in HTML mode to edit a draft that wasn't saved with K9mail.
String messageFormat = k9identity.get(IdentityField.MESSAGE_FORMAT);
if (messageFormat == null) {
// This message probably wasn't created by us. The exception is legacy
// drafts created before the advent of HTML composition. In those cases,
// we'll display the whole message (including the quoted part) in the
// composition window. If that's the case, try and convert it to text to
// match the behavior in text mode.
mMessageContentView.setText(getBodyTextFromMessage(message, MessageFormat.TEXT));
mMessageFormat = MessageFormat.TEXT;
showOrHideQuotedText(QuotedTextMode.valueOf(showQuotedTextMode));
return;
}
mMessageFormat = MessageFormat.valueOf(messageFormat);
if (mMessageFormat == MessageFormat.HTML) {
if (k9identity.get(IdentityField.MESSAGE_FORMAT) == null || !MessageFormat.valueOf(k9identity.get(IdentityField.MESSAGE_FORMAT)).equals(MessageFormat.HTML)) {
// This message probably wasn't created by us. The exception is legacy
// drafts created before the advent of HTML composition. In those cases,
// we'll display the whole message (including the quoted part) in the
// composition window. If that's the case, try and convert it to text to
// match the behavior in text mode.
mMessageContentView.setText(getBodyTextFromMessage(message, MessageFormat.TEXT));
} else {
Part part = MimeUtility.findFirstPartByMimeType(message, "text/html");
if (part != null) { // Shouldn't happen if we were the one who saved it.
String text = MimeUtility.getTextFromPart(part);
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Loading message with offset " + bodyOffset + ", length " + bodyLength + ". Text length is " + text.length() + ".");
}
Part part = MimeUtility.findFirstPartByMimeType(message, "text/html");
if (part != null) { // Shouldn't happen if we were the one who saved it.
String text = MimeUtility.getTextFromPart(part);
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Loading message with offset " + bodyOffset + ", length " + bodyLength + ". Text length is " + text.length() + ".");
}
// Grab our reply text.
String bodyText = text.substring(bodyOffset, bodyOffset + bodyLength);
mMessageContentView.setText(HtmlConverter.htmlToText(bodyText));
// Grab our reply text.
String bodyText = text.substring(bodyOffset, bodyOffset + bodyLength);
mMessageContentView.setText(HtmlConverter.htmlToText(bodyText));
// Regenerate the quoted html without our user content in it.
StringBuilder quotedHTML = new StringBuilder();
quotedHTML.append(text.substring(0, bodyOffset)); // stuff before the reply
quotedHTML.append(text.substring(bodyOffset + bodyLength));
if (quotedHTML.length() > 0) {
mQuotedHtmlContent = new InsertableHtmlContent();
mQuotedHtmlContent.setQuotedContent(quotedHTML);
mQuotedHtmlContent.setHeaderInsertionPoint(bodyOffset);
mQuotedHTML.loadDataWithBaseURL("http://", mQuotedHtmlContent.getQuotedContent(), "text/html", "utf-8", null);
mQuotedHTML.setVisibility(View.VISIBLE);
mQuotedTextBar.setVisibility(View.VISIBLE);
mQuotedTextEdit.setVisibility(View.VISIBLE);
}
// Regenerate the quoted html without our user content in it.
StringBuilder quotedHTML = new StringBuilder();
quotedHTML.append(text.substring(0, bodyOffset)); // stuff before the reply
quotedHTML.append(text.substring(bodyOffset + bodyLength));
if (quotedHTML.length() > 0) {
mQuotedHtmlContent = new InsertableHtmlContent();
mQuotedHtmlContent.setQuotedContent(quotedHTML);
mQuotedHtmlContent.setHeaderInsertionPoint(bodyOffset);
mQuotedHTML.loadDataWithBaseURL("http://", mQuotedHtmlContent.getQuotedContent(), "text/html", "utf-8", null);
}
}
} else if (mMessageFormat == MessageFormat.TEXT) {
MessageFormat format = k9identity.get(IdentityField.MESSAGE_FORMAT) != null
? MessageFormat.valueOf(k9identity.get(IdentityField.MESSAGE_FORMAT))
: null;
if (format == null) {
mMessageContentView.setText(getBodyTextFromMessage(message, MessageFormat.TEXT));
} else if (format.equals(MessageFormat.HTML)) {
// We are in text mode, but have an HTML message.
Part htmlPart = MimeUtility.findFirstPartByMimeType(message, "text/html");
if (htmlPart != null) { // Shouldn't happen if we were the one who saved it.
String text = MimeUtility.getTextFromPart(htmlPart);
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Loading message with offset " + bodyOffset + ", length " + bodyLength + ". Text length is " + text.length() + ".");
}
Part textPart = MimeUtility.findFirstPartByMimeType(message, "text/plain");
if (textPart != null) {
String text = MimeUtility.getTextFromPart(textPart);
// If we had a body length (and it was valid), separate the composition from the quoted text
// and put them in their respective places in the UI.
if (bodyLength != null && bodyLength + 1 < text.length()) { // + 1 to get rid of the newline we added when saving the draft
String bodyText = text.substring(0, bodyLength);
String quotedText = text.substring(bodyLength + 1, text.length());
// Grab our reply text.
String bodyText = text.substring(bodyOffset, bodyOffset + bodyLength);
mMessageContentView.setText(Html.fromHtml(bodyText).toString());
// Regenerate the quoted html without out content in it.
StringBuilder quotedHTML = new StringBuilder();
quotedHTML.append(text.substring(0, bodyOffset)); // stuff before the reply
quotedHTML.append(text.substring(bodyOffset + bodyLength));
// Convert it to text.
mQuotedText.setText(HtmlConverter.htmlToText(quotedHTML.toString()));
mQuotedTextBar.setVisibility(View.VISIBLE);
mQuotedText.setVisibility(View.VISIBLE);
mMessageContentView.setText(bodyText);
mQuotedText.setText(quotedText);
} else {
Log.e(K9.LOG_TAG, "Found an HTML draft but couldn't find the HTML part! Something's wrong.");
mMessageContentView.setText(text);
}
} else if (format.equals(MessageFormat.TEXT)) {
Part textPart = MimeUtility.findFirstPartByMimeType(message, "text/plain");
if (textPart != null) {
String text = MimeUtility.getTextFromPart(textPart);
// If we had a body length (and it was valid), separate the composition from the quoted text
// and put them in their respective places in the UI.
if (bodyLength != null && bodyLength + 1 < text.length()) { // + 1 to get rid of the newline we added when saving the draft
String bodyText = text.substring(0, bodyLength);
String quotedText = text.substring(bodyLength + 1, text.length());
mMessageContentView.setText(bodyText);
mQuotedText.setText(quotedText);
mQuotedTextBar.setVisibility(View.VISIBLE);
mQuotedText.setVisibility(View.VISIBLE);
mQuotedHTML.setVisibility(View.VISIBLE);
} else {
mMessageContentView.setText(text);
}
}
} else {
Log.e(K9.LOG_TAG, "Unhandled message format.");
}
} else {
Log.e(K9.LOG_TAG, "Unhandled message format.");
}
// Set the cursor position if we have it.
@ -2170,6 +2198,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
} catch(Exception e) {
Log.e(K9.LOG_TAG, "Could not set cursor position in MessageCompose; ignoring.", e);
}
showOrHideQuotedText(QuotedTextMode.valueOf(showQuotedTextMode));
}
} catch (MessagingException me) {
/**
@ -2178,8 +2208,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
*/
Log.e(K9.LOG_TAG, "Error while processing source message: ", me);
}
mSourceMessageProcessed = true;
mDraftNeedsSaving = false;
finally {
mSourceMessageProcessed = true;
mDraftNeedsSaving = false;
}
}
/**
@ -2200,20 +2232,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// Load the message with the reply header.
mQuotedHTML.loadDataWithBaseURL("http://", mQuotedHtmlContent.getQuotedContent(), "text/html", "utf-8", null);
mQuotedTextBar.setVisibility(View.VISIBLE);
mQuotedHTML.setVisibility(View.VISIBLE);
mQuotedTextEdit.setVisibility(View.VISIBLE);
mQuotedText.setVisibility(View.GONE);
showOrHideQuotedText(QuotedTextMode.SHOW);
} else if (mMessageFormat == MessageFormat.TEXT) {
mQuotedText.setText(quoteOriginalTextMessage(mSourceMessage, content, mAccount.getQuoteStyle()));
mQuotedTextBar.setVisibility(View.VISIBLE);
mQuotedText.setVisibility(View.VISIBLE);
mQuotedHtmlContent = null;
mQuotedTextEdit.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.GONE);
showOrHideQuotedText(QuotedTextMode.SHOW);
}
}
@ -2428,7 +2451,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
populateUIWithQuotedMessage();
} catch (MessagingException e) {
// Hm, if we couldn't populate the UI after source reprocessing, let's just delete it?
deleteQuotedText();
showOrHideQuotedText(QuotedTextMode.HIDE);
Log.e(K9.LOG_TAG, "Could not re-process source message; deleting quoted text to be safe.", e);
}
} else {