diff --git a/app/src/main/java/com/owncloud/android/datamodel/OCFile.java b/app/src/main/java/com/owncloud/android/datamodel/OCFile.java index 3884eefa9003..454b39cad85d 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/OCFile.java +++ b/app/src/main/java/com/owncloud/android/datamodel/OCFile.java @@ -701,6 +701,10 @@ public long getFileId() { return this.fileId; } + public boolean isRoot() { + return isFolder() && getFileId() == 1; + } + public long getParentId() { return this.parentId; } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index bf66e8f92e09..0abe87cfe371 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1006,24 +1006,38 @@ private Boolean isRootDirectory() { @Override public void onBackPressed() { final boolean isDrawerOpen = isDrawerOpen(); - final boolean isSearchOpen = isSearchOpen(); - - final Fragment leftFragment = getLeftFragment(); + if (isDrawerOpen) { + super.onBackPressed(); + return; + } + final boolean isSearchOpen = isSearchOpen(); if (isSearchOpen) { resetSearchAction(); - } else if (isDrawerOpen) { - super.onBackPressed(); - } else if (leftFragment instanceof OCFileListFragment listOfFiles) { + return; + } - // all closed + final Fragment leftFragment = getLeftFragment(); + if (leftFragment instanceof OCFileListFragment listOfFiles) { OCFile currentDir = getCurrentDir(); + OCFile parentDir = fileDataStorageManager.getFileById(currentDir.getParentId()); + if (isRoot(currentDir)) { finish(); - return; + } else if (parentDir != null && parentDir.isRoot()) { + openDrawer(); + } else { + browseUp(listOfFiles); + + if (parentDir != null) { + OCFile grandParentDir = fileDataStorageManager.getFileById(parentDir.getParentId()); + if (grandParentDir != null) { + if (grandParentDir.isRoot()) { + filterCurrentDirectory(); + } + } + } } - browseUp(listOfFiles); - filterCurrentDirectory(); } else { popBack(); }