- public boolean onNavigationItemSelected(int itemPosition, long itemId) {
- if (itemPosition != 0) {
- String targetPath = "";
- for (int i=itemPosition; i < mDirectories.getCount() - 1; i++) {
- targetPath = mDirectories.getItem(i) + OCFile.PATH_SEPARATOR + targetPath;
- }
- targetPath = OCFile.PATH_SEPARATOR + targetPath;
- OCFile targetFolder = getStorageManager().getFileByPath(targetPath);
- if (targetFolder != null) {
- browseTo(targetFolder);
- }
-
- // the next operation triggers a new call to this method, but it's necessary to
- // ensure that the name exposed in the action bar is the current directory when the
- // user selected it in the navigation list
- if (getSupportActionBar().getNavigationMode() == ActionBar.NAVIGATION_MODE_LIST && itemPosition != 0)
- getSupportActionBar().setSelectedNavigationItem(0);
- }
- return true;
- }
-
- public void browseTo(OCFile folder) {
- if (folder == null || !folder.isFolder()) {
- throw new IllegalArgumentException("Trying to browse to invalid folder " + folder);
- }
- MoveFileListFragment listOfFiles = getListOfFilesFragment();
- if (listOfFiles != null) {
- setNavigationListWithFolder(folder);
- listOfFiles.listDirectory(folder);
- setFile(listOfFiles.getCurrentFile());
- startSyncFolderOperation(folder);
- } else {
- Log_OC.e(TAG, "Unexpected null when accessing list fragment");
- }
- }
-
- @Override
- public void onBackPressed() {
- MoveFileListFragment listOfFiles = getListOfFilesFragment();
- if (listOfFiles != null) { // should never be null, indeed
- if (mDirectories.getCount() <= 1) {
- finish();
- return;
- }
- int levelsUp = listOfFiles.onBrowseUp();
- for (int i=0; i < levelsUp && mDirectories.getCount() > 1 ; i++) {
- popDirname();
- }
- }
- if (listOfFiles != null) { // should never be null, indeed
- setFile(listOfFiles.getCurrentFile());
- }
- }
-
- private void updateNavigationElementsInActionBar(OCFile chosenFile) {
- ActionBar actionBar = getSupportActionBar();
- if (chosenFile == null) {
- // only list of files - set for browsing through folders
- OCFile currentDir = getCurrentDir();
- boolean noRoot = (currentDir != null && currentDir.getParentId() != 0);
- actionBar.setDisplayHomeAsUpEnabled(noRoot);
- actionBar.setDisplayShowTitleEnabled(!noRoot);
- if (!noRoot) {
- actionBar.setTitle(getString(R.string.default_display_name_for_root_folder));
- }
- actionBar.setNavigationMode(!noRoot ? ActionBar.NAVIGATION_MODE_STANDARD : ActionBar.NAVIGATION_MODE_LIST);
- actionBar.setListNavigationCallbacks(mDirectories, this); // assuming mDirectories is updated