public boolean areAllPartitionsEmpty() { int count = getPartitionCount(); for (int i = 0; i < count; i++) { if (!isPartitionEmpty(i)) { return false; } } return true; }
public boolean isLoading() { int count = getPartitionCount(); for (int i = 0; i < count; i++) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition && ((DirectoryPartition) partition).isLoading()) { return true; } } return false; }
protected int getPartitionByDirectoryId(long id) { int count = getPartitionCount(); for (int i = 0; i < count; i++) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition) { if (((DirectoryPartition)partition).getDirectoryId() == id) { return i; } } } return -1; }
protected DirectoryPartition getDirectoryById(long id) { int count = getPartitionCount(); for (int i = 0; i < count; i++) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition) { final DirectoryPartition directoryPartition = (DirectoryPartition) partition; if (directoryPartition.getDirectoryId() == id) { return directoryPartition; } } } return null; }
@Override public void clearPartitions() { int count = getPartitionCount(); for (int i = 0; i < count; i++) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition) { DirectoryPartition directoryPartition = (DirectoryPartition)partition; directoryPartition.setStatus(DirectoryPartition.STATUS_NOT_LOADED); } } super.clearPartitions(); }
/** * Remove all directories after the default directory. This is typically used when contacts * list screens are asked to exit the search mode and thus need to remove all remote directory * results for the search. * * This code assumes that the default directory and directories before that should not be * deleted (e.g. Join screen has "suggested contacts" directory before the default director, * and we should not remove the directory). */ public void removeDirectoriesAfterDefault() { final int partitionCount = getPartitionCount(); for (int i = partitionCount - 1; i >= 0; i--) { final Partition partition = getPartition(i); if ((partition instanceof DirectoryPartition) && ((DirectoryPartition) partition).getDirectoryId() == Directory.DEFAULT) { break; } else { removePartition(i); } } }
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(); } }
/** * 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); } }
int count = getPartitionCount(); for (int i = count; --i >= 0; ) { Partition partition = getPartition(i);
protected void startLoading() { if (mAdapter == null) { // The method was called before the fragment was started return; } configureAdapter(); int partitionCount = mAdapter.getPartitionCount(); for (int i = 0; i < partitionCount; i++) { Partition partition = mAdapter.getPartition(i); if (partition instanceof DirectoryPartition) { DirectoryPartition directoryPartition = (DirectoryPartition)partition; if (directoryPartition.getStatus() == DirectoryPartition.STATUS_NOT_LOADED) { if (directoryPartition.isPriorityDirectory() || !mLoadPriorityDirectoriesOnly) { startLoadingDirectoryPartition(i); } } } else { getLoaderManager().initLoader(i, null, this); } } // Next time this method is called, we should start loading non-priority directories mLoadPriorityDirectoriesOnly = false; }
@Override public void changeCursor(int partitionIndex, Cursor cursor) { if (partitionIndex >= getPartitionCount()) { // There is no partition for this data return; } Partition partition = getPartition(partitionIndex); if (partition instanceof DirectoryPartition) { ((DirectoryPartition)partition).setStatus(DirectoryPartition.STATUS_LOADED); } if (mDisplayPhotos && mPhotoLoader != null && isPhotoSupported(partitionIndex)) { mPhotoLoader.refreshCache(); } super.changeCursor(partitionIndex, cursor); if (isSectionHeaderDisplayEnabled() && partitionIndex == getIndexedPartition()) { updateIndexer(cursor); } // When the cursor changes, cancel any pending asynchronous photo loads. mPhotoLoader.cancelPendingRequests(mFragmentRootView); }