From c4ef4a69b9e5df432c1e3bd0b0c7c9b50b6550f9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 25 May 2018 11:54:37 +0200 Subject: [PATCH] make really sure that only the proper folders are shown at Show All Folders Content --- .../gallery/activities/MediaActivity.kt | 1 + .../gallery/asynctasks/GetMediaAsynctask.kt | 4 +-- .../gallery/extensions/Context.kt | 31 ++++++++----------- .../gallery/interfaces/MediumDao.kt | 3 -- 4 files changed, 16 insertions(+), 23 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 ca1b7226e..877fcf228 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -481,6 +481,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mCurrAsyncTask = GetMediaAsynctask(applicationContext, mPath, mIsGetImageIntent, mIsGetVideoIntent, mShowAll) { gotMedia(it) } + mCurrAsyncTask!!.execute() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index 6a5dee554..bd82fdac3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -17,8 +17,8 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage return if (showAll) { val foldersToScan = mediaFetcher.getFoldersToScan() val media = ArrayList() - for (folder in foldersToScan) { - val newMedia = mediaFetcher.getFilesFrom(folder, isPickImage, isPickVideo, sorting) + foldersToScan.forEach { + val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, sorting) media.addAll(newMedia) } 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 069a2f405..80fb91dee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -302,36 +302,31 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: 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 foldersToScan = if (path == "/") MediaFetcher(this).getFoldersToScan() else arrayListOf(path) + var media = ArrayList() val shouldShowHidden = config.shouldShowHidden - var filteredMedia = media - if (!shouldShowHidden) { - filteredMedia = media.filter { !it.path.contains("/.") } as ArrayList + foldersToScan.forEach { + val currMedia = mediumDao.getMediaFromPath(it) + media.addAll(currMedia) } - if (path == "/") { - val excludedFolders = config.excludedFolders - filteredMedia = filteredMedia.filter { - val mediumPath = it.path - excludedFolders.none { - mediumPath.startsWith(it, true) - } - } as ArrayList + if (!shouldShowHidden) { + media = media.filter { !it.path.contains("/.") } 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 { + media = (when { + getVideosOnly -> media.filter { it.type == TYPE_VIDEOS } + getImagesOnly -> media.filter { it.type == TYPE_IMAGES } + else -> media.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 - MediaFetcher(this).sortMedia(filteredMedia, config.getFileSorting(path)) - callback(filteredMedia) + MediaFetcher(this).sortMedia(media, config.getFileSorting(path)) + callback(media) media.filter { !getDoesFilePathExist(it.path) }.forEach { mediumDao.deleteMediumPath(it.path) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt index eee0430c4..1c076f768 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -8,9 +8,6 @@ import com.simplemobiletools.gallery.models.Medium @Dao interface MediumDao { - @Query("SELECT * FROM media") - fun getAll(): List - @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type FROM media WHERE parent_path = :path") fun getMediaFromPath(path: String): List