am 38ca4b14: am 63287be2: am 44441af5: am d636f8c6: Merge "Sending a mail to self crashes gmail" into ub-gmail-ur14-dev
* commit '38ca4b1434f3b4a4fc0bab6965bb87dc74cc99e2':
Sending a mail to self crashes gmail
diff --git a/src/com/android/mail/browse/ConversationItemView.java b/src/com/android/mail/browse/ConversationItemView.java
index bb20182..cc5305d 100644
--- a/src/com/android/mail/browse/ConversationItemView.java
+++ b/src/com/android/mail/browse/ConversationItemView.java
@@ -779,13 +779,7 @@
SendersView.format(context, mHeader.conversation.conversationInfo,
mHeader.messageInfoString.toString(), maxChars, mHeader.styledNames,
mHeader.displayableNames, mHeader.mSenderAvatarModel,
- mAccount.getEmailAddress(), mDisplayedFolder.shouldShowRecipients(), true);
-
- if (mHeader.mSenderAvatarModel.isNotPopulated() && mHeader.hasDraftMessage) {
- mHeader.mSenderAvatarModel.populate(mAccount.getDisplayName(),
- mAccount.getEmailAddress());
- mHeader.displayableNames.add(mAccount.getDisplayName());
- }
+ mAccount, mDisplayedFolder.shouldShowRecipients(), true);
// If we have displayable senders, load their thumbnails
loadImages();
diff --git a/src/com/android/mail/browse/SendersView.java b/src/com/android/mail/browse/SendersView.java
index 734a59a..8b22496 100644
--- a/src/com/android/mail/browse/SendersView.java
+++ b/src/com/android/mail/browse/SendersView.java
@@ -32,6 +32,7 @@
import android.text.style.TextAppearanceSpan;
import com.android.mail.R;
+import com.android.mail.providers.Account;
import com.android.mail.providers.Conversation;
import com.android.mail.providers.ConversationInfo;
import com.android.mail.providers.ParticipantInfo;
@@ -226,7 +227,7 @@
String messageInfo, int maxChars, ArrayList<SpannableString> styledSenders,
ArrayList<String> displayableSenderNames,
ConversationItemViewModel.SenderAvatarModel senderAvatarModel,
- String account, final boolean showToHeader, final boolean resourceCachingRequired) {
+ Account account, final boolean showToHeader, final boolean resourceCachingRequired) {
try {
getSenderResources(context, resourceCachingRequired);
format(context, conversationInfo, messageInfo, maxChars, styledSenders,
@@ -243,7 +244,7 @@
String messageInfo, int maxChars, ArrayList<SpannableString> styledSenders,
ArrayList<String> displayableSenderNames,
ConversationItemViewModel.SenderAvatarModel senderAvatarModel,
- String account, final TextAppearanceSpan notificationUnreadStyleSpan,
+ Account account, final TextAppearanceSpan notificationUnreadStyleSpan,
final CharacterStyle notificationReadStyleSpan, final boolean showToHeader,
final boolean resourceCachingRequired) {
try {
@@ -262,7 +263,7 @@
ConversationInfo conversationInfo, ArrayList<SpannableString> styledSenders,
ArrayList<String> displayableSenderNames,
ConversationItemViewModel.SenderAvatarModel senderAvatarModel,
- String account, final TextAppearanceSpan unreadStyleSpan,
+ Account account, final TextAppearanceSpan unreadStyleSpan,
final CharacterStyle readStyleSpan, final boolean showToHeader) {
final boolean shouldSelectSenders = displayableSenderNames != null;
final boolean shouldSelectAvatar = senderAvatarModel != null;
@@ -363,7 +364,7 @@
}
}
- final String senderEmail = TextUtils.isEmpty(currentName) ? account :
+ final String senderEmail = TextUtils.isEmpty(currentName) ? account.getEmailAddress() :
TextUtils.isEmpty(currentEmail) ? currentName : currentEmail;
if (shouldSelectSenders) {
@@ -406,9 +407,7 @@
}
// if all messages in the thread were read, we must search for an appropriate avatar
- if (shouldSelectAvatar && senderAvatarModel.isNotPopulated() &&
- !conversationInfo.participantInfos.isEmpty()) {
-
+ if (shouldSelectAvatar && senderAvatarModel.isNotPopulated()) {
// search for the last sender that is not the current account
for (int i = conversationInfo.participantInfos.size() - 1; i >= 0; i--) {
final ParticipantInfo participant = conversationInfo.participantInfos.get(i);
@@ -418,11 +417,9 @@
}
}
- // if we still don't have an avatar, the account is emailing itself; use the last sender
+ // if we still don't have an avatar, the account is emailing itself
if (senderAvatarModel.isNotPopulated()) {
- final int lastIndex = conversationInfo.participantInfos.size() - 1;
- final ParticipantInfo lastSender = conversationInfo.participantInfos.get(lastIndex);
- senderAvatarModel.populate(lastSender.name, lastSender.email);
+ senderAvatarModel.populate(account.getDisplayName(), account.getEmailAddress());
}
}
}
diff --git a/src/com/android/mail/utils/NotificationUtils.java b/src/com/android/mail/utils/NotificationUtils.java
index 3c61f78..31c61fa 100644
--- a/src/com/android/mail/utils/NotificationUtils.java
+++ b/src/com/android/mail/utils/NotificationUtils.java
@@ -90,7 +90,6 @@
public static final String EXTRA_UNREAD_COUNT = "unread-count";
public static final String EXTRA_UNSEEN_COUNT = "unseen-count";
public static final String EXTRA_GET_ATTENTION = "get-attention";
- private static final int PUBLIC_NOTIFICATIONS_VISIBLE_CHARS = 4;
/** Contains a list of <(account, label), unread conversations> */
private static NotificationMap sActiveNotificationMap = null;
@@ -954,7 +953,7 @@
Bitmap bg = sDefaultWearableBg.get();
if (bg == null) {
bg = BitmapFactory.decodeResource(context.getResources(), R.drawable.bg_email);
- sDefaultWearableBg = new WeakReference<Bitmap>(bg);
+ sDefaultWearableBg = new WeakReference<>(bg);
}
return bg;
}
@@ -969,8 +968,6 @@
final int unreadCount, final int unseenCount,
final Folder folder, final long when, final ContactFetcher contactFetcher) {
final Resources res = context.getResources();
- final String notificationAccountDisplayName = account.getDisplayName();
- final String notificationAccountEmail = account.getEmailAddress();
final boolean multipleUnseen = unseenCount > 1;
LogUtils.i(LOG_TAG, "Showing notification with unreadCount of %d and unseenCount of %d",
@@ -1002,7 +999,7 @@
// The body of the notification is the account name, or the label name.
notificationBuilder.setSubText(
- isInbox ? notificationAccountDisplayName : notificationLabelName);
+ isInbox ? account.getDisplayName() : notificationLabelName);
final NotificationCompat.InboxStyle digest =
new NotificationCompat.InboxStyle(notificationBuilder);
@@ -1057,7 +1054,7 @@
res.getInteger(R.integer.swipe_senders_length);
sendersBuilder = getStyledSenders(context, conversationCursor,
- sendersLength, notificationAccountEmail);
+ sendersLength, account);
} else {
sendersBuilder =
new SpannableStringBuilder(getWrappedFromString(from));
@@ -1108,7 +1105,6 @@
configureNotifForOneConversation(context, account,
folderPreferences, conversationNotif, conversationWearExtender,
conversationCursor, notificationIntent, folder, when, res,
- notificationAccountDisplayName, notificationAccountEmail,
isInbox, notificationLabelName, conversationNotificationId,
contactFetcher);
msgNotifications.put(conversationNotificationId,
@@ -1142,7 +1138,7 @@
} else {
// The body of the notification is the account name, or the label name.
notificationBuilder.setContentText(
- isInbox ? notificationAccountDisplayName : notificationLabelName);
+ isInbox ? account.getDisplayName() : notificationLabelName);
}
} else {
// For notifications for a single new conversation, we want to get the information
@@ -1153,8 +1149,7 @@
final ConfigResult result = configureNotifForOneConversation(context, account,
folderPreferences, notificationBuilder, wearableExtender, conversationCursor,
- notificationIntent, folder, when, res, notificationAccountDisplayName,
- notificationAccountEmail, isInbox, notificationLabelName,
+ notificationIntent, folder, when, res, isInbox, notificationLabelName,
summaryNotificationId, contactFetcher);
notificationTicker = result.notificationTicker;
@@ -1194,7 +1189,6 @@
NotificationCompat.Builder notificationBuilder,
NotificationCompat.WearableExtender wearExtender, Cursor conversationCursor,
Intent notificationIntent, Folder folder, long when, Resources res,
- String notificationAccountDisplayName, String notificationAccountEmail,
boolean isInbox, String notificationLabelName, int notificationId,
final ContactFetcher contactFetcher) {
@@ -1260,8 +1254,7 @@
int sendersLength = res.getInteger(R.integer.swipe_senders_length);
final SpannableStringBuilder sendersBuilder = getStyledSenders(
- context, conversationCursor, sendersLength,
- notificationAccountEmail);
+ context, conversationCursor, sendersLength, account);
notificationBuilder.setContentTitle(sendersBuilder);
// For a single new conversation, the ticker is based on the sender's name.
@@ -1281,7 +1274,7 @@
// notifications, or will based on the the label name for user label
// notifications.
notificationBuilder.setSubText(isInbox ?
- notificationAccountDisplayName : notificationLabelName);
+ account.getDisplayName() : notificationLabelName);
final NotificationCompat.BigTextStyle bigText =
new NotificationCompat.BigTextStyle(notificationBuilder);
@@ -1316,7 +1309,7 @@
// notifications, or will based on the the label name for user label
// notifications.
notificationBuilder.setContentText(
- isInbox ? notificationAccountDisplayName : notificationLabelName);
+ isInbox ? account.getDisplayName() : notificationLabelName);
// For a single new conversation, the ticker is based on the sender's name.
result.notificationTicker = from;
@@ -1427,11 +1420,11 @@
}
private static SpannableStringBuilder getStyledSenders(final Context context,
- final Cursor conversationCursor, final int maxLength, final String account) {
+ final Cursor conversationCursor, final int maxLength, final Account account) {
final Conversation conversation = new Conversation(conversationCursor);
final com.android.mail.providers.ConversationInfo conversationInfo =
conversation.conversationInfo;
- final ArrayList<SpannableString> senders = new ArrayList<SpannableString>();
+ final ArrayList<SpannableString> senders = new ArrayList<>();
if (sNotificationUnreadStyleSpan == null) {
sNotificationUnreadStyleSpan = new TextAppearanceSpan(
context, R.style.NotificationSendersUnreadTextAppearance);
diff --git a/src/com/android/mail/widget/WidgetService.java b/src/com/android/mail/widget/WidgetService.java
index 2f82e30..d8e9861 100644
--- a/src/com/android/mail/widget/WidgetService.java
+++ b/src/com/android/mail/widget/WidgetService.java
@@ -409,7 +409,7 @@
ArrayList<SpannableString> senders = new ArrayList<SpannableString>();
SendersView.format(mContext, conversation.conversationInfo, "",
- MAX_SENDERS_LENGTH, senders, null, null, mAccount.getEmailAddress(),
+ MAX_SENDERS_LENGTH, senders, null, null, mAccount,
Folder.shouldShowRecipients(mFolderCapabilities), true);
final SpannableStringBuilder senderBuilder = elideParticipants(senders);
diff --git a/tests/src/com/android/mail/browse/SendersFormattingTests.java b/tests/src/com/android/mail/browse/SendersFormattingTests.java
index c55e03b..142e04c 100644
--- a/tests/src/com/android/mail/browse/SendersFormattingTests.java
+++ b/tests/src/com/android/mail/browse/SendersFormattingTests.java
@@ -21,11 +21,18 @@
import android.test.suitebuilder.annotation.SmallTest;
import android.text.SpannableString;
+import com.android.mail.providers.Account;
import com.android.mail.providers.ConversationInfo;
import com.android.mail.providers.ParticipantInfo;
+import com.android.mail.providers.UIProvider;
import com.google.common.collect.Lists;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
@SmallTest
public class SendersFormattingTests extends AndroidTestCase {
@@ -40,7 +47,8 @@
final ArrayList<SpannableString> strings = Lists.newArrayList();
assertEquals(0, strings.size());
- SendersView.format(getContext(), conv, "", 100, strings, null, null, null, false, false);
+ final Account account = createAccount();
+ SendersView.format(getContext(), conv, "", 100, strings, null, null, account, false, false);
assertEquals(1, strings.size());
assertEquals("me", strings.get(0).toString());
}
@@ -51,7 +59,8 @@
final ArrayList<SpannableString> strings = Lists.newArrayList();
assertEquals(0, strings.size());
- SendersView.format(getContext(), conv, "", 100, strings, null, null, null, false, false);
+ final Account account = createAccount();
+ SendersView.format(getContext(), conv, "", 100, strings, null, null, account, false, false);
assertEquals(1, strings.size());
assertEquals("me", strings.get(0).toString());
}
@@ -63,7 +72,8 @@
final ArrayList<SpannableString> strings = Lists.newArrayList();
assertEquals(0, strings.size());
- SendersView.format(getContext(), conv, "", 100, strings, null, null, null, false, false);
+ final Account account = createAccount();
+ SendersView.format(getContext(), conv, "", 100, strings, null, null, account, false, false);
assertEquals(2, strings.size());
assertNull(strings.get(0));
assertEquals("me", strings.get(1).toString());
@@ -161,8 +171,9 @@
final ConversationItemViewModel.SenderAvatarModel senderAvatarModel =
new ConversationItemViewModel.SenderAvatarModel();
+ final Account account = createAccount();
SendersView.format(getContext(), conv, "", 100, styledSenders, displayableSenderNames,
- senderAvatarModel, null, false, false);
+ senderAvatarModel, account, false, false);
assertEquals("b@b.com", senderAvatarModel.getEmailAddress());
assertEquals("b", senderAvatarModel.getName());
@@ -178,11 +189,12 @@
final ConversationItemViewModel.SenderAvatarModel senderAvatarModel =
new ConversationItemViewModel.SenderAvatarModel();
+ final Account account = createAccount();
SendersView.format(getContext(), conv, "", 100, styledSenders, displayableSenderNames,
- senderAvatarModel, null, false, false);
+ senderAvatarModel, account, false, false);
- assertEquals("a@a.com", senderAvatarModel.getEmailAddress());
- assertEquals("", senderAvatarModel.getName());
+ assertEquals("fflinstone@example.com", senderAvatarModel.getEmailAddress());
+ assertEquals("Fred Flinstone", senderAvatarModel.getName());
}
/**
@@ -206,4 +218,21 @@
assertEquals("Andrew", displayableSenderNames.get(0));
assertEquals("Andrew", displayableSenderNames.get(1));
}
+
+ private static Account createAccount() {
+ try {
+ final Map<String, Object> map = new HashMap<>(2);
+ map.put(UIProvider.AccountColumns.NAME, "Fred Flinstone");
+ map.put(UIProvider.AccountColumns.ACCOUNT_MANAGER_NAME, "fflinstone@example.com");
+ map.put(UIProvider.AccountColumns.TYPE, "IMAP");
+ map.put(UIProvider.AccountColumns.PROVIDER_VERSION, 1);
+ map.put(UIProvider.AccountColumns.CAPABILITIES, 0);
+
+ final JSONObject json = new JSONObject(map);
+
+ return Account.builder().buildFrom(json);
+ } catch (JSONException je) {
+ throw new RuntimeException(je);
+ }
+ }
}
\ No newline at end of file