add side margin if file thumbnails have rounded corners

This commit is contained in:
tibbi 2021-01-18 19:44:48 +01:00
parent 73cf37d463
commit 92802b2923
2 changed files with 30 additions and 10 deletions

View file

@ -739,7 +739,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
if (viewType == VIEW_TYPE_GRID) {
val spanCount = config.mediaColumnCnt
val spacing = config.thumbnailSpacing
media_grid.addItemDecoration(GridSpacingItemDecoration(spanCount, spacing, config.scrollHorizontally))
media_grid.addItemDecoration(GridSpacingItemDecoration(spanCount, spacing, config.scrollHorizontally, config.fileRoundedCorners))
}
}

View file

@ -4,18 +4,37 @@ import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
class GridSpacingItemDecoration(val spanCount: Int, val spacing: Int, val isScrollingHorizontally: Boolean) : RecyclerView.ItemDecoration() {
class GridSpacingItemDecoration(val spanCount: Int, val spacing: Int, val isScrollingHorizontally: Boolean, val addSideSpacing: Boolean) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val position = parent.getChildAdapterPosition(view)
val column = position % spanCount
if (isScrollingHorizontally) {
if (addSideSpacing) {
outRect.top = spacing - column * spacing / spanCount
outRect.bottom = (column + 1) * spacing / spanCount
outRect.right = spacing
if (position < spanCount) {
outRect.left = spacing
}
} else {
outRect.top = column * spacing / spanCount
outRect.bottom = spacing - (column + 1) * spacing / spanCount
if (position >= spanCount) {
outRect.left = spacing
}
}
} else {
if (addSideSpacing) {
outRect.left = spacing - column * spacing / spanCount
outRect.right = (column + 1) * spacing / spanCount
outRect.bottom = spacing
if (position < spanCount) {
outRect.top = spacing
}
} else {
outRect.left = column * spacing / spanCount
outRect.right = spacing - (column + 1) * spacing / spanCount
@ -24,4 +43,5 @@ class GridSpacingItemDecoration(val spanCount: Int, val spacing: Int, val isScro
}
}
}
}
}