From 7f2db078925d1371bec5fb3e1d62c4570b89be98 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jan 2021 23:12:39 +0100 Subject: [PATCH] properly handle grid updating if a thumbnail gets deleted --- .../gallery/pro/activities/MediaActivity.kt | 17 +++++++++++++++++ .../gallery/pro/activities/SearchActivity.kt | 3 +++ .../gallery/pro/adapters/MediaAdapter.kt | 1 + .../pro/interfaces/MediaOperationsListener.kt | 3 +++ 4 files changed, 24 insertions(+) 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 740877462..763295a73 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 @@ -46,6 +46,7 @@ import kotlinx.android.synthetic.main.activity_media.* import java.io.File import java.io.IOException import java.util.* +import kotlin.collections.ArrayList class MediaActivity : SimpleActivity(), MediaOperationsListener { private val LAST_MEDIA_CHECK_PERIOD = 3000L @@ -989,6 +990,22 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { finish() } + override fun updateMediaGridDecoration(media: ArrayList) { + var currentGridPosition = 0 + media.forEach { + if (it is Medium) { + it.gridPosition = currentGridPosition++ + } else if (it is ThumbnailSection) { + currentGridPosition = 0 + } + } + + if (media_grid.itemDecorationCount > 0) { + val currentGridDecoration = media_grid.getItemDecorationAt(0) as GridSpacingItemDecoration + currentGridDecoration.items = media + } + } + private fun setAsDefaultFolder() { config.defaultFolder = mPath invalidateOptionsMenu() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt index 24c48600b..6a5b30483 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt @@ -379,4 +379,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener { override fun selectedPaths(paths: ArrayList) { } + + override fun updateMediaGridDecoration(media: ArrayList) { + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index 2fec95f6b..fa04937fc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -439,6 +439,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList) fun selectedPaths(paths: ArrayList) + + fun updateMediaGridDecoration(media: ArrayList) }