Changing wording for empty contact list

Bug: 3338546
Change-Id: Ic9b9e5a7dda12e03252c80d116fff2460c86b348
diff --git a/res/layout/search_header.xml b/res/layout/search_header.xml
index 1eaa4e0..ab8ec53 100644
--- a/res/layout/search_header.xml
+++ b/res/layout/search_header.xml
@@ -34,6 +34,7 @@
         android:id="@+id/progress"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:layout_toRightOf="@id/totalContactsText"
         style="?android:attr/progressBarStyleSmall"
         android:layout_alignParentRight="true"
         android:layout_centerVertical="true"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b0dffca..d09904a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -307,8 +307,8 @@
         <item quantity="other"><xliff:g id="count">%d</xliff:g> contacts with phone numbers</item>
     </plurals>
 
-    <!-- Displayed at the top of the contacts showing the zero as total number of contacts visible when "Only contacts with phones" is selected -->
-    <string name="listTotalPhoneContactsZero">No visible contacts with phone numbers</string>
+    <!-- Displayed at the top of the contacts showing the zero as total number of contacts visible when "Only contacts with phones" is selected [CHAR LIMIT=64]-->
+    <string name="listTotalPhoneContactsZero">No contacts with phone numbers</string>
 
     <!-- Displayed at the top of the contacts showing the total number of contacts visible when "Only contacts with phones" not selected -->
     <plurals name="listTotalAllContacts">
@@ -316,8 +316,17 @@
         <item quantity="other"><xliff:g id="count">%d</xliff:g> contacts</item>
     </plurals>
 
-    <!-- Displayed at the top of the contacts showing the zero total number of contacts visible when "Only contacts with phones" not selected -->
-    <string name="listTotalAllContactsZero">No visible contacts</string>
+    <!-- Displayed at the top of the contacts showing the zero total number of contacts visible when "All contacts" is selected  [CHAR LIMIT=64]-->
+    <string name="listTotalAllContactsZero">No contacts</string>
+
+    <!-- Displayed at the top of the contacts showing the zero total number of contacts visible when "Custom" is selected  [CHAR LIMIT=64]-->
+    <string name="listTotalAllContactsZeroCustom">No visible contacts</string>
+
+    <!-- Displayed at the top of the contacts showing the zero total number of contacts visible when starred contact list is selected  [CHAR LIMIT=64]-->
+    <string name="listTotalAllContactsZeroStarred">No starred contacts</string>
+
+    <!-- Displayed at the top of the contacts showing the zero total number of contacts visible when a group or account is selected  [CHAR LIMIT=64]-->
+    <string name="listTotalAllContactsZeroGroup">No contacts in <xliff:g id="name" example="Friends">%s</xliff:g></string>
 
     <!-- Displayed at the top of the contacts showing the total number of contacts found when "Only contacts with phones" not selected -->
     <plurals name="listFoundAllContacts">
diff --git a/src/com/android/contacts/list/ContactEntryListFragment.java b/src/com/android/contacts/list/ContactEntryListFragment.java
index e61232a..763c094 100644
--- a/src/com/android/contacts/list/ContactEntryListFragment.java
+++ b/src/com/android/contacts/list/ContactEntryListFragment.java
@@ -892,17 +892,6 @@
         }
     }
 
