From 5d6df85aac5a9ded0579f4bfd7dfee56dde8ec95 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Wed, 11 May 2011 00:54:17 +0900 Subject: [PATCH] possible to toggle to display the quoted message to send. --- res/layout/message_compose.xml | 10 + src/com/fsck/k9/activity/MessageCompose.java | 277 ++++++++++--------- 2 files changed, 160 insertions(+), 127 deletions(-) diff --git a/res/layout/message_compose.xml b/res/layout/message_compose.xml index 66f0de097..bc8d89d39 100644 --- a/res/layout/message_compose.xml +++ b/res/layout/message_compose.xml @@ -237,6 +237,16 @@ android:textColor="@android:color/primary_text_light" android:textAppearance="?android:attr/textAppearanceMedium" /> + + 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 {