Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -655,20 +655,26 @@ public long getPhotoSearchTimestamp() {
}

/**
* Get preference value for a folder. If folder is not set itself, it finds an ancestor that is set.
* Retrieves a preference value for a specific folder.
* <p>
* If the folder itself does not have the preference set, the method searches up its ancestor hierarchy
* until a value is found. If no value is found in any ancestor, the provided {@code defaultValue} is returned.
* <p>
* Anonymous users or {@code null} folders will always return the {@code defaultValue}.
*
* @param context Context object.
* @param preferenceName Name of the preference to lookup.
* @param folder Folder.
* @param defaultValue Fallback value in case no ancestor is set.
* @return Preference value
* @param context The Android context.
* @param user The user for whom the preference is queried.
* @param preferenceName The name/key of the preference to look up.
* @param folder The folder to check.
* @param defaultValue The value to return if no preference is set in the folder hierarchy.
* @return The preference value for the folder, or {@code defaultValue} if none is set.
*/
private static String getFolderPreference(final Context context,
final User user,
final String preferenceName,
final OCFile folder,
final String defaultValue) {
if (user.isAnonymous()) {
if (user.isAnonymous() || folder == null) {
return defaultValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ private void onNavigationItemClicked(final MenuItem menuItem) {
}

closeDrawer();
setupHomeSearchToolbarWithSortAndListButtons();
updateActionBarTitleAndHomeButton(null);
} else if (itemId == R.id.nav_favorites) {
openFavoritesTab();
} else if (itemId == R.id.nav_gallery) {
Expand Down Expand Up @@ -618,6 +620,8 @@ private void handleBottomNavigationViewClicks() {
fda.browseToRoot();
}
EventBus.getDefault().post(new ChangeMenuEvent());
setupHomeSearchToolbarWithSortAndListButtons();
updateActionBarTitleAndHomeButton(null);
} else if (menuItemId == R.id.nav_favorites) {
openFavoritesTab();
} else if (menuItemId == R.id.nav_assistant && !(this instanceof ComposeActivity)) {
Expand Down Expand Up @@ -692,8 +696,7 @@ private void resetFileDepth() {
}
}

protected void openSharedTab() {
resetFileDepth();
private void openSharedTab() {
resetOnlyPersonalAndOnDevice();
SearchEvent searchEvent = new SearchEvent("", SearchRemoteOperation.SearchType.SHARED_FILTER);
launchActivityForSearch(searchEvent, R.id.nav_shared);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2764,7 +2764,6 @@ class FileDisplayActivity :

listOfFilesFragment?.setCurrentSearchType(event)
updateActionBarTitleAndHomeButton(null)
// listOfFilesFragment?.setActionBarTitle()
}

@Subscribe(threadMode = ThreadMode.MAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,13 @@ open class ExtendedListFragment :
}
}

protected fun setGridSwitchButton() {
protected fun setLayoutSwitchButton() {
setLayoutSwitchButton(isGridEnabled)
}

protected fun setLayoutSwitchButton(isGrid: Boolean) {
mSwitchGridViewButton?.let {
if (isGridEnabled) {
if (isGrid) {
it.setContentDescription(getString(R.string.action_switch_list_view))
it.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_view_list)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
}
}

setGridSwitchButton();
setLayoutSwitchButton();

if (mSwitchGridViewButton != null) {
mSwitchGridViewButton.setOnClickListener(v -> {
Expand All @@ -143,7 +143,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
} else {
switchToGridView();
}
setGridSwitchButton();
setLayoutSwitchButton();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
} else {
setGridAsPreferred();
}
setGridSwitchButton();
setLayoutSwitchButton();
});
}

Expand Down Expand Up @@ -1570,17 +1570,9 @@ public void updateOCFile(@NonNull OCFile file) {
}

private void updateLayout() {
// decide grid vs list view
if (isGridViewPreferred(mFile)) {
switchToGridView();
} else {
switchToListView();
}

setLayoutViewMode();
updateSortButton();
if (mSwitchGridViewButton != null) {
setGridSwitchButton();
}
setLayoutSwitchButton();

setFabVisible(!mHideFab);
slideHideBottomBehaviourForBottomNavigationView(!mHideFab);
Expand Down Expand Up @@ -1616,14 +1608,34 @@ public void sortFiles(FileSortOrder sortOrder) {
}

/**
* Determines if user set folder to grid or list view. If folder is not set itself, it finds a parent that is set
* (at least root is set).
* Determines whether a folder should be displayed in grid or list view.
* <p>
* The preference is checked for the given folder. If the folder itself does not have a preference set,
* it will fall back to its parent folder recursively until a preference is found (root folder is always set).
* Additionally, if a search event is active and is of type {@code SHARED_FILTER}, grid view is disabled.
*
* @param folder Folder to check or null for root folder
* @return 'true' is folder should be shown in grid mode, 'false' if list mode is preferred.
* @param folder The folder to check, or {@code null} to refer to the root folder.
* @return {@code true} if the folder should be displayed in grid mode, {@code false} if list mode is preferred.
*/
public boolean isGridViewPreferred(@Nullable OCFile folder) {
return FOLDER_LAYOUT_GRID.equals(preferences.getFolderLayout(folder));
private boolean isGridViewPreferred(@Nullable OCFile folder) {
if (searchEvent != null) {
return (searchEvent.toSearchType() != SHARED_FILTER) &&
FOLDER_LAYOUT_GRID.equals(preferences.getFolderLayout(folder));
} else {
return FOLDER_LAYOUT_GRID.equals(preferences.getFolderLayout(folder));
}
}

private void setLayoutViewMode() {
boolean isGrid = isGridViewPreferred(mFile);

if (isGrid) {
switchToGridView();
} else {
switchToListView();
}

setLayoutSwitchButton(isGrid);
}

public void setListAsPreferred() {
Expand Down Expand Up @@ -1854,11 +1866,7 @@ protected void handleSearchEvent(SearchEvent event) {

new Handler(Looper.getMainLooper()).post(() -> {
updateSortButton();
if (isGridViewPreferred(mFile) && !isGridEnabled()) {
switchToGridView();
} else if (!isGridViewPreferred(mFile) && isGridEnabled()) {
switchToListView();
}
setLayoutViewMode();
});

final User currentUser = accountManager.getUser();
Expand Down
Loading