Ensure appended emails have a comma separator

There was some code that checked for comma placement, but that is no
longer necessary. Instead, we verify that the email address has a
trailing comma (plus optional whitespace), and if not, we append a
comma and space, to ensure the address is later chipified correctly.

Bug: 8272316
Change-Id: Ifbb1bae466e3ae15c39d6b90a4bc22edc72a096f
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java
index 7be2f52..551245c 100644
--- a/chips/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java
@@ -111,6 +111,9 @@
 
     private static final char COMMIT_CHAR_SPACE = ' ';
 
+    private static final String SEPARATOR = String.valueOf(COMMIT_CHAR_COMMA)
+            + String.valueOf(COMMIT_CHAR_SPACE);
+
     private static final String TAG = "RecipientEditTextView";
 
     private static int DISMISS = "dismiss".hashCode();
@@ -371,22 +374,17 @@
         super.append(text, start, end);
         if (!TextUtils.isEmpty(text) && TextUtils.getTrimmedLength(text) > 0) {
             String displayString = text.toString();
-            int separatorPos = displayString.lastIndexOf(COMMIT_CHAR_COMMA);
-            // Verify that the separator pos is not within ""; if it is, look
-            // past the closing quote. If there is no comma past ", this string
-            // will resolve to an error chip.
-            if (separatorPos > -1) {
-                String parseDisplayString = displayString.substring(separatorPos);
-                int endQuotedTextPos = parseDisplayString.indexOf(NAME_WRAPPER_CHAR);
-                if (endQuotedTextPos > separatorPos) {
-                    separatorPos = parseDisplayString.lastIndexOf(COMMIT_CHAR_COMMA,
-                            endQuotedTextPos);
-                }
+
+            if (!displayString.trim().endsWith(String.valueOf(COMMIT_CHAR_COMMA))) {
+                // We have no separator, so we should add it
+                super.append(SEPARATOR, 0, SEPARATOR.length());
+                displayString += SEPARATOR;
             }
+
             if (!TextUtils.isEmpty(displayString)
                     && TextUtils.getTrimmedLength(displayString) > 0) {
                 mPendingChipsCount++;
-                mPendingChips.add(text.toString());
+                mPendingChips.add(displayString);
             }
         }
         // Put a message on the queue to make sure we ALWAYS handle pending