/** * Loads the directory partition. */ protected void loadDirectoryPartition(int partitionIndex, DirectoryPartition partition) { Bundle args = new Bundle(); args.putLong(DIRECTORY_ID_ARG_KEY, partition.getDirectoryId()); getLoaderManager().restartLoader(partitionIndex, args, this); }
private void startLoadingDirectoryPartition(int partitionIndex) { DirectoryPartition partition = (DirectoryPartition)mAdapter.getPartition(partitionIndex); partition.setStatus(DirectoryPartition.STATUS_LOADING); long directoryId = partition.getDirectoryId(); if (mForceLoad) { if (directoryId == Directory.DEFAULT) { loadDirectoryPartition(partitionIndex, partition); } else { loadDirectoryPartitionDelayed(partitionIndex, partition); } } else { Bundle args = new Bundle(); args.putLong(DIRECTORY_ID_ARG_KEY, directoryId); getLoaderManager().initLoader(partitionIndex, args, this); } }
@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); } } }
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; }
/** * 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); } } }