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 77ed679b8..ed1e71546 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 @@ -418,10 +418,11 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { media_grid.adapter = this } setupLayoutManager() - measureRecyclerViewContent(mMedia) handleGridSpacing() + measureRecyclerViewContent(mMedia) } else if (mLastSearchedText.isEmpty()) { (currAdapter as MediaAdapter).updateMedia(mMedia) + handleGridSpacing() measureRecyclerViewContent(mMedia) } else { searchQueryChanged(mLastSearchedText) 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 86d2e56e1..25d2ffb60 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,15 +635,12 @@ 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) } @@ -667,8 +664,14 @@ class MediaFetcher(val context: Context) { val today = formatDate(System.currentTimeMillis().toString(), true) val yesterday = formatDate((System.currentTimeMillis() - DAY_SECONDS * 1000).toString(), true) for ((key, value) in mediumGroups) { + var currentGridPosition = 0 val sectionKey = getFormattedKey(key, currentGrouping, today, yesterday) thumbnailItems.add(ThumbnailSection(sectionKey)) + + value.forEach { + it.gridPosition = currentGridPosition++ + } + thumbnailItems.addAll(value) }