diff --git a/changelog/unreleased/4894 b/changelog/unreleased/4894 new file mode 100644 index 00000000000..6658770f4be --- /dev/null +++ b/changelog/unreleased/4894 @@ -0,0 +1,7 @@ +Bugfix: Recalculate grid mode after rotation + +The grid mode column count has been recalculated after device rotation, keeping +file tiles in the correct layout for the new orientation. + +https://github.com/owncloud/android/issues/4884 +https://github.com/owncloud/android/pull/4894 diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt index cbcc73f3cad..f3d3c5eefdc 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt @@ -335,6 +335,7 @@ class MainFileListFragment : Fragment(), override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) updateConfigDependentSizes() + updateRecyclerViewLayoutForCurrentViewType() } private fun updateConfigDependentSizes() { @@ -998,17 +999,24 @@ class MainFileListFragment : Fragment(), } override fun onViewTypeListener(viewType: ViewType) { + this.viewType = viewType binding.optionsLayout.viewTypeSelected = viewType if (viewType == ViewType.VIEW_TYPE_LIST) { mainFileListViewModel.setListModeAsPreferred() - layoutManager.spanCount = 1 } else { mainFileListViewModel.setGridModeAsPreferred() - layoutManager.spanCount = ColumnQuantity(requireContext(), R.layout.grid_item).calculateNoOfColumns() } + updateRecyclerViewLayoutForCurrentViewType() + } + + private fun updateRecyclerViewLayoutForCurrentViewType() { + layoutManager.spanCount = when (viewType) { + ViewType.VIEW_TYPE_LIST -> 1 + ViewType.VIEW_TYPE_GRID -> ColumnQuantity(requireContext(), R.layout.grid_item).calculateNoOfColumns() + } fileListAdapter.notifyItemRangeChanged(0, fileListAdapter.itemCount) } @@ -1675,4 +1683,3 @@ class MainFileListFragment : Fragment(), } } } -