Skip to content

Commit 03b1888

Browse files
committed
fix(tabs-list-mode): layout switch
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 705908c commit 03b1888

6 files changed

Lines changed: 56 additions & 36 deletions

File tree

app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -655,20 +655,26 @@ public long getPhotoSearchTimestamp() {
655655
}
656656

657657
/**
658-
* Get preference value for a folder. If folder is not set itself, it finds an ancestor that is set.
658+
* Retrieves a preference value for a specific folder.
659+
* <p>
660+
* If the folder itself does not have the preference set, the method searches up its ancestor hierarchy
661+
* until a value is found. If no value is found in any ancestor, the provided {@code defaultValue} is returned.
662+
* <p>
663+
* Anonymous users or {@code null} folders will always return the {@code defaultValue}.
659664
*
660-
* @param context Context object.
661-
* @param preferenceName Name of the preference to lookup.
662-
* @param folder Folder.
663-
* @param defaultValue Fallback value in case no ancestor is set.
664-
* @return Preference value
665+
* @param context The Android context.
666+
* @param user The user for whom the preference is queried.
667+
* @param preferenceName The name/key of the preference to look up.
668+
* @param folder The folder to check.
669+
* @param defaultValue The value to return if no preference is set in the folder hierarchy.
670+
* @return The preference value for the folder, or {@code defaultValue} if none is set.
665671
*/
666672
private static String getFolderPreference(final Context context,
667673
final User user,
668674
final String preferenceName,
669675
final OCFile folder,
670676
final String defaultValue) {
671-
if (user.isAnonymous()) {
677+
if (user.isAnonymous() || folder == null) {
672678
return defaultValue;
673679
}
674680

app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ private void onNavigationItemClicked(final MenuItem menuItem) {
548548
}
549549

550550
closeDrawer();
551+
setupHomeSearchToolbarWithSortAndListButtons();
552+
updateActionBarTitleAndHomeButton(null);
551553
} else if (itemId == R.id.nav_favorites) {
552554
openFavoritesTab();
553555
} else if (itemId == R.id.nav_gallery) {
@@ -621,6 +623,8 @@ private void handleBottomNavigationViewClicks() {
621623
fda.browseToRoot();
622624
}
623625
EventBus.getDefault().post(new ChangeMenuEvent());
626+
setupHomeSearchToolbarWithSortAndListButtons();
627+
updateActionBarTitleAndHomeButton(null);
624628
} else if (menuItemId == R.id.nav_favorites) {
625629
openFavoritesTab();
626630
} else if (menuItemId == R.id.nav_assistant && !(this instanceof ComposeActivity)) {
@@ -697,8 +701,7 @@ private void resetFileDepth() {
697701
}
698702
}
699703

700-
protected void openSharedTab() {
701-
resetFileDepth();
704+
private void openSharedTab() {
702705
resetOnlyPersonalAndOnDevice();
703706
SearchEvent searchEvent = new SearchEvent("", SearchRemoteOperation.SearchType.SHARED_FILTER);
704707
launchActivityForSearch(searchEvent, R.id.nav_shared);

app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,6 @@ class FileDisplayActivity :
27642764

27652765
listOfFilesFragment?.setCurrentSearchType(event)
27662766
updateActionBarTitleAndHomeButton(null)
2767-
// listOfFilesFragment?.setActionBarTitle()
27682767
}
27692768

27702769
@Subscribe(threadMode = ThreadMode.MAIN)

app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,13 @@ open class ExtendedListFragment :
765765
}
766766
}
767767