-    // TODO: fix PluralRules to handle zero correctly and use Resources.getQuantityText directly
-    public String getQuantityText(int count, int zeroResourceId, int pluralResourceId) {
-        if (count == 0) {
-            return mContext.getString(zeroResourceId);
-        } else {
-            String format = mContext.getResources()
-                    .getQuantityText(pluralResourceId, count).toString();
-            return String.format(format, count);
-        }
-    }
-
     protected void setEmptyText(int resourceId) {
         TextView empty = (TextView) getEmptyView().findViewById(R.id.emptyText);
         empty.setText(mContext.getText(resourceId));
diff --git a/src/com/android/contacts/list/ContactListFilter.java b/src/com/android/contacts/list/ContactListFilter.java
index 5cb96b4..c53859b 100644
--- a/src/com/android/contacts/list/ContactListFilter.java
+++ b/src/com/android/contacts/list/ContactListFilter.java
@@ -43,6 +43,7 @@
     private static final String KEY_GROUP_ID = "filter.groupId";
     private static final String KEY_GROUP_SOURCE_ID = "filter.groupSourceId";
     private static final String KEY_GROUP_READ_ONLY = "filter.groupReadOnly";
+    private static final String KEY_GROUP_TITLE = "filter.groupTitle";
 
     public int filterType;
     public String accountType;
@@ -177,6 +178,7 @@
             .putLong(KEY_GROUP_ID, filter == null ? -1 : filter.groupId)
             .putString(KEY_GROUP_SOURCE_ID, filter == null ? null : filter.groupSourceId)
             .putBoolean(KEY_GROUP_READ_ONLY, filter == null ? false : filter.groupReadOnly)
+            .putString(KEY_GROUP_TITLE, filter == null ? null : filter.title)
             .apply();
     }
 
@@ -192,6 +194,7 @@
         filter.groupId = prefs.getLong(KEY_GROUP_ID, -1);
         filter.groupSourceId = prefs.getString(KEY_GROUP_SOURCE_ID, null);
         filter.groupReadOnly = prefs.getBoolean(KEY_GROUP_READ_ONLY, false);
+        filter.title = prefs.getString(KEY_GROUP_TITLE, "group");
         return filter;
     }
 
diff --git a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
index 7b04562..f95c4af 100644
--- a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
+++ b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
@@ -95,15 +95,38 @@
     protected void showCount(int partitionIndex, Cursor data) {
         if (!isSearchMode() && data != null) {
             int count = data.getCount();
-            // TODO
-            // if (contactsListActivity.mDisplayOnlyPhones) {
-            // text = contactsListActivity.getQuantityText(count,
-            // R.string.listTotalPhoneContactsZero,
-            // R.plurals.listTotalPhoneContacts);
-            TextView textView = (TextView)mCounterHeaderView.findViewById(R.id.totalContactsText);
-            String text = getQuantityText(count, R.string.listTotalAllContactsZero,
-                    R.plurals.listTotalAllContacts);
-            textView.setText(text);
+            TextView textView = (TextView) mCounterHeaderView.findViewById(R.id.totalContactsText);
+            if (count != 0) {
+                String format = getResources().getQuantityText(
+                        R.plurals.listTotalAllContacts, count).toString();
+                textView.setText(String.format(format, count));
+            } else {
+                ContactListFilter filter = getFilter();
+                int filterType = filter != null ? filter.filterType
+                        : ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS;
+                switch (filterType) {
+                    case ContactListFilter.FILTER_TYPE_ACCOUNT:
+                        textView.setText(getString(
+                                R.string.listTotalAllContactsZeroGroup, filter.accountName));
+                        break;
+                    case ContactListFilter.FILTER_TYPE_GROUP:
+                        textView.setText(
+                                getString(R.string.listTotalAllContactsZeroGroup, filter.title));
+                        break;
+                    case ContactListFilter.FILTER_TYPE_WITH_PHONE_NUMBERS_ONLY:
+                        textView.setText(R.string.listTotalPhoneContactsZero);
+                        break;
+                    case ContactListFilter.FILTER_TYPE_STARRED:
+                        textView.setText(R.string.listTotalAllContactsZeroStarred);
+                        break;
+                    case ContactListFilter.FILTER_TYPE_CUSTOM:
+                        textView.setText(R.string.listTotalAllContactsZeroCustom);
+                        break;
+                    default:
+                        textView.setText(R.string.listTotalAllContactsZero);
+                        break;
+                }
+            }
         } else {
             ContactListAdapter adapter = getAdapter();
             if (adapter == null) {