Fixup formatting of custom from displayed addresses.
Add an address field to replyfromaddress and customfromaddress.
Change-Id: I01d81d5db32b6ea27286de4d5ceaaebc185708ba
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 484d6a2..dfae210 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -180,6 +180,8 @@
<string name="quoted_text_label">Quote text</string>
<!-- Button for including inline responses. [CHAR LIMIT=25] -->
<string name="respond_inline">Respond inline</string>
+ <!-- Format string for email addresses -->
+ <string name="formatted_email_address" translate="false"><<xliff:g id="email">%1$s</xliff:g>></string>
<!-- Attachments -->
<!-- Size unit, displayed in a button next to an attachment [CHAR LIMIT=5]-->
diff --git a/src/com/android/mail/compose/ComposeActivity.java b/src/com/android/mail/compose/ComposeActivity.java
index a28ca84..de2ce13 100644
--- a/src/com/android/mail/compose/ComposeActivity.java
+++ b/src/com/android/mail/compose/ComposeActivity.java
@@ -597,7 +597,7 @@
}
if (mReplyFromAccount == null) {
mReplyFromAccount = new ReplyFromAccount(mAccount, mAccount.uri, mAccount.name,
- mAccount.name, true, false);
+ mAccount.name, mAccount.name, true, false);
}
mFromSpinner.setCurrentAccount(mReplyFromAccount);
@@ -700,7 +700,8 @@
return from;
}
}
- return new ReplyFromAccount(account, account.uri, account.name, account.name, true, false);
+ return new ReplyFromAccount(account, account.uri, account.name, account.name, account.name,
+ true, false);
}
private ReplyFromAccount getReplyFromAccountFromDraft(Account account, Message msg) {
@@ -709,7 +710,7 @@
List<ReplyFromAccount> replyFromAccounts = mFromSpinner.getReplyFromAccounts();
if (TextUtils.equals(account.name, sender)) {
replyFromAccount = new ReplyFromAccount(mAccount, mAccount.uri, mAccount.name,
- mAccount.name, true, false);
+ mAccount.name, mAccount.name, true, false);
} else {
for (ReplyFromAccount fromAccount : replyFromAccounts) {
if (TextUtils.equals(fromAccount.name, sender)) {
diff --git a/src/com/android/mail/compose/FromAddressSpinner.java b/src/com/android/mail/compose/FromAddressSpinner.java
index ca10727..21ab29c 100644
--- a/src/com/android/mail/compose/FromAddressSpinner.java
+++ b/src/com/android/mail/compose/FromAddressSpinner.java
@@ -138,7 +138,7 @@
return froms;
}
ReplyFromAccount replyFrom = new ReplyFromAccount(account, account.uri, account.name,
- account.name, false, false);
+ account.name, account.name, false, false);
if (replyFrom != null) {
froms.add(replyFrom);
}
diff --git a/src/com/android/mail/compose/FromAddressSpinnerAdapter.java b/src/com/android/mail/compose/FromAddressSpinnerAdapter.java
index 9a6bacb..512daa6 100644
--- a/src/com/android/mail/compose/FromAddressSpinnerAdapter.java
+++ b/src/com/android/mail/compose/FromAddressSpinnerAdapter.java
@@ -16,6 +16,8 @@
package com.android.mail.compose;
import android.content.Context;
+import android.text.TextUtils;
+import android.text.util.Rfc822Tokenizer;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -36,6 +38,7 @@
public class FromAddressSpinnerAdapter extends ArrayAdapter<ReplyFromAccount> {
private static final int FROM = 0;
private static final int CUSTOM_FROM = 1;
+ private static String sFormatString;
public static int REAL_ACCOUNT = 2;
@@ -47,6 +50,7 @@
public FromAddressSpinnerAdapter(Context context) {
super(context, R.layout.from_item, R.id.spinner_account_name);
+ sFormatString = getContext().getString(R.string.formatted_email_address);
}
protected LayoutInflater getInflater() {
@@ -91,11 +95,18 @@
acctName.setText(fromItem.name);
if (fromItem.isCustomFrom) {
((TextView) fromEntry.findViewById(R.id.spinner_account_address))
- .setText(fromItem.address);
+ .setText(formatAddress(fromItem.address));
}
return fromEntry;
}
+ private CharSequence formatAddress(String address) {
+ if (TextUtils.isEmpty(address)) {
+ return "";
+ }
+ return String.format(sFormatString, Rfc822Tokenizer.tokenize(address)[0].getAddress());
+ }
+
public void addAccounts(List<ReplyFromAccount> replyFromAccounts) {
// Get the position of the current account
for (ReplyFromAccount account : replyFromAccounts) {
diff --git a/src/com/android/mail/providers/ReplyFromAccount.java b/src/com/android/mail/providers/ReplyFromAccount.java
index 0412249..d7c636a 100644
--- a/src/com/android/mail/providers/ReplyFromAccount.java
+++ b/src/com/android/mail/providers/ReplyFromAccount.java
@@ -17,7 +17,6 @@
package com.android.mail.providers;
import android.net.Uri;
-import android.os.Parcelable;
import com.android.mail.utils.LogUtils;
import com.android.mail.utils.Utils;
@@ -26,7 +25,6 @@
import org.json.JSONObject;
import java.io.Serializable;
-import java.util.regex.Pattern;
public class ReplyFromAccount implements Serializable {
private static final long serialVersionUID = 1L;
@@ -34,6 +32,7 @@
private static final String LOG_TAG = new LogUtils().getLogTag();
private static final String BASE_ACCOUNT_URI = "baseAccountUri";
private static final String ADDRESS_STRING = "address";
+ private static final String REPLY_TO = "replyTo";
private static final String NAME_STRING = "name";
private static final String IS_DEFAULT = "isDefault";
private static final String IS_CUSTOM_FROM = "isCustom";
@@ -41,16 +40,18 @@
public Account account;
Uri baseAccountUri;
public String address;
+ public String replyTo;
public String name;
public boolean isDefault;
public boolean isCustomFrom;
public ReplyFromAccount(Account account, Uri baseAccountUri, String address, String name,
- boolean isDefault, boolean isCustom) {
+ String replyTo, boolean isDefault, boolean isCustom) {
this.account = account;
this.baseAccountUri = baseAccountUri;
this.address = address;
this.name = name;
+ this.replyTo = replyTo;
this.isDefault = isDefault;
this.isCustomFrom = isCustom;
}
@@ -61,6 +62,7 @@
json.put(BASE_ACCOUNT_URI, baseAccountUri);
json.put(ADDRESS_STRING, address);
json.put(NAME_STRING, name);
+ json.put(REPLY_TO, replyTo);
json.put(IS_DEFAULT, isDefault);
json.put(IS_CUSTOM_FROM, isCustomFrom);
} catch (JSONException e) {
@@ -75,10 +77,11 @@
Uri uri = Utils.getValidUri(json.getString(BASE_ACCOUNT_URI));
String addressString = json.getString(ADDRESS_STRING);
String nameString = json.getString(NAME_STRING);
+ String replyTo = json.getString(REPLY_TO);
boolean isDefault = json.getBoolean(IS_DEFAULT);
boolean isCustomFrom = json.getBoolean(IS_CUSTOM_FROM);
replyFromAccount = new ReplyFromAccount(account, uri, addressString, nameString,
- isDefault, isCustomFrom);
+ replyTo, isDefault, isCustomFrom);
} catch (JSONException e) {
LogUtils.wtf(LOG_TAG, e, "Could not deserialize replyfromaccount");
}
diff --git a/src/com/android/mail/providers/protos/mock/MockUiProvider.java b/src/com/android/mail/providers/protos/mock/MockUiProvider.java
index f60c6c0..d0bed71 100644
--- a/src/com/android/mail/providers/protos/mock/MockUiProvider.java
+++ b/src/com/android/mail/providers/protos/mock/MockUiProvider.java
@@ -315,9 +315,9 @@
JSONArray replyFroms = new JSONArray();
ArrayList<ReplyFromAccount> list = new ArrayList<ReplyFromAccount>();
list.add(new ReplyFromAccount(null, Uri.parse(accountUri), "customAddress1@custom.com",
- "Custom1", false, true));
+ "customAddress2@custom.com", "Custom1", false, true));
list.add(new ReplyFromAccount(null, Uri.parse(accountUri), "customAddress2@custom.com",
- "Custom2", false, true));
+ "customAddress2@custom.com", "Custom2", false, true));
for (ReplyFromAccount a : list) {
replyFroms.put(a.serialize());
}