768-
protected fun setGridSwitchButton() {
768+
protected fun setLayoutSwitchButton() {
769+
setLayoutSwitchButton(isGridEnabled)
770+
}
771+
772+
protected fun setLayoutSwitchButton(isGrid: Boolean) {
769773
mSwitchGridViewButton?.let {
770-
if (isGridEnabled) {
774+
if (isGrid) {
771775
it.setContentDescription(getString(R.string.action_switch_list_view))
772776
it.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_view_list)
773777
} else {

app/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
134134
}
135135
}
136136

137-
setGridSwitchButton();
137+
setLayoutSwitchButton();
138138

139139
if (mSwitchGridViewButton != null) {
140140
mSwitchGridViewButton.setOnClickListener(v -> {
@@ -143,7 +143,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
143143
} else {
144144
switchToGridView();
145145
}
146-
setGridSwitchButton();
146+
setLayoutSwitchButton();
147147
});
148148
}
149149

app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
435435
} else {
436436
setGridAsPreferred();
437437
}
438-
setGridSwitchButton();
438+
setLayoutSwitchButton();
439439
});
440440
}
441441

@@ -1577,17 +1577,9 @@ public void updateOCFile(@NonNull OCFile file) {
15771577
}
15781578

15791579
private void updateLayout() {
1580-
// decide grid vs list view
1581-
if (isGridViewPreferred(mFile)) {
1582-
switchToGridView();
1583-
} else {
1584-
switchToListView();
1585-
}
1586-
1580+
setLayoutViewMode();
15871581
updateSortButton();
1588-
if (mSwitchGridViewButton != null) {
1589-
setGridSwitchButton();
1590-
}
1582+
setLayoutSwitchButton();
15911583

15921584
setFabVisible(!mHideFab);
15931585
slideHideBottomBehaviourForBottomNavigationView(!mHideFab);
@@ -1623,14 +1615,34 @@ public void sortFiles(FileSortOrder sortOrder) {
16231615
}
16241616

16251617
/**
1626-
* Determines if user set folder to grid or list view. If folder is not set itself, it finds a parent that is set
1627-
* (at least root is set).
1618+
* Determines whether a folder should be displayed in grid or list view.
1619+
* <p>
1620+
* The preference is checked for the given folder. If the folder itself does not have a preference set,
1621+
* it will fall back to its parent folder recursively until a preference is found (root folder is always set).
1622+
* Additionally, if a search event is active and is of type {@code SHARED_FILTER}, grid view is disabled.
16281623
*
1629-
* @param folder Folder to check or null for root folder
1630-
* @return 'true' is folder should be shown in grid mode, 'false' if list mode is preferred.
1624+
* @param folder The folder to check, or {@code null} to refer to the root folder.
1625+
* @return {@code true} if the folder should be displayed in grid mode, {@code false} if list mode is preferred.
16311626
*/
1632-
public boolean isGridViewPreferred(@Nullable OCFile folder) {
1633-
return FOLDER_LAYOUT_GRID.equals(preferences.getFolderLayout(folder));
1627+
private boolean isGridViewPreferred(@Nullable OCFile folder) {
1628+
if (searchEvent != null) {
1629+
return (searchEvent.toSearchType() != SHARED_FILTER) &&
1630+
FOLDER_LAYOUT_GRID.equals(preferences.getFolderLayout(folder));
1631+
} else {
1632+
return FOLDER_LAYOUT_GRID.equals(preferences.getFolderLayout(folder));
1633+
}
1634+
}
1635+
1636+
private void setLayoutViewMode() {
1637+
boolean isGrid = isGridViewPreferred(mFile);
1638+
1639+
if (isGrid) {
1640+
switchToGridView();
1641+
} else {
1642+
switchToListView();
1643+
}
1644+
1645+
setLayoutSwitchButton(isGrid);
16341646
}
16351647

16361648
public void setListAsPreferred() {
@@ -1861,11 +1873,7 @@ protected void handleSearchEvent(SearchEvent event) {
18611873

18621874
new Handler(Looper.getMainLooper()).post(() -> {
18631875
updateSortButton();
1864-
if (isGridViewPreferred(mFile) && !isGridEnabled()) {
1865-
switchToGridView();
1866-
} else if (!isGridViewPreferred(mFile) && isGridEnabled()) {
1867-
switchToListView();
1868-
}
1876+
setLayoutViewMode();
18691877
});
18701878

18711879
final User currentUser = accountManager.getUser();

0 commit comments

Comments
 (0)