diff --git a/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java b/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java index 3d6330923ec6..682e211fcd5a 100644 --- a/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java +++ b/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java @@ -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. + *
+ * 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. + *
+ * 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; } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index f26047d581a3..c8dc3a114b21 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -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) { @@ -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)) { @@ -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); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt index f973795ebf23..2fa70a55eb61 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt @@ -2764,7 +2764,6 @@ class FileDisplayActivity : listOfFilesFragment?.setCurrentSearchType(event) updateActionBarTitleAndHomeButton(null) - // listOfFilesFragment?.setActionBarTitle() } @Subscribe(threadMode = ThreadMode.MAIN) diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt b/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt index 54bbad82e7ab..f009f632380f 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt @@ -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 { diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java index 26b3f8de3d6a..14d5cbc9cf6e 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java @@ -134,7 +134,7 @@ public void onActivityCreated(Bundle savedInstanceState) { } } - setGridSwitchButton(); + setLayoutSwitchButton(); if (mSwitchGridViewButton != null) { mSwitchGridViewButton.setOnClickListener(v -> { @@ -143,7 +143,7 @@ public void onActivityCreated(Bundle savedInstanceState) { } else { switchToGridView(); } - setGridSwitchButton(); + setLayoutSwitchButton(); }); } diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 2f2766ac6f83..15dfb62e92d1 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -433,7 +433,7 @@ public void onActivityCreated(Bundle savedInstanceState) { } else { setGridAsPreferred(); } - setGridSwitchButton(); + setLayoutSwitchButton(); }); } @@ -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); @@ -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. + *
+ * 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() { @@ -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();