From 41d0b0bef9b9fb25d234dca2fcd39280cb735832 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 23 Jan 2018 10:14:50 +0100 Subject: [PATCH] move thumbnail hashcode checking directly in adapters --- .../gallery/activities/MainActivity.kt | 4 ---- .../gallery/activities/MediaActivity.kt | 6 ------ .../gallery/adapters/DirectoryAdapter.kt | 10 +++++++--- .../gallery/adapters/MediaAdapter.kt | 12 ++++++++---- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index d8423670e..228a5d13c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -548,10 +548,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll) checkLastMediaChanged() - if (dirs.hashCode() == mDirs.hashCode()) { - return - } - mDirs = dirs runOnUiThread { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index e8d13e7fb..28cee544a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -59,7 +59,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mStoredScrollHorizontally = true private var mStoredShowInfoBubble = true private var mStoredTextColor = 0 - private var mLastDrawnHashCode = 0 private var mLatestMediaId = 0L private var mLastMediaHandler = Handler() private var mCurrAsyncTask: GetMediaAsynctask? = null @@ -603,11 +602,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { checkLastMediaChanged() - if (media.hashCode() == mMedia.hashCode() && media.hashCode() == mLastDrawnHashCode) { - return - } - - mLastDrawnHashCode = media.hashCode() mMedia = media runOnUiThread { setupAdapter() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 559a9bcc4..a334e344d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -38,6 +38,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList) { - dirs = newDirs - notifyDataSetChanged() - finishActMode() + if (newDirs.hashCode() != currentDirectoriesHash) { + currentDirectoriesHash = newDirs.hashCode() + dirs = newDirs + notifyDataSetChanged() + finishActMode() + } } fun updateAnimateGifs(animateGifs: Boolean) { 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 cb5dad83c..e54fd102c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -38,6 +38,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private var visibleItemPaths = ArrayList() private var loadImageInstantly = false private var delayHandler = Handler(Looper.getMainLooper()) + private var currentMediaHash = media.hashCode() private var scrollHorizontally = config.scrollHorizontally private var animateGifs = config.animateGifs @@ -246,10 +247,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } fun updateMedia(newMedia: ArrayList) { - media = newMedia - enableInstantLoad() - notifyDataSetChanged() - finishActMode() + if (newMedia.hashCode() != currentMediaHash) { + currentMediaHash = newMedia.hashCode() + media = newMedia + enableInstantLoad() + notifyDataSetChanged() + finishActMode() + } } fun updateDisplayFilenames(displayFilenames: Boolean) {