diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index d136ee640..2a773ec0a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -405,6 +405,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } setupLayoutManager() measureRecyclerViewContent(mMedia) + handleGridSpacing() } else if (mLastSearchedText.isEmpty()) { (currAdapter as MediaAdapter).updateMedia(mMedia) measureRecyclerViewContent(mMedia) @@ -723,6 +724,19 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { media_vertical_fastscroller.setScrollToY(media_grid.computeVerticalScrollOffset()) } + private fun handleGridSpacing() { + if (media_grid.itemDecorationCount > 0) { + media_grid.removeItemDecorationAt(0) + } + + val viewType = config.getFolderViewType(if (mShowAll) SHOW_ALL else mPath) + if (viewType == VIEW_TYPE_GRID) { + val spanCount = config.mediaColumnCnt + val spacing = 2 + media_grid.addItemDecoration(GridSpacingItemDecoration(spanCount, spacing, config.scrollHorizontally)) + } + } + private fun initZoomListener() { val viewType = config.getFolderViewType(if (mShowAll) SHOW_ALL else mPath) if (viewType == VIEW_TYPE_GRID) { @@ -773,6 +787,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } private fun columnCountChanged() { + handleGridSpacing() invalidateOptionsMenu() getMediaAdapter()?.apply { notifyItemRangeChanged(0, media.size) 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 new file mode 100644 index 000000000..07aa1cc43 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/GridSpacingItemDecoration.kt @@ -0,0 +1,27 @@ +package com.simplemobiletools.gallery.pro.helpers + +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() { + + 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 + } + } else { + outRect.left = column * spacing / spanCount + outRect.right = spacing - (column + 1) * spacing / spanCount + if (position >= spanCount) { + outRect.top = spacing + } + } + } +} diff --git a/app/src/main/res/layout/photo_video_item_grid.xml b/app/src/main/res/layout/photo_video_item_grid.xml index 64dbbf88f..cc3fc718d 100644 --- a/app/src/main/res/layout/photo_video_item_grid.xml +++ b/app/src/main/res/layout/photo_video_item_grid.xml @@ -5,8 +5,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" - android:focusable="true" - android:padding="1px"> + android:focusable="true">