Skip to content

Commit

Permalink
Use search event
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Sep 23, 2024
1 parent 41aa4f2 commit 11fe1ac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,6 @@ 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
4 changes: 0 additions & 4 deletions app/src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,6 @@ 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 @@ -1017,35 +1017,14 @@ public void onBackPressed() {
return;
}

// FIXME browse up to root
listOfFiles.filterCurrentDirectory(menuItemId);
browseUp(listOfFiles);

if (menuItemId == R.id.nav_favorites || menuItemId == R.id.nav_shared) {
OCFile parentDir = fileDataStorageManager.getFileById(currentDir.getParentId());
if (parentDir != null && parentDir.isRoot()) {
openDrawer();
} else {
browseUp(listOfFiles);

OCFile secondParentDir = fileDataStorageManager.getNthParent(currentDir, 2);
if (secondParentDir != null && secondParentDir.isRoot()) {
filterCurrentDirectory();
setActionBarLeadingIcon(R.drawable.ic_menu);
}
}
}
} else {
popBack();
}
}

private void filterCurrentDirectory() {
if (menuItemId == R.id.nav_favorites) {
filterFavoritesFiles(menuItemId);
} else if (menuItemId == R.id.nav_shared) {
startSharedSearch(menuItemId);
}
}

private void browseUp(OCFileListFragment listOfFiles) {
listOfFiles.onBrowseUp();
setFile(listOfFiles.getCurrentFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1114,10 +1114,6 @@ private void fileOnItemClick(OCFile file) {
@Override
@OptIn(markerClass = UnstableApi.class)
public void onItemClicked(OCFile file) {
if (mContainerActivity != null && mContainerActivity instanceof FileActivity fileActivity) {
fileActivity.setActionBarLeadingIcon(R.drawable.ic_arrow_back);
}

if (getCommonAdapter() != null && getCommonAdapter().isMultiSelect()) {
toggleItemToCheckedList(file);
} else {
Expand Down Expand Up @@ -1974,6 +1970,20 @@ public void onRefresh() {
}
}

public void filterCurrentDirectory(int menuItemId) {
if (menuItemId == R.id.nav_favorites || menuItemId == R.id.nav_shared) {
setSearchFragment(true);

if (menuItemId == R.id.nav_favorites) {
searchEvent = new SearchEvent("", SearchRemoteOperation.SearchType.FAVORITE_SEARCH);
currentSearchType = FAVORITE_SEARCH;
} else {
searchEvent = new SearchEvent("", SearchRemoteOperation.SearchType.SHARED_FILTER);
currentSearchType = SHARED_FILTER;
}
}
}

public void setSearchFragment(boolean searchFragment) {
this.searchFragment = searchFragment;
}
Expand Down

0 comments on commit 11fe1ac

Please sign in to comment.