From 2c486e31b6c7172fefb7c3d8098be7020e186ce8 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 24 Sep 2012 19:11:21 -0400 Subject: [PATCH] option to put the sender of a message above the subject --- res/values/strings.xml | 4 + res/xml/global_preferences.xml | 6 +- src/com/fsck/k9/K9.java | 10 ++ src/com/fsck/k9/activity/MessageList.java | 118 ++++++++++++++-------- src/com/fsck/k9/activity/setup/Prefs.java | 6 ++ 5 files changed, 103 insertions(+), 41 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index c2ea562cd..ddaa432e6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -313,6 +313,10 @@ http://k9mail.googlecode.com/ Preview lines Show correspondent names Show correspondent names rather than their email addresses + + Correspondent above subject + Show correspondent names above the subject line, rather than below it + Show contact names Use recipient names from Contacts when available Colorize contacts diff --git a/res/xml/global_preferences.xml b/res/xml/global_preferences.xml index a0d75ac6d..9d8b9e23a 100644 --- a/res/xml/global_preferences.xml +++ b/res/xml/global_preferences.xml @@ -116,7 +116,11 @@ android:summary="@string/global_settings_show_correspondent_names_summary" /> - + null. */ + + + private void bindView(final int position, final View view, final MessageViewHolder holder, final MessageInfoHolder message) { - holder.subject.setTypeface(null, message.read ? Typeface.NORMAL : Typeface.BOLD); + int maybeBoldTypeface = message.read ? Typeface.NORMAL : Typeface.BOLD; // So that the mSelectedCount is only incremented/decremented // when a user checks the checkbox (vs code) holder.position = -1; - if (message.selected) { holder.chip.setBackgroundDrawable(message.message.getFolder().getAccount().getCheckmarkChip().drawable()); @@ -2211,78 +2224,103 @@ public class MessageList extends K9ListActivity implements OnItemClickListener, holder.chip.setBackgroundDrawable(message.message.getFolder().getAccount().generateColorChip(message.read,message.message.toMe(), false, message.flagged).drawable()); } - // TODO: Make these colors part of the theme - // if (K9.getK9Theme() == K9.THEME_LIGHT) { // // Light theme: light grey background for read messages -// view.setBackgroundColor(message.read ? Color.rgb(229, 229, 229) : Color.rgb(255, 255, 255)); +// view.setBackgroundColor(message.read ? +// Color.rgb(230, 230, 230) : Color.rgb(255, 255, 255)); // } else { // // Dark theme: dark grey background for unread messages // view.setBackgroundColor(message.read ? 0 : Color.rgb(45, 45, 45)); // } + String subject = null; + if ((message.message.getSubject() == null) || message.message.getSubject().equals("")) { - holder.subject.setText(getText(R.string.general_no_subject)); + subject = (String) getText(R.string.general_no_subject); + } else { - holder.subject.setText(message.message.getSubject()); + subject = message.message.getSubject(); } - int senderTypeface = message.read ? Typeface.NORMAL : Typeface.BOLD; + // We'll get badge support soon --jrv +// if (holder.badge != null) { +// String email = message.counterpartyAddress; +// holder.badge.assignContactFromEmail(email, true); +// if (email != null) { +// mContactsPictureLoader.loadContactPicture(email, holder.badge); +// } +// } + if (holder.preview != null) { /* + * In the touchable UI, we have previews. Otherwise, we + * have just a "from" line. * Because text views can't wrap around each other(?) we * compose a custom view containing the preview and the * from. */ + CharSequence beforePreviewText = null; + if (mSenderAboveSubject) { + beforePreviewText = subject; + } else { + beforePreviewText = message.sender; + } + holder.preview.setText(new SpannableStringBuilder(recipientSigil(message)) - .append(message.sender).append(" ").append(message.message.getPreview()), + .append(beforePreviewText).append(" ").append(message.message.getPreview()), TextView.BufferType.SPANNABLE); Spannable str = (Spannable)holder.preview.getText(); // Create a span section for the sender, and assign the correct font size and weight. - str.setSpan(new StyleSpan(senderTypeface), - 0, - message.sender.length() + 1, - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - str.setSpan(new AbsoluteSizeSpan(mFontSizes.getMessageListSender(), true), - 0, - message.sender.length() + 1, - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + str.setSpan(new AbsoluteSizeSpan((mSenderAboveSubject ? mFontSizes.getMessageListSubject(): mFontSizes.getMessageListSender()), true), + 0, beforePreviewText.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - // TODO: Make these colors part of the theme int color = (K9.getK9Theme() == K9.THEME_LIGHT) ? Color.rgb(105, 105, 105) : Color.rgb(160, 160, 160); // set span for preview message. str.setSpan(new ForegroundColorSpan(color), // How do I can specify the android.R.attr.textColorTertiary - message.sender.length() + 1, + beforePreviewText.length() + 1, str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - } else { - holder.from.setText(new SpannableStringBuilder(recipientSigil(message)).append(message.sender)); + } - holder.from.setTypeface(null, senderTypeface); + + if (holder.from != null ) { + holder.from.setTypeface(null, maybeBoldTypeface); + if (mSenderAboveSubject) { + holder.from.setCompoundDrawablesWithIntrinsicBounds( + message.answered ? mAnsweredIcon : null, // left + null, // top + message.message.hasAttachments() ? mAttachmentIcon : null, // right + null); // bottom + + holder.from.setText(message.sender); + } else { + holder.from.setText(new SpannableStringBuilder(recipientSigil(message)).append(message.sender)); + } + } + + if (holder.subject != null ) { + if (!mSenderAboveSubject) { + holder.subject.setCompoundDrawablesWithIntrinsicBounds( + message.answered ? mAnsweredIcon : null, // left + null, // top + message.message.hasAttachments() ? mAttachmentIcon : null, // right + null); // bottom + } + + holder.subject.setTypeface(null, maybeBoldTypeface); + holder.subject.setText(subject); } holder.date.setText(message.getDate(mMessageHelper)); - - Drawable statusHolder = null; - if (message.forwarded && message.answered) { - statusHolder = mForwardedAnsweredIcon; - } else if (message.answered) { - statusHolder = mAnsweredIcon; - } else if (message.forwarded) { - statusHolder = mForwardedIcon; - } - holder.subject.setCompoundDrawablesWithIntrinsicBounds(statusHolder, // left - null, // top - message.message.hasAttachments() ? mAttachmentIcon : null, // right - null); // bottom holder.position = position; } + private String recipientSigil(MessageInfoHolder message) { if (message.message.toMe()) { return getString(R.string.messagelist_sent_to_me_sigil); diff --git a/src/com/fsck/k9/activity/setup/Prefs.java b/src/com/fsck/k9/activity/setup/Prefs.java index a93664450..ba036e501 100644 --- a/src/com/fsck/k9/activity/setup/Prefs.java +++ b/src/com/fsck/k9/activity/setup/Prefs.java @@ -60,6 +60,7 @@ public class Prefs extends K9PreferenceActivity { private static final String PREFERENCE_COUNT_SEARCH = "count_search"; private static final String PREFERENCE_HIDE_SPECIAL_ACCOUNTS = "hide_special_accounts"; private static final String PREFERENCE_MESSAGELIST_PREVIEW_LINES = "messagelist_preview_lines"; + private static final String PREFERENCE_MESSAGELIST_SENDER_ABOVE_SUBJECT = "messagelist_sender_above_subject"; private static final String PREFERENCE_MESSAGELIST_SHOW_CORRESPONDENT_NAMES = "messagelist_show_correspondent_names"; private static final String PREFERENCE_MESSAGELIST_SHOW_CONTACT_NAME = "messagelist_show_contact_name"; private static final String PREFERENCE_MESSAGELIST_CONTACT_NAME_COLOR = "messagelist_contact_name_color"; @@ -99,6 +100,7 @@ public class Prefs extends K9PreferenceActivity { private CheckBoxPreference mCountSearch; private CheckBoxPreference mHideSpecialAccounts; private ListPreference mPreviewLines; + private CheckBoxPreference mSenderAboveSubject; private CheckBoxPreference mShowCorrespondentNames; private CheckBoxPreference mShowContactName; private CheckBoxPreference mChangeContactNameColor; @@ -212,6 +214,9 @@ public class Prefs extends K9PreferenceActivity { mPreviewLines = setupListPreference(PREFERENCE_MESSAGELIST_PREVIEW_LINES, Integer.toString(K9.messageListPreviewLines())); + mSenderAboveSubject = (CheckBoxPreference)findPreference(PREFERENCE_MESSAGELIST_SENDER_ABOVE_SUBJECT); + mSenderAboveSubject.setChecked(K9.messageListSenderAboveSubject()); + mShowCorrespondentNames = (CheckBoxPreference)findPreference(PREFERENCE_MESSAGELIST_SHOW_CORRESPONDENT_NAMES); mShowCorrespondentNames.setChecked(K9.showCorrespondentNames()); @@ -399,6 +404,7 @@ public class Prefs extends K9PreferenceActivity { K9.setHideSpecialAccounts(mHideSpecialAccounts.isChecked()); K9.setMessageListPreviewLines(Integer.parseInt(mPreviewLines.getValue())); K9.setShowCorrespondentNames(mShowCorrespondentNames.isChecked()); + K9.setMessageListSenderAboveSubject(mSenderAboveSubject.isChecked()); K9.setShowContactName(mShowContactName.isChecked()); K9.setChangeContactNameColor(mChangeContactNameColor.isChecked()); K9.setMessageViewFixedWidthFont(mFixedWidth.isChecked());