From 302a7842c4cab7a364dc4101b84ffa4a1aa07a4c Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 22:17:40 +0200 Subject: [PATCH] fetch all stored media files at "Show all folders content" --- .../gallery/extensions/Context.kt | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) 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 944051624..cbf70ea24 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -271,32 +271,33 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: }.start() } -fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList) -> Unit) = - Thread { - val mediumDao = galleryDB.MediumDao() - val media = mediumDao.getMediaFromPath(path) as ArrayList - val shouldShowHidden = config.shouldShowHidden - var filteredMedia = media - if (!shouldShowHidden) { - filteredMedia = media.filter { !it.name.startsWith('.') } as ArrayList - } +fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList) -> Unit) { + Thread { + val mediumDao = galleryDB.MediumDao() + val media = (if (path == "/") mediumDao.getAll() else mediumDao.getMediaFromPath(path)) as ArrayList + val shouldShowHidden = config.shouldShowHidden + var filteredMedia = media + if (!shouldShowHidden) { + filteredMedia = media.filter { !it.name.startsWith('.') } as ArrayList + } - val filterMedia = config.filterMedia - filteredMedia = (when { - getVideosOnly -> filteredMedia.filter { it.type == TYPE_VIDEOS } - getImagesOnly -> filteredMedia.filter { it.type == TYPE_IMAGES } - else -> filteredMedia.filter { - (filterMedia and TYPE_IMAGES != 0 && it.type == TYPE_IMAGES) || - (filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) || - (filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS) - } - }) as ArrayList - - callback(filteredMedia) - media.filter { !File(it.path).exists() }.forEach { - mediumDao.deleteMediumPath(it.path) + val filterMedia = config.filterMedia + filteredMedia = (when { + getVideosOnly -> filteredMedia.filter { it.type == TYPE_VIDEOS } + getImagesOnly -> filteredMedia.filter { it.type == TYPE_IMAGES } + else -> filteredMedia.filter { + (filterMedia and TYPE_IMAGES != 0 && it.type == TYPE_IMAGES) || + (filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) || + (filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS) } - }.start() + }) as ArrayList + + callback(filteredMedia) + media.filter { !File(it.path).exists() }.forEach { + mediumDao.deleteMediumPath(it.path) + } + }.start() +} fun Context.removeInvalidDirectories(dirs: ArrayList? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { val dirsToCheck = dirs ?: directoryDao.getAll()