From f47190b9e128912ec548149c727cf3929e953c0f Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Jun 2018 23:48:50 +0200 Subject: [PATCH] refresh media thumbnails if only the grouping changes --- .../gallery/adapters/MediaAdapter.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index c6fc604af..49a0e47d6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -39,6 +39,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private var loadImageInstantly = false private var delayHandler = Handler(Looper.getMainLooper()) private var currentMediaHash = media.hashCode() + private var currentGrouping = GROUP_BY_NONE private val hasOTGConnected = activity.hasOTGConnected() private var mediumGroups = LinkedHashMap>() @@ -291,7 +292,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } fun updateMedia(newMedia: ArrayList) { - if (newMedia.hashCode() != currentMediaHash) { + if (newMedia.hashCode() != currentMediaHash || currentGrouping != getCurrentFolderGrouping()) { currentMediaHash = newMedia.hashCode() Handler().postDelayed({ media = newMedia @@ -333,20 +334,20 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } private fun groupMedia() { - val grouping = activity.config.getFolderGrouping(path) - if (grouping and GROUP_BY_NONE != 0) { + currentGrouping = getCurrentFolderGrouping() + if (currentGrouping and GROUP_BY_NONE != 0) { return } media.forEach { - val key = it.getGroupingKey(grouping) + val key = it.getGroupingKey(currentGrouping) if (!mediumGroups.containsKey(key)) { mediumGroups[key] = ArrayList() } mediumGroups[key]!!.add(it) } - val sortDescending = grouping and GROUP_DESCENDING != 0 + val sortDescending = currentGrouping and GROUP_DESCENDING != 0 val sorted = mediumGroups.toSortedMap(if (sortDescending) compareByDescending { it } else compareBy { it }) mediumGroups.clear() sorted.forEach { key, value -> @@ -354,6 +355,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } + private fun getCurrentFolderGrouping() = activity.config.getFolderGrouping(path) + private fun setupView(view: View, medium: Medium) { view.apply { play_outline.beVisibleIf(medium.isVideo())