From a90f48889d6be5fc8f8634ff1541f417ffac0318 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 10:20:32 +0200 Subject: [PATCH] do the hidden file filtering right inside getCachedMedia --- .../gallery/activities/MediaActivity.kt | 13 ++++--------- .../simplemobiletools/gallery/extensions/Context.kt | 7 ++++++- 2 files changed, 10 insertions(+), 10 deletions(-) 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 384af1343..7d167f334 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -456,16 +456,10 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mIsGettingMedia = true if (!mLoadedInitialPhotos) { getCachedMedia(mPath) { - val shouldShowHidden = config.shouldShowHidden - var media = it - if (!shouldShowHidden) { - media = media.filter { !it.name.startsWith('.') } as ArrayList - } - - if (media.isEmpty()) { + if (it.isEmpty()) { media_refresh_layout.isRefreshing = true } else { - gotMedia(media, true) + gotMedia(it, true) } } } else { @@ -485,8 +479,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { deleteDirectoryIfEmpty() finish() true - } else + } else { false + } } private fun tryToggleTemporarilyShowHidden() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt index 74718a1f7..906c0f026 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -258,7 +258,12 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList) -> Unit) Thread { val mediumDao = galleryDB.MediumDao() val media = mediumDao.getMediaFromPath(path) as ArrayList - callback(media) + val shouldShowHidden = config.shouldShowHidden + var filteredMedia = media + if (!shouldShowHidden) { + filteredMedia = media.filter { !it.name.startsWith('.') } as ArrayList + } + callback(filteredMedia) media.filter { !File(it.path).exists() }.forEach { mediumDao.deleteMediumPath(it.path)