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) { if (viewType == VIEW_TYPE_GRID) {
val spanCount = config.mediaColumnCnt val spanCount = config.mediaColumnCnt
val spacing = config.thumbnailSpacing 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,23 +4,43 @@ import android.graphics.Rect
import android.view.View import android.view.View
import androidx.recyclerview.widget.RecyclerView 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) { override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val position = parent.getChildAdapterPosition(view) val position = parent.getChildAdapterPosition(view)
val column = position % spanCount val column = position % spanCount
if (isScrollingHorizontally) { if (isScrollingHorizontally) {
outRect.top = column * spacing / spanCount if (addSideSpacing) {
outRect.bottom = spacing - (column + 1) * spacing / spanCount outRect.top = spacing - column * spacing / spanCount
if (position >= spanCount) { outRect.bottom = (column + 1) * spacing / spanCount
outRect.left = spacing 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 { } else {
outRect.left = column * spacing / spanCount if (addSideSpacing) {
outRect.right = spacing - (column + 1) * spacing / spanCount outRect.left = spacing - column * spacing / spanCount
if (position >= spanCount) { outRect.right = (column + 1) * spacing / spanCount
outRect.top = spacing outRect.bottom = spacing
if (position < spanCount) {
outRect.top = spacing
}
} else {
outRect.left = column * spacing / spanCount
outRect.right = spacing - (column + 1) * spacing / spanCount
if (position >= spanCount) {
outRect.top = spacing
}
} }
} }
} }