Skip to content
Open
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
6 changes: 6 additions & 0 deletions changelog/unreleased/4884
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Grid mode after rotation

Grid mode now recalculates its column count after device rotation, keeping
file tiles in the correct layout for the new orientation.

https://github.com/owncloud/android/issues/4884
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ class MainFileListFragment : Fragment(),
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
updateConfigDependentSizes()
if (::viewType.isInitialized && viewType == ViewType.VIEW_TYPE_GRID) {
updateRecyclerViewLayoutForCurrentViewType()
}
}

private fun updateConfigDependentSizes() {
Expand Down Expand Up @@ -998,17 +1001,30 @@ 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() {
if (!::layoutManager.isInitialized || !::fileListAdapter.isInitialized) {
return
}

layoutManager.spanCount = when (viewType) {
ViewType.VIEW_TYPE_LIST -> 1
ViewType.VIEW_TYPE_GRID -> ColumnQuantity(requireContext(), R.layout.grid_item).calculateNoOfColumns()
}
layoutManager.invalidateSpanAssignments()
binding.recyclerViewMainFileList.requestLayout()
fileListAdapter.notifyItemRangeChanged(0, fileListAdapter.itemCount)
}

Expand Down Expand Up @@ -1675,4 +1691,3 @@ class MainFileListFragment : Fragment(),
}
}
}