diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/GridSpacingItemDecoration.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/GridSpacingItemDecoration.kt index d9150bd1b..d6d0f7ca7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/GridSpacingItemDecoration.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/GridSpacingItemDecoration.kt @@ -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) { 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 column = gridPositionToUse % spanCount