use proper grid position at thumbnails with grouping and section titles
This commit is contained in:
parent
78a75fe873
commit
efe26e9c58
4 changed files with 27 additions and 14 deletions
|
@ -747,7 +747,9 @@ 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, config.fileRoundedCorners))
|
val useGridPosition = mMedia.firstOrNull() is ThumbnailSection
|
||||||
|
val decoration = GridSpacingItemDecoration(spanCount, spacing, config.scrollHorizontally, config.fileRoundedCorners, mMedia, useGridPosition)
|
||||||
|
media_grid.addItemDecoration(decoration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,17 @@ package com.simplemobiletools.gallery.pro.helpers
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
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<ThumbnailItem>, val useGridPosition: 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 medium = items[position] as? Medium ?: return
|
||||||
|
val gridPositionToUse = if (useGridPosition) medium.gridPosition else position
|
||||||
|
val column = gridPositionToUse % spanCount
|
||||||
|
|
||||||
if (isScrollingHorizontally) {
|
if (isScrollingHorizontally) {
|
||||||
if (addSideSpacing) {
|
if (addSideSpacing) {
|
||||||
|
@ -32,13 +37,14 @@ class GridSpacingItemDecoration(val spanCount: Int, val spacing: Int, val isScro
|
||||||
outRect.right = (column + 1) * spacing / spanCount
|
outRect.right = (column + 1) * spacing / spanCount
|
||||||
outRect.bottom = spacing
|
outRect.bottom = spacing
|
||||||
|
|
||||||
if (position < spanCount) {
|
if (position < spanCount && !useGridPosition) {
|
||||||
outRect.top = spacing
|
outRect.top = spacing
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
outRect.left = column * spacing / spanCount
|
outRect.left = column * spacing / spanCount
|
||||||
outRect.right = spacing - (column + 1) * spacing / spanCount
|
outRect.right = spacing - (column + 1) * spacing / spanCount
|
||||||
if (position >= spanCount) {
|
|
||||||
|
if (gridPositionToUse >= spanCount) {
|
||||||
outRect.top = spacing
|
outRect.top = spacing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -635,12 +635,15 @@ class MediaFetcher(val context: Context) {
|
||||||
return thumbnailItems
|
return thumbnailItems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currentGridPosition = 0
|
||||||
val mediumGroups = LinkedHashMap<String, ArrayList<Medium>>()
|
val mediumGroups = LinkedHashMap<String, ArrayList<Medium>>()
|
||||||
media.forEach {
|
media.forEach {
|
||||||
val key = it.getGroupingKey(currentGrouping)
|
val key = it.getGroupingKey(currentGrouping)
|
||||||
if (!mediumGroups.containsKey(key)) {
|
if (!mediumGroups.containsKey(key)) {
|
||||||
mediumGroups[key] = ArrayList()
|
mediumGroups[key] = ArrayList()
|
||||||
|
currentGridPosition = 0
|
||||||
}
|
}
|
||||||
|
it.gridPosition = currentGridPosition++
|
||||||
mediumGroups[key]!!.add(it)
|
mediumGroups[key]!!.add(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package com.simplemobiletools.gallery.pro.models
|
package com.simplemobiletools.gallery.pro.models
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.*
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.Index
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import com.bumptech.glide.signature.ObjectKey
|
import com.bumptech.glide.signature.ObjectKey
|
||||||
import com.simplemobiletools.commons.extensions.formatDate
|
import com.simplemobiletools.commons.extensions.formatDate
|
||||||
import com.simplemobiletools.commons.extensions.formatSize
|
import com.simplemobiletools.commons.extensions.formatSize
|
||||||
|
@ -25,13 +22,18 @@ data class Medium(
|
||||||
@ColumnInfo(name = "filename") var name: String,
|
@ColumnInfo(name = "filename") var name: String,
|
||||||
@ColumnInfo(name = "full_path") var path: String,
|
@ColumnInfo(name = "full_path") var path: String,
|
||||||
@ColumnInfo(name = "parent_path") var parentPath: 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 = "date_taken") var taken: Long,
|
||||||
@ColumnInfo(name = "size") val size: Long,
|
@ColumnInfo(name = "size") var size: Long,
|
||||||
@ColumnInfo(name = "type") val type: Int,
|
@ColumnInfo(name = "type") var type: Int,
|
||||||
@ColumnInfo(name = "video_duration") val videoDuration: Int,
|
@ColumnInfo(name = "video_duration") var videoDuration: Int,
|
||||||
@ColumnInfo(name = "is_favorite") var isFavorite: Boolean,
|
@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 {
|
companion object {
|
||||||
private const val serialVersionUID = -6553149366975655L
|
private const val serialVersionUID = -6553149366975655L
|
||||||
|
|
Loading…
Reference in a new issue