Skip to content

Commit

Permalink
Fix onBackPress behaviour
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Sep 5, 2024
1 parent 23b534d commit 7a67f37
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@ public long getFileId() {
return this.fileId;
}

public boolean isRoot() {
return isFolder() && getFileId() == 1;
}

public long getParentId() {
return this.parentId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 7a67f37

Please sign in to comment.