From d66b465776261b3313c4b3bb3ef7c3954ebb08e4 Mon Sep 17 00:00:00 2001 From: Mihai Preda Date: Wed, 23 Sep 2009 16:50:31 +0200 Subject: [PATCH] Fix loading the quoted text when editing draft. Bug 2140036. Only load the reply fields for an edit-draft situation. --- .../email/activity/MessageCompose.java | 55 +++++++++++-------- .../android/email/provider/EmailContent.java | 18 +++++- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/com/android/email/activity/MessageCompose.java b/src/com/android/email/activity/MessageCompose.java index d4c52f3b6..2e1b7a4c7 100644 --- a/src/com/android/email/activity/MessageCompose.java +++ b/src/com/android/email/activity/MessageCompose.java @@ -335,7 +335,6 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus cancelTask(mLoadMessageTask); mLoadMessageTask = null; // don't cancel mSaveMessageTask, let it do its job to the end. - // cancelTask(mSaveMessageTask); } /** @@ -505,6 +504,17 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus // Body body = Body.restoreBodyWithMessageId(MessageCompose.this, message.mId); message.mHtml = Body.restoreBodyHtmlWithMessageId(MessageCompose.this, message.mId); message.mText = Body.restoreBodyTextWithMessageId(MessageCompose.this, message.mId); + boolean isEditDraft = ACTION_EDIT_DRAFT.equals(getIntent().getAction()); + // the reply fields are only filled/used for Drafts. + if (isEditDraft) { + message.mHtmlReply = + Body.restoreHtmlReplyWithMessageId(MessageCompose.this, message.mId); + message.mTextReply = + Body.restoreTextReplyWithMessageId(MessageCompose.this, message.mId); + } else { + message.mHtmlReply = null; + message.mTextReply = null; + } } catch (RuntimeException e) { Log.d(Email.LOG_TAG, "Exception while loading message body: " + e); return null; @@ -590,21 +600,6 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus return addresses; } - private ContentValues getUpdateContentValues(Message message) { - ContentValues values = new ContentValues(); - values.put(MessageColumns.TIMESTAMP, message.mTimeStamp); - values.put(MessageColumns.FROM_LIST, message.mFrom); - values.put(MessageColumns.TO_LIST, message.mTo); - values.put(MessageColumns.CC_LIST, message.mCc); - values.put(MessageColumns.BCC_LIST, message.mBcc); - values.put(MessageColumns.SUBJECT, message.mSubject); - values.put(MessageColumns.DISPLAY_NAME, message.mDisplayName); - values.put(MessageColumns.FLAG_LOADED, message.mFlagLoaded); - values.put(MessageColumns.FLAG_ATTACHMENT, message.mFlagAttachment); - values.put(MessageColumns.FLAGS, message.mFlags); - return values; - } - /* * Computes a short string indicating the destination of the message based on To, Cc, Bcc. * If only one address appears, returns the friendly form of that address. @@ -630,6 +625,21 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus return this.getString(R.string.message_compose_display_name, friendly, nRecipients - 1); } + private ContentValues getUpdateContentValues(Message message) { + ContentValues values = new ContentValues(); + values.put(MessageColumns.TIMESTAMP, message.mTimeStamp); + values.put(MessageColumns.FROM_LIST, message.mFrom); + values.put(MessageColumns.TO_LIST, message.mTo); + values.put(MessageColumns.CC_LIST, message.mCc); + values.put(MessageColumns.BCC_LIST, message.mBcc); + values.put(MessageColumns.SUBJECT, message.mSubject); + values.put(MessageColumns.DISPLAY_NAME, message.mDisplayName); + values.put(MessageColumns.FLAG_LOADED, message.mFlagLoaded); + values.put(MessageColumns.FLAG_ATTACHMENT, message.mFlagAttachment); + values.put(MessageColumns.FLAGS, message.mFlags); + return values; + } + /** * @param message The message to be updated. * @param account the account (used to obtain From: address). @@ -1123,9 +1133,9 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus } // used by processSourceMessage() - private void displayQuotedText(Message message) { - boolean plainTextFlag = message.mHtml == null; - String text = plainTextFlag ? message.mText : message.mHtml; + private void displayQuotedText(String textBody, String htmlBody) { + boolean plainTextFlag = htmlBody == null; + String text = plainTextFlag ? textBody : htmlBody; if (text != null) { text = plainTextFlag ? EmailHtmlUtil.escapeCharacterToDisplay(text) : text; // TODO: re-enable EmailHtmlUtil.resolveInlineImage() for HTML @@ -1213,11 +1223,11 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus mSubjectView.setText(subject); } - displayQuotedText(message); + displayQuotedText(message.mText, message.mHtml); } else if (ACTION_FORWARD.equals(action)) { mSubjectView.setText(subject != null && !subject.toLowerCase().startsWith("fwd:") ? "Fwd: " + subject : subject); - displayQuotedText(message); + displayQuotedText(message.mText, message.mHtml); if (!mSourceMessageProcessed) { // TODO: re-enable loadAttachments below // if (!loadAttachments(message, 0)) { @@ -1238,9 +1248,8 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus mBccView.setVisibility(View.VISIBLE); } - // TODO: why not the same text handling as in displayQuotedText() ? mMessageContentView.setText(message.mText); - + displayQuotedText(message.mTextReply, message.mHtmlReply); if (!mSourceMessageProcessed) { // TODO: re-enable loadAttachments // loadAttachments(message, 0); diff --git a/src/com/android/email/provider/EmailContent.java b/src/com/android/email/provider/EmailContent.java index 635569714..a4752b889 100644 --- a/src/com/android/email/provider/EmailContent.java +++ b/src/com/android/email/provider/EmailContent.java @@ -210,16 +210,22 @@ public abstract class EmailContent { BodyColumns.INTRO_TEXT }; - public static final int TEXT_TEXT_COLUMN = 1; public static final String[] TEXT_PROJECTION = new String[] { RECORD_ID, BodyColumns.TEXT_CONTENT }; - public static final int HTML_HTML_COLUMN = 1; public static final String[] HTML_PROJECTION = new String[] { RECORD_ID, BodyColumns.HTML_CONTENT }; + public static final String[] HTML_REPLY_PROJECTION = new String[] { + RECORD_ID, BodyColumns.HTML_REPLY + }; + + public static final String[] TEXT_REPLY_PROJECTION = new String[] { + RECORD_ID, BodyColumns.TEXT_REPLY + }; + public static final int COMMON_TEXT_COLUMN = 1; public long mMessageKey; @@ -330,6 +336,14 @@ public abstract class EmailContent { return restoreTextWithMessageId(context, messageId, Body.HTML_PROJECTION); } + public static String restoreTextReplyWithMessageId(Context context, long messageId) { + return restoreTextWithMessageId(context, messageId, Body.TEXT_REPLY_PROJECTION); + } + + public static String restoreHtmlReplyWithMessageId(Context context, long messageId) { + return restoreTextWithMessageId(context, messageId, Body.HTML_REPLY_PROJECTION); + } + @Override @SuppressWarnings("unchecked") public EmailContent.Body restore(Cursor c) {