change the way grid spacing is handled, make it more dynamic
This commit is contained in:
parent
f84f4e3098
commit
823309c35e
3 changed files with 43 additions and 2 deletions
|
@ -405,6 +405,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
}
|
}
|
||||||
setupLayoutManager()
|
setupLayoutManager()
|
||||||
measureRecyclerViewContent(mMedia)
|
measureRecyclerViewContent(mMedia)
|
||||||
|
handleGridSpacing()
|
||||||
} else if (mLastSearchedText.isEmpty()) {
|
} else if (mLastSearchedText.isEmpty()) {
|
||||||
(currAdapter as MediaAdapter).updateMedia(mMedia)
|
(currAdapter as MediaAdapter).updateMedia(mMedia)
|
||||||
measureRecyclerViewContent(mMedia)
|
measureRecyclerViewContent(mMedia)
|
||||||
|
@ -723,6 +724,19 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
media_vertical_fastscroller.setScrollToY(media_grid.computeVerticalScrollOffset())
|
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() {
|
private fun initZoomListener() {
|
||||||
val viewType = config.getFolderViewType(if (mShowAll) SHOW_ALL else mPath)
|
val viewType = config.getFolderViewType(if (mShowAll) SHOW_ALL else mPath)
|
||||||
if (viewType == VIEW_TYPE_GRID) {
|
if (viewType == VIEW_TYPE_GRID) {
|
||||||
|
@ -773,6 +787,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun columnCountChanged() {
|
private fun columnCountChanged() {
|
||||||
|
handleGridSpacing()
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
getMediaAdapter()?.apply {
|
getMediaAdapter()?.apply {
|
||||||
notifyItemRangeChanged(0, media.size)
|
notifyItemRangeChanged(0, media.size)
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,8 +5,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true"
|
android:focusable="true">
|
||||||
android:padding="1px">
|
|
||||||
|
|
||||||
<com.simplemobiletools.gallery.pro.views.MySquareImageView
|
<com.simplemobiletools.gallery.pro.views.MySquareImageView
|
||||||
android:id="@+id/medium_thumbnail"
|
android:id="@+id/medium_thumbnail"
|
||||||
|
|
Loading…
Reference in a new issue