mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 14:37:59 +01:00
add side margin if file thumbnails have rounded corners
This commit is contained in:
parent
73cf37d463
commit
92802b2923
2 changed files with 30 additions and 10 deletions
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,23 +4,43 @@ 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) {
|
||||
outRect.top = column * spacing / spanCount
|
||||
outRect.bottom = spacing - (column + 1) * spacing / spanCount
|
||||
if (position >= spanCount) {
|
||||
outRect.left = spacing
|
||||
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 {
|
||||
outRect.left = column * spacing / spanCount
|
||||
outRect.right = spacing - (column + 1) * spacing / spanCount
|
||||
if (position >= spanCount) {
|
||||
outRect.top = spacing
|
||||
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
|
||||
if (position >= spanCount) {
|
||||
outRect.top = spacing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue