summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrandon Maxwell <maxwelb@google.com>2015-10-28 15:29:58 -0700
committerBrandon Maxwell <maxwelb@google.com>2015-10-30 15:03:42 -0700
commit774321318c2b779d9edaf02e9a7e10ef2a8cad90 (patch)
tree3f2c853871d1241f91f4cc951dde71a93987241c /src
parent7323d631ba028ead01371d7d00abaeba3e3ef56e (diff)
Speed dial respects display order prefs
- Speed dial names change based on whether user wants first name first or last name first - Sort order preferece is respected if ContactEntries have conflicting pinned positions - Added tests for PhoneFavoritesTileAdapter.arrangeContactsByPinnedPosition method Bug:19364093 Change-Id: I81214abce572e297cc21fcb4f5a901ecad958380
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dialer/list/PhoneFavoriteSquareTileView.java5
-rw-r--r--src/com/android/dialer/list/PhoneFavoritesTileAdapter.java48
-rw-r--r--src/com/android/dialer/list/SpeedDialFragment.java4
3 files changed, 43 insertions, 14 deletions
diff --git a/src/com/android/dialer/list/PhoneFavoriteSquareTileView.java b/src/com/android/dialer/list/PhoneFavoriteSquareTileView.java
index 05780c66a..c12bed737 100644
--- a/src/com/android/dialer/list/PhoneFavoriteSquareTileView.java
+++ b/src/com/android/dialer/list/PhoneFavoriteSquareTileView.java
@@ -95,6 +95,11 @@ public class PhoneFavoriteSquareTileView extends PhoneFavoriteTileView {
setMeasuredDimension(width, height);
}
+ @Override
+ protected String getNameForView(ContactEntry contactEntry) {
+ return contactEntry.getPreferredDisplayName();
+ }
+
public ContactEntry getContactEntry() {
return mContactEntry;
}
diff --git a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
index e957c8321..cd4c10b59 100644
--- a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
+++ b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
@@ -38,13 +38,13 @@ import android.util.LongSparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
-import android.widget.FrameLayout;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.ContactTileLoaderFactory;
import com.android.contacts.common.list.ContactEntry;
import com.android.contacts.common.list.ContactTileAdapter.DisplayType;
import com.android.contacts.common.list.ContactTileView;
+import com.android.contacts.common.preference.ContactsPreferences;
import com.android.dialer.R;
import java.util.ArrayList;
@@ -70,6 +70,7 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements
private Context mContext;
private Resources mResources;
+ private ContactsPreferences mContactsPreferences;
/** Contact data stored in cache. This is used to populate the associated view. */
protected ArrayList<ContactEntry> mContactEntries = null;
@@ -92,7 +93,8 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements
protected int mIdIndex;
protected int mLookupIndex;
protected int mPhotoUriIndex;
- protected int mNameIndex;
+ protected int mNamePrimaryIndex;
+ protected int mNameAlternativeIndex;
protected int mPresenceIndex;
protected int mStatusIndex;
@@ -124,9 +126,17 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements
public int compare(ContactEntry lhs, ContactEntry rhs) {
return ComparisonChain.start()
.compare(lhs.pinned, rhs.pinned)
- .compare(lhs.name, rhs.name)
+ .compare(getPreferredSortName(lhs), getPreferredSortName(rhs))
.result();
}
+
+ private String getPreferredSortName(ContactEntry contactEntry) {
+ if (mContactsPreferences.getSortOrder() == ContactsPreferences.SORT_ORDER_PRIMARY
+ || TextUtils.isEmpty(contactEntry.nameAlternative)) {
+ return contactEntry.namePrimary;
+ }
+ return contactEntry.nameAlternative;
+ }
};
public interface OnDataSetChangedForAnimationListener {
@@ -140,6 +150,7 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements
mListener = listener;
mContext = context;
mResources = context.getResources();
+ mContactsPreferences = new ContactsPreferences(mContext);
mNumFrequents = 0;
mContactEntries = new ArrayList<ContactEntry>();
@@ -172,19 +183,26 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements
*/
protected void bindColumnIndices() {
mIdIndex = ContactTileLoaderFactory.CONTACT_ID;
- mLookupIndex = ContactTileLoaderFactory.LOOKUP_KEY;
- mPhotoUriIndex = ContactTileLoaderFactory.PHOTO_URI;
- mNameIndex = ContactTileLoaderFactory.DISPLAY_NAME;
+ mNamePrimaryIndex = ContactTileLoaderFactory.DISPLAY_NAME;
+ mNameAlternativeIndex = ContactTileLoaderFactory.DISPLAY_NAME_ALTERNATIVE;
mStarredIndex = ContactTileLoaderFactory.STARRED;
- mPresenceIndex = ContactTileLoaderFactory.CONTACT_PRESENCE;
- mStatusIndex = ContactTileLoaderFactory.CONTACT_STATUS;
-
+ mPhotoUriIndex = ContactTileLoaderFactory.PHOTO_URI;
+ mLookupIndex = ContactTileLoaderFactory.LOOKUP_KEY;
mPhoneNumberIndex = ContactTileLoaderFactory.PHONE_NUMBER;
mPhoneNumberTypeIndex = ContactTileLoaderFactory.PHONE_NUMBER_TYPE;
mPhoneNumberLabelIndex = ContactTileLoaderFactory.PHONE_NUMBER_LABEL;
- mIsDefaultNumberIndex = ContactTileLoaderFactory.IS_DEFAULT_NUMBER;
mPinnedIndex = ContactTileLoaderFactory.PINNED;
- mContactIdIndex = ContactTileLoaderFactory.CONTACT_ID_FOR_DATA;
+ mContactIdIndex = ContactTileLoaderFactory.CONTACT_ID;
+
+
+ mPresenceIndex = ContactTileLoaderFactory.CONTACT_PRESENCE;
+ mStatusIndex = ContactTileLoaderFactory.CONTACT_STATUS;
+ mIsDefaultNumberIndex = ContactTileLoaderFactory.IS_DEFAULT_NUMBER;
+ }
+
+ public void refreshContactsPreferences() {
+ mContactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY);
+ mContactsPreferences.refreshValue(ContactsPreferences.SORT_ORDER_KEY);
}
/**
@@ -261,15 +279,19 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements
final String photoUri = cursor.getString(mPhotoUriIndex);
final String lookupKey = cursor.getString(mLookupIndex);
final int pinned = cursor.getInt(mPinnedIndex);
- final String name = cursor.getString(mNameIndex);
+ final String name = cursor.getString(mNamePrimaryIndex);
+ final String nameAlternative = cursor.getString(mNameAlternativeIndex);
final boolean isStarred = cursor.getInt(mStarredIndex) > 0;
final boolean isDefaultNumber = cursor.getInt(mIsDefaultNumberIndex) > 0;
final ContactEntry contact = new ContactEntry();
contact.id = id;
- contact.name = (!TextUtils.isEmpty(name)) ? name :
+ contact.namePrimary = (!TextUtils.isEmpty(name)) ? name :
+ mResources.getString(R.string.missing_name);
+ contact.nameAlternative = (!TextUtils.isEmpty(nameAlternative)) ? nameAlternative :
mResources.getString(R.string.missing_name);
+ contact.nameDisplayOrder = mContactsPreferences.getDisplayOrder();
contact.photoUri = (photoUri != null ? Uri.parse(photoUri) : null);
contact.lookupKey = lookupKey;
contact.lookupUri = ContentUris.withAppendedId(
diff --git a/src/com/android/dialer/list/SpeedDialFragment.java b/src/com/android/dialer/list/SpeedDialFragment.java
index 64129cdea..e30f40633 100644
--- a/src/com/android/dialer/list/SpeedDialFragment.java
+++ b/src/com/android/dialer/list/SpeedDialFragment.java
@@ -202,7 +202,9 @@ public class SpeedDialFragment extends Fragment implements OnItemClickListener,
public void onResume() {
Trace.beginSection(TAG + " onResume");
super.onResume();
-
+ if (mContactTileAdapter != null) {
+ mContactTileAdapter.refreshContactsPreferences();
+ }
if (PermissionsUtil.hasContactsPermissions(getActivity())) {
if (getLoaderManager().getLoader(LOADER_ID_CONTACT_TILE) == null) {
getLoaderManager().initLoader(LOADER_ID_CONTACT_TILE, null,