Skip to content

Commit

Permalink
Add getNthParent
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 7a67f37 commit dbffa19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,22 @@ OCFile getFileById(long id) {
return null;
}

public OCFile getNthParent(OCFile file, int n) {
if (file == null || !file.isFolder() || n < 1) {
return null;
}

OCFile currentFile = file;
for (int i = 0; i < n; i++) {
currentFile = getFileById(currentFile.getParentId());
if (currentFile == null) {
return null;
}
}

return currentFile;
}

public @Nullable
OCFile getFileByLocalPath(String path) {
FileEntity fileEntity = fileDao.getFileByLocalPath(path, user.getAccountName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,13 +1029,9 @@ public void onBackPressed() {
} else {
browseUp(listOfFiles);

if (parentDir != null) {
OCFile grandParentDir = fileDataStorageManager.getFileById(parentDir.getParentId());
if (grandParentDir != null) {
if (grandParentDir.isRoot()) {
filterCurrentDirectory();
}
}
OCFile secondParentDir = fileDataStorageManager.getNthParent(currentDir, 2);
if (secondParentDir != null && secondParentDir.isRoot()) {
filterCurrentDirectory();
}
}
} else {
Expand Down

0 comments on commit dbffa19

Please sign in to comment.