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 00eff92ec..77ed679b8 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 @@ -747,7 +747,9 @@ 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, config.fileRoundedCorners)) + val useGridPosition = mMedia.firstOrNull() is ThumbnailSection + val decoration = GridSpacingItemDecoration(spanCount, spacing, config.scrollHorizontally, config.fileRoundedCorners, mMedia, useGridPosition) + media_grid.addItemDecoration(decoration) } } 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 index f690443ec..d9150bd1b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/GridSpacingItemDecoration.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/GridSpacingItemDecoration.kt @@ -3,12 +3,17 @@ package com.simplemobiletools.gallery.pro.helpers import android.graphics.Rect import android.view.View import androidx.recyclerview.widget.RecyclerView +import com.simplemobiletools.gallery.pro.models.Medium +import com.simplemobiletools.gallery.pro.models.ThumbnailItem -class GridSpacingItemDecoration(val spanCount: Int, val spacing: Int, val isScrollingHorizontally: Boolean, val addSideSpacing: Boolean) : RecyclerView.ItemDecoration() { +class GridSpacingItemDecoration(val spanCount: Int, val spacing: Int, val isScrollingHorizontally: Boolean, val addSideSpacing: Boolean, + val items: ArrayList, val useGridPosition: Boolean) : RecyclerView.ItemDecoration() { override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) { val position = parent.getChildAdapterPosition(view) - val column = position % spanCount + val medium = items[position] as? Medium ?: return + val gridPositionToUse = if (useGridPosition) medium.gridPosition else position + val column = gridPositionToUse % spanCount if (isScrollingHorizontally) { if (addSideSpacing) { @@ -32,13 +37,14 @@ class GridSpacingItemDecoration(val spanCount: Int, val spacing: Int, val isScro outRect.right = (column + 1) * spacing / spanCount outRect.bottom = spacing - if (position < spanCount) { + if (position < spanCount && !useGridPosition) { outRect.top = spacing } } else { outRect.left = column * spacing / spanCount outRect.right = spacing - (column + 1) * spacing / spanCount - if (position >= spanCount) { + + if (gridPositionToUse >= spanCount) { outRect.top = spacing } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt index 04248ae02..86d2e56e1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt @@ -635,12 +635,15 @@ class MediaFetcher(val context: Context) { return thumbnailItems } + var currentGridPosition = 0 val mediumGroups = LinkedHashMap>() media.forEach { val key = it.getGroupingKey(currentGrouping) if (!mediumGroups.containsKey(key)) { mediumGroups[key] = ArrayList() + currentGridPosition = 0 } + it.gridPosition = currentGridPosition++ mediumGroups[key]!!.add(it) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Medium.kt index 0041b0e28..05adfa524 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Medium.kt @@ -1,10 +1,7 @@ package com.simplemobiletools.gallery.pro.models import android.content.Context -import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.Index -import androidx.room.PrimaryKey +import androidx.room.* import com.bumptech.glide.signature.ObjectKey import com.simplemobiletools.commons.extensions.formatDate import com.simplemobiletools.commons.extensions.formatSize @@ -25,13 +22,18 @@ data class Medium( @ColumnInfo(name = "filename") var name: String, @ColumnInfo(name = "full_path") var path: String, @ColumnInfo(name = "parent_path") var parentPath: String, - @ColumnInfo(name = "last_modified") val modified: Long, + @ColumnInfo(name = "last_modified") var modified: Long, @ColumnInfo(name = "date_taken") var taken: Long, - @ColumnInfo(name = "size") val size: Long, - @ColumnInfo(name = "type") val type: Int, - @ColumnInfo(name = "video_duration") val videoDuration: Int, + @ColumnInfo(name = "size") var size: Long, + @ColumnInfo(name = "type") var type: Int, + @ColumnInfo(name = "video_duration") var videoDuration: Int, @ColumnInfo(name = "is_favorite") var isFavorite: Boolean, - @ColumnInfo(name = "deleted_ts") var deletedTS: Long) : Serializable, ThumbnailItem() { + @ColumnInfo(name = "deleted_ts") var deletedTS: Long, + + @Ignore var gridPosition: Int = 0 // used at grid view decoration at Grouping enabled +) : Serializable, ThumbnailItem() { + + constructor() : this(null, "", "", "", 0L, 0L, 0L, 0, 0, false, 0L, 0) companion object { private const val serialVersionUID = -6553149366975655L