Regularize usage of ReplyFromAccount#name
b/11334332
b/11292541
Change-Id: I0394ea2caf86bbf200a3027f288aa078d965503c
diff --git a/src/com/android/mail/compose/ComposeActivity.java b/src/com/android/mail/compose/ComposeActivity.java
index 720ab35..2426c6d 100644
--- a/src/com/android/mail/compose/ComposeActivity.java
+++ b/src/com/android/mail/compose/ComposeActivity.java
@@ -940,10 +940,10 @@
message.accountUri = null;
final String email = selectedReplyFromAccount != null ? selectedReplyFromAccount.address
: mAccount != null ? mAccount.getEmailAddress() : null;
- // TODO: this behavior is wrong. Pull the name from selectedReplyFromAccount.name
- final String senderName = mAccount != null ? mAccount.getSenderName() : null;
+ final String senderName = selectedReplyFromAccount != null ? selectedReplyFromAccount.name
+ : mAccount != null ? mAccount.getSenderName() : null;
final Address address = new Address(senderName, email);
- message.setFrom(address.pack());
+ message.setFrom(address.toHeader());
message.draftType = getDraftType(mode);
return message;
}
@@ -1092,18 +1092,18 @@
return from;
}
}
- return new ReplyFromAccount(account, account.uri, account.getEmailAddress(), account.name,
- account.getEmailAddress(), true, false);
+ return new ReplyFromAccount(account, account.uri, account.getEmailAddress(),
+ account.getSenderName(), account.getEmailAddress(), true, false);
}
- private ReplyFromAccount getReplyFromAccountFromDraft(Account account, Message msg) {
- String sender = msg.getFrom();
+ private ReplyFromAccount getReplyFromAccountFromDraft(final Account account,
+ final Message msg) {
+ final Address[] draftFroms = Address.parse(msg.getFrom());
+ final String sender = draftFroms.length > 0 ? draftFroms[0].getAddress() : "";
ReplyFromAccount replyFromAccount = null;
List<ReplyFromAccount> replyFromAccounts = mFromSpinner.getReplyFromAccounts();
if (TextUtils.equals(account.getEmailAddress(), sender)) {
- replyFromAccount = new ReplyFromAccount(mAccount, mAccount.uri,
- mAccount.getEmailAddress(), mAccount.name, mAccount.getEmailAddress(),
- true, false);
+ replyFromAccount = getDefaultReplyFromAccount(account);
} else {
for (ReplyFromAccount fromAccount : replyFromAccounts) {
if (TextUtils.equals(fromAccount.address, sender)) {
diff --git a/src/com/android/mail/compose/FromAddressSpinner.java b/src/com/android/mail/compose/FromAddressSpinner.java
index a9a0886..7d82d1e 100644
--- a/src/com/android/mail/compose/FromAddressSpinner.java
+++ b/src/com/android/mail/compose/FromAddressSpinner.java
@@ -70,8 +70,7 @@
public ReplyFromAccount getMatchingReplyFromAccount(String accountString) {
if (!TextUtils.isEmpty(accountString)) {
for (ReplyFromAccount acct : mReplyFromAccounts) {
- // TODO: Do not key off ReplyFromAccount.name b/11292541
- if (accountString.equals(acct.name)) {
+ if (accountString.equals(acct.address)) {
return acct;
}
}
@@ -148,8 +147,7 @@
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
ReplyFromAccount selection = (ReplyFromAccount) getItemAtPosition(position);
- // TODO: Do not key off ReplyFromAccount.name b/11292541
- if (!selection.name.equals(mAccount.name)) {
+ if (!selection.address.equals(mAccount.address)) {
mAccount = selection;
mAccountChangedListener.onAccountChanged();
}
diff --git a/src/com/android/mail/compose/FromAddressSpinnerAdapter.java b/src/com/android/mail/compose/FromAddressSpinnerAdapter.java
index 6ea8e7d..1abc8c6 100644
--- a/src/com/android/mail/compose/FromAddressSpinnerAdapter.java
+++ b/src/com/android/mail/compose/FromAddressSpinnerAdapter.java
@@ -77,10 +77,14 @@
ReplyFromAccount fromItem = getItem(position);
int res = fromItem.isCustomFrom ? R.layout.custom_from_item : R.layout.from_item;
View fromEntry = convertView == null ? getInflater().inflate(res, null) : convertView;
- ((TextView) fromEntry.findViewById(R.id.spinner_account_name)).setText(fromItem.name);
if (fromItem.isCustomFrom) {
+ ((TextView) fromEntry.findViewById(R.id.spinner_account_name)).setText(fromItem.name);
+
((TextView) fromEntry.findViewById(R.id.spinner_account_address))
.setText(formatAddress(fromItem.address));
+ } else {
+ ((TextView) fromEntry.findViewById(R.id.spinner_account_name))
+ .setText(fromItem.address);
}
return fromEntry;
}
@@ -91,11 +95,14 @@
int res = fromItem.isCustomFrom ? R.layout.custom_from_dropdown_item
: R.layout.from_dropdown_item;
View fromEntry = getInflater().inflate(res, null);
- TextView acctName = ((TextView) fromEntry.findViewById(R.id.spinner_account_name));
- acctName.setText(fromItem.name);
if (fromItem.isCustomFrom) {
+ ((TextView) fromEntry.findViewById(R.id.spinner_account_name))
+ .setText(fromItem.name);
((TextView) fromEntry.findViewById(R.id.spinner_account_address))
.setText(formatAddress(fromItem.address));
+ } else {
+ ((TextView) fromEntry.findViewById(R.id.spinner_account_name))
+ .setText(fromItem.address);
}
return fromEntry;
}
diff --git a/src/com/android/mail/providers/Account.java b/src/com/android/mail/providers/Account.java
index b9d46a8..b9f21c1 100644
--- a/src/com/android/mail/providers/Account.java
+++ b/src/com/android/mail/providers/Account.java
@@ -712,9 +712,7 @@
}
// add the main account address
- // TODO: name is incorrect here, use senderName once FromAddressSpinner is fixed
- // b/11292541
- mReplyFroms.add(new ReplyFromAccount(this, uri, getEmailAddress(), name,
+ mReplyFroms.add(new ReplyFromAccount(this, uri, getEmailAddress(), getSenderName(),
getEmailAddress(), false /* isDefault */, false /* isCustom */));
if (!TextUtils.isEmpty(accountFromAddresses)) {