/** * Marks all partitions as "loading" */ public void onDataReload() { boolean notify = false; int count = getPartitionCount(); for (int i = 0; i < count; i++) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition) { DirectoryPartition directoryPartition = (DirectoryPartition)partition; if (!directoryPartition.isLoading()) { notify = true; } directoryPartition.setStatus(DirectoryPartition.STATUS_NOT_LOADED); } } if (notify) { notifyDataSetChanged(); } }
/** * Changes visibility parameters for the default directory partition. */ public void configureDefaultPartition(boolean showIfEmpty, boolean hasHeader) { int defaultPartitionIndex = -1; int count = getPartitionCount(); for (int i = 0; i < count; 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); } }
protected void addPartitions() { addPartition(createDefaultDirectoryPartition()); }
public ContactEntryListAdapter(Context context) { super(context); setDefaultFilterHeaderText(R.string.local_search_label); addPartitions(); }
@Override protected void bindView(View itemView, int partition, Cursor cursor, int position) { final ContactListItemView view = (ContactListItemView) itemView; view.setIsSectionHeaderEnabled(isSectionHeaderDisplayEnabled()); bindWorkProfileIcon(view, partition); }
long id = cursor.getLong(idColumnIndex); directoryIds.add(id); if (getPartitionByDirectoryId(id) == -1) { DirectoryPartition partition = new DirectoryPartition(false, true); partition.setDirectoryId(id); partition.setPhotoSupported(photoSupport == Directory.PHOTO_SUPPORT_THUMBNAIL_ONLY || photoSupport == Directory.PHOTO_SUPPORT_FULL); addPartition(partition); int count = getPartitionCount(); for (int i = count; --i >= 0; ) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition) { long id = ((DirectoryPartition)partition).getDirectoryId(); if (!directoryIds.contains(id)) { removePartition(i); invalidate(); notifyDataSetChanged();
/** * Enter/exit search mode. This is method is tightly related to the current query, and should * only be called by {@link #setQueryString}. * * Also note this method doesn't call {@link #reloadData()}; {@link #setQueryString} does it. */ protected void setSearchMode(boolean flag) { if (mSearchMode != flag) { mSearchMode = flag; setSectionHeaderDisplayEnabled(!mSearchMode); if (!flag) { mDirectoryListStatus = STATUS_NOT_LOADED; getLoaderManager().destroyLoader(DIRECTORY_LOADER_ID); } if (mAdapter != null) { mAdapter.setSearchMode(flag); mAdapter.clearPartitions(); if (!flag) { // If we are switching from search to regular display, remove all directory // partitions after default one, assuming they are remote directories which // should be cleaned up on exiting the search mode. mAdapter.removeDirectoriesAfterDefault(); } mAdapter.configureDefaultPartition(false, flag); } if (mListView != null) { mListView.setFastScrollEnabled(!flag); } } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { onCreateView(inflater, container); boolean searchMode = isSearchMode(); mAdapter.setSearchMode(searchMode); mAdapter.configureDefaultPartition(false, searchMode); mAdapter.setPhotoLoader(mPhotoManager); mListView.setAdapter(mAdapter); if (!isSearchMode()) { mListView.setFocusableInTouchMode(true); mListView.requestFocus(); } return mView; }
@Override protected void setSearchMode(boolean flag) { super.setSearchMode(flag); // This hides the "All contacts with phone numbers" header in the search fragment final ContactEntryListAdapter adapter = getAdapter(); if (adapter != null) { adapter.setHasHeader(0, false); } }
@Override public void onChangeFilteredNumberUndo() { getAdapter().notifyDataSetChanged(); }
protected void onPartitionLoaded(int partitionIndex, Cursor data) { if (partitionIndex >= mAdapter.getPartitionCount()) { // When we get unsolicited data, ignore it. This could happen // when we are switching from search mode to the default mode. return; } mAdapter.changeCursor(partitionIndex, data); setProfileHeader(); if (!isLoading()) { completeRestoreInstanceState(); } }
public void changeCursor(Cursor cursor) { changeCursor(0, cursor); }
public void setEnabled(boolean enabled) { if (mEnabled != enabled) { mEnabled = enabled; if (mAdapter != null) { if (mEnabled) { reloadData(); } else { mAdapter.clearPartitions(); } } } }
super.changeDirectories(cursor); if (getDirectorySearchMode() == DirectoryListLoader.SEARCH_MODE_NONE) { return;
@Override protected void bindView(View itemView, int partition, Cursor cursor, int position) { super.bindView(itemView, partition, cursor, position); ContactListItemView view = (ContactListItemView)itemView;
super.onStart(); if (isSearchMode()) { getAdapter().setHasHeader(0, false);
@Override protected void startLoading() { if (getActivity() == null) { return; } if (PermissionsUtil.hasContactsPermissions(getActivity())) { super.startLoading(); } else if (TextUtils.isEmpty(getQueryString())) { // Clear out any existing call shortcuts. final DialerPhoneNumberListAdapter adapter = (DialerPhoneNumberListAdapter) getAdapter(); adapter.disableAllShortcuts(); } else { // The contact list is not going to change (we have no results since permissions are // denied), but the shortcuts might because of the different query, so update the // list. getAdapter().notifyDataSetChanged(); } setupEmptyView(); }
@Override public void changeCursor(int partitionIndex, Cursor cursor) { super.changeCursor(partitionIndex, cursor); // Check if a profile exists if (cursor != null && cursor.moveToFirst()) { setProfileExists(cursor.getInt(ContactQuery.CONTACT_IS_USER_PROFILE) == 1); } }
@Override public void onStop() { super.onStop(); mContactsPrefs.unregisterChangeListener(); mAdapter.clearPartitions(); }
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (!mEnabled) { return; } int loaderId = loader.getId(); if (loaderId == DIRECTORY_LOADER_ID) { mDirectoryListStatus = STATUS_LOADED; mAdapter.changeDirectories(data); startLoading(); } else { onPartitionLoaded(loaderId, data); if (isSearchMode()) { int directorySearchMode = getDirectorySearchMode(); if (directorySearchMode != DirectoryListLoader.SEARCH_MODE_NONE) { if (mDirectoryListStatus == STATUS_NOT_LOADED) { mDirectoryListStatus = STATUS_LOADING; getLoaderManager().initLoader(DIRECTORY_LOADER_ID, null, this); } else { startLoading(); } } } else { mDirectoryListStatus = STATUS_NOT_LOADED; getLoaderManager().destroyLoader(DIRECTORY_LOADER_ID); } } }