add a null check at grid spacing decorator

This commit is contained in:
tibbi 2021-01-18 23:25:22 +01:00
parent efe26e9c58
commit 146cb1a052

View file

@ -11,7 +11,7 @@ class GridSpacingItemDecoration(val spanCount: Int, val spacing: Int, val isScro
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) { override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val position = parent.getChildAdapterPosition(view) val position = parent.getChildAdapterPosition(view)
val medium = items[position] as? Medium ?: return val medium = items.getOrNull(position) as? Medium ?: return
val gridPositionToUse = if (useGridPosition) medium.gridPosition else position val gridPositionToUse = if (useGridPosition) medium.gridPosition else position
val column = gridPositionToUse % spanCount val column = gridPositionToUse % spanCount