diff options
Diffstat (limited to 'java/com/android/contacts/common/list')
5 files changed, 61 insertions, 39 deletions
diff --git a/java/com/android/contacts/common/list/ContactEntryListAdapter.java b/java/com/android/contacts/common/list/ContactEntryListAdapter.java index 064214ef2..7335297e0 100644 --- a/java/com/android/contacts/common/list/ContactEntryListAdapter.java +++ b/java/com/android/contacts/common/list/ContactEntryListAdapter.java @@ -40,6 +40,7 @@ import com.android.contacts.common.compat.DirectoryCompat; import com.android.contacts.common.util.SearchUtil; import com.android.dialer.common.LogUtil; import com.android.dialer.compat.CompatUtils; +import com.android.dialer.configprovider.ConfigProviderBindings; import com.android.dialer.logging.InteractionEvent; import com.android.dialer.logging.Logger; import java.util.HashSet; @@ -55,7 +56,6 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter { */ public static final boolean LOCAL_INVISIBLE_DIRECTORY_ENABLED = false; - private static final String TAG = "ContactEntryListAdapter"; private int mDisplayOrder; private int mSortOrder; @@ -82,6 +82,8 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter { private ContactListFilter mFilter; private boolean mDarkTheme = false; + public static final int SUGGESTIONS_LOADER_ID = 0; + /** Resource used to provide header-text for default filter. */ private CharSequence mDefaultFilterHeaderText; @@ -130,9 +132,22 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter { } protected void addPartitions() { + if (ConfigProviderBindings.get(getContext()).getBoolean("p13n_ranker_should_enable", false)) { + addPartition(createSuggestionsDirectoryPartition()); + } addPartition(createDefaultDirectoryPartition()); } + protected DirectoryPartition createSuggestionsDirectoryPartition() { + DirectoryPartition partition = new DirectoryPartition(true, true); + partition.setDirectoryId(SUGGESTIONS_LOADER_ID); + partition.setDirectoryType(getContext().getString(R.string.contact_suggestions)); + partition.setPriorityDirectory(true); + partition.setPhotoSupported(true); + partition.setLabel(getContext().getString(R.string.local_suggestions_search_label)); + return partition; + } + protected DirectoryPartition createDefaultDirectoryPartition() { DirectoryPartition partition = new DirectoryPartition(true, true); partition.setDirectoryId(Directory.DEFAULT); @@ -245,6 +260,11 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter { } else { mUpperCaseQueryString = SearchUtil.cleanStartAndEndOfSearchQuery(queryString.toUpperCase()); } + + // Enable default partition header if in search mode (including zero-suggest). + if (mQueryString != null) { + setDefaultPartitionHeader(true); + } } public String getUpperCaseQueryString() { @@ -356,9 +376,9 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter { if (cursor.getCount() == 0) { // Directory table must have at least local directory, without which this adapter will // enter very weird state. - LogUtil.e( - TAG, - "Directory search loader returned an empty cursor, which implies we have " + LogUtil.i( + "ContactEntryListAdapter.changeDirectories", + "directory search loader returned an empty cursor, which implies we have " + "no directory entries.", new RuntimeException()); return; @@ -531,22 +551,27 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter { return false; } - /** Changes visibility parameters for the default directory partition. */ - public void configureDefaultPartition(boolean showIfEmpty, boolean hasHeader) { + /** Configures visibility parameters for the directory partitions. */ + public void configurePartitionsVisibility(boolean isInSearchMode) { + for (int i = 0; i < getPartitionCount(); i++) { + setShowIfEmpty(i, false); + setHasHeader(i, isInSearchMode); + } + } + + // Sets header for the default partition. + private void setDefaultPartitionHeader(boolean setHeader) { + // Iterate in reverse here to ensure the first DEFAULT directory has header. + // Both "Suggestions" and "All Contacts" directories have DEFAULT id. int defaultPartitionIndex = -1; - int count = getPartitionCount(); - for (int i = 0; i < count; i++) { + for (int i = getPartitionCount() - 1; i >= 0; i--) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition && ((DirectoryPartition) partition).getDirectoryId() == Directory.DEFAULT) { defaultPartitionIndex = i; - break; } } - if (defaultPartitionIndex != -1) { - setShowIfEmpty(defaultPartitionIndex, showIfEmpty); - setHasHeader(defaultPartitionIndex, hasHeader); - } + setHasHeader(defaultPartitionIndex, setHeader); } @Override diff --git a/java/com/android/contacts/common/list/ContactEntryListFragment.java b/java/com/android/contacts/common/list/ContactEntryListFragment.java index 146986f75..04658be89 100644 --- a/java/com/android/contacts/common/list/ContactEntryListFragment.java +++ b/java/com/android/contacts/common/list/ContactEntryListFragment.java @@ -47,6 +47,7 @@ import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.preference.ContactsPreferences; import com.android.contacts.common.util.ContactListViewUtils; import com.android.dialer.common.LogUtil; +import com.android.dialer.performancereport.PerformanceReport; import java.lang.ref.WeakReference; import java.util.Locale; @@ -440,6 +441,11 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter return; } + // Return for non-"Suggestions" if on the zero-suggest screen. + if (TextUtils.isEmpty(mQueryString) && partitionIndex > 0) { + return; + } + mAdapter.changeCursor(partitionIndex, data); setProfileHeader(); @@ -571,7 +577,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter // should be cleaned up on exiting the search mode. mAdapter.removeDirectoriesAfterDefault(); } - mAdapter.configureDefaultPartition(false, flag); + mAdapter.configurePartitionsVisibility(flag); } if (mListView != null) { @@ -675,22 +681,16 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter boolean searchMode = isSearchMode(); mAdapter.setSearchMode(searchMode); - mAdapter.configureDefaultPartition(false, searchMode); + mAdapter.configurePartitionsVisibility(searchMode); mAdapter.setPhotoLoader(mPhotoManager); mListView.setAdapter(mAdapter); - - if (!isSearchMode()) { - mListView.setFocusableInTouchMode(true); - mListView.requestFocus(); - } - return mView; } protected void onCreateView(LayoutInflater inflater, ViewGroup container) { mView = inflateView(inflater, container); - mListView = (ListView) mView.findViewById(android.R.id.list); + mListView = mView.findViewById(android.R.id.list); if (mListView == null) { throw new RuntimeException( "Your content must have a ListView whose id attribute is " + "'android.R.id.list'"); @@ -769,6 +769,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter @Override public void onScrollStateChanged(AbsListView view, int scrollState) { + PerformanceReport.recordScrollStateChange(scrollState); if (scrollState == OnScrollListener.SCROLL_STATE_FLING) { mPhotoManager.pause(); } else if (isPhotoLoaderEnabled()) { diff --git a/java/com/android/contacts/common/list/ContactListItemView.java b/java/com/android/contacts/common/list/ContactListItemView.java index 5a2749178..91abe4c4f 100644 --- a/java/com/android/contacts/common/list/ContactListItemView.java +++ b/java/com/android/contacts/common/list/ContactListItemView.java @@ -330,19 +330,19 @@ public class ContactListItemView extends ViewGroup implements SelectionBoundsAdj int description; OnClickListener onClickListener; if (action == CALL_AND_SHARE) { - drawable = getContext().getResources().getDrawable(R.drawable.ic_phone_attach); + drawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_phone_attach); drawable.setAutoMirrored(true); description = R.string.description_search_call_and_share; onClickListener = v -> listener.onCallAndShareIconClicked(position); } else if (action == VIDEO && mSupportVideoCall) { drawable = - getContext().getResources().getDrawable(R.drawable.quantum_ic_videocam_vd_theme_24); + ContextCompat.getDrawable(getContext(), R.drawable.quantum_ic_videocam_vd_theme_24); drawable.setAutoMirrored(true); description = R.string.description_search_video_call; onClickListener = v -> listener.onVideoCallIconClicked(position); } else if (action == LIGHTBRINGER) { drawable = - getContext().getResources().getDrawable(R.drawable.quantum_ic_videocam_vd_theme_24); + ContextCompat.getDrawable(getContext(), R.drawable.quantum_ic_videocam_vd_theme_24); drawable.setAutoMirrored(true); description = R.string.description_search_video_call; onClickListener = v -> listener.onLightbringerIconClicked(position); diff --git a/java/com/android/contacts/common/list/PhoneNumberListAdapter.java b/java/com/android/contacts/common/list/PhoneNumberListAdapter.java index 65e6f2da2..d1118c3c7 100644 --- a/java/com/android/contacts/common/list/PhoneNumberListAdapter.java +++ b/java/com/android/contacts/common/list/PhoneNumberListAdapter.java @@ -69,7 +69,6 @@ public class PhoneNumberListAdapter extends ContactEntryListAdapter { // A list of extended directories to add to the directories from the database private final List<DirectoryPartition> mExtendedDirectories; private final CharSequence mUnknownNameText; - private final boolean mIsPresenceEnabled; protected final boolean mIsImsVideoEnabled; // Extended directories will have ID's that are higher than any of the id's from the database, @@ -88,8 +87,9 @@ public class PhoneNumberListAdapter extends ContactEntryListAdapter { PhoneDirectoryExtenderAccessor.get(mContext).getExtendedDirectories(mContext); int videoCapabilities = CallUtil.getVideoCallingAvailability(context); - mIsImsVideoEnabled = CallUtil.isVideoEnabled(context); - mIsPresenceEnabled = (videoCapabilities & CallUtil.VIDEO_CALLING_PRESENCE) != 0; + mIsImsVideoEnabled = + CallUtil.isVideoEnabled(context) + && (videoCapabilities & CallUtil.VIDEO_CALLING_PRESENCE) != 0; } @Override @@ -351,14 +351,8 @@ public class PhoneNumberListAdapter extends ContactEntryListAdapter { } final DirectoryPartition directory = (DirectoryPartition) getPartition(partition); - - // If the first partition does not have a header, then all subsequent partitions' - // getPositionForPartition returns an index off by 1. - int partitionOffset = 0; - if (partition > 0 && !getPartition(0).getHasHeader()) { - partitionOffset = 1; - } - position += getPositionForPartition(partition) + partitionOffset; + // All sections have headers, so scroll position is off by 1. + position += getPositionForPartition(partition) + 1; bindPhoneNumber(view, cursor, directory.isDisplayNumber(), position); } @@ -397,8 +391,8 @@ public class PhoneNumberListAdapter extends ContactEntryListAdapter { int carrierPresence = cursor.getInt(PhoneQuery.CARRIER_PRESENCE); boolean isPresent = (carrierPresence & Phone.CARRIER_PRESENCE_VT_CAPABLE) != 0; - boolean isVideoIconShown = mIsImsVideoEnabled && (!mIsPresenceEnabled || isPresent); - if (isVideoIconShown) { + boolean showViewIcon = mIsImsVideoEnabled && isPresent; + if (showViewIcon) { action = ContactListItemView.VIDEO; } } diff --git a/java/com/android/contacts/common/list/PhoneNumberPickerFragment.java b/java/com/android/contacts/common/list/PhoneNumberPickerFragment.java index 79e670010..de7903e83 100644 --- a/java/com/android/contacts/common/list/PhoneNumberPickerFragment.java +++ b/java/com/android/contacts/common/list/PhoneNumberPickerFragment.java @@ -42,6 +42,7 @@ import com.android.dialer.enrichedcall.EnrichedCallManager; import com.android.dialer.lightbringer.LightbringerComponent; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; +import com.android.dialer.performancereport.PerformanceReport; import com.android.dialer.protos.ProtoParsers; import java.util.Set; import org.json.JSONException; @@ -91,6 +92,7 @@ public class PhoneNumberPickerFragment extends ContactEntryListFragment<ContactE @Override public void onLightbringerIconClicked(int position) { + PerformanceReport.stopRecording(); String phoneNumber = getPhoneNumber(position); Intent intent = LightbringerComponent.get(getContext()) @@ -282,7 +284,7 @@ public class PhoneNumberPickerFragment extends ContactEntryListFragment<ContactE && data != null && !data.isClosed() && data.getCount() > 0 - && loader.getId() != -1) { // skip invalid directory ID of -1 + && loader.getId() == 0) { // only re-rank if a suggestions loader with id of 0. data = mCursorReranker.rerankCursor(data); } super.onLoadFinished(loader, data); |