make really sure that only the proper folders are shown at Show All Folders Content

This commit is contained in:
tibbi 2018-05-25 11:54:37 +02:00
parent af6121ec63
commit c4ef4a69b9
4 changed files with 16 additions and 23 deletions

View file

@ -481,6 +481,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mCurrAsyncTask = GetMediaAsynctask(applicationContext, mPath, mIsGetImageIntent, mIsGetVideoIntent, mShowAll) { mCurrAsyncTask = GetMediaAsynctask(applicationContext, mPath, mIsGetImageIntent, mIsGetVideoIntent, mShowAll) {
gotMedia(it) gotMedia(it)
} }
mCurrAsyncTask!!.execute() mCurrAsyncTask!!.execute()
} }

View file

@ -17,8 +17,8 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
return if (showAll) { return if (showAll) {
val foldersToScan = mediaFetcher.getFoldersToScan() val foldersToScan = mediaFetcher.getFoldersToScan()
val media = ArrayList<Medium>() val media = ArrayList<Medium>()
for (folder in foldersToScan) { foldersToScan.forEach {
val newMedia = mediaFetcher.getFilesFrom(folder, isPickImage, isPickVideo, sorting) val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, sorting)
media.addAll(newMedia) media.addAll(newMedia)
} }

View file

@ -302,36 +302,31 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList<Medium>) -> Unit) { fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList<Medium>) -> Unit) {
Thread { Thread {
val mediumDao = galleryDB.MediumDao() val mediumDao = galleryDB.MediumDao()
val media = (if (path == "/") mediumDao.getAll() else mediumDao.getMediaFromPath(path)) as ArrayList<Medium> val foldersToScan = if (path == "/") MediaFetcher(this).getFoldersToScan() else arrayListOf(path)
var media = ArrayList<Medium>()
val shouldShowHidden = config.shouldShowHidden val shouldShowHidden = config.shouldShowHidden
var filteredMedia = media foldersToScan.forEach {
if (!shouldShowHidden) { val currMedia = mediumDao.getMediaFromPath(it)
filteredMedia = media.filter { !it.path.contains("/.") } as ArrayList<Medium> media.addAll(currMedia)
} }
if (path == "/") { if (!shouldShowHidden) {
val excludedFolders = config.excludedFolders media = media.filter { !it.path.contains("/.") } as ArrayList<Medium>
filteredMedia = filteredMedia.filter {
val mediumPath = it.path
excludedFolders.none {
mediumPath.startsWith(it, true)
}
} as ArrayList<Medium>
} }
val filterMedia = config.filterMedia val filterMedia = config.filterMedia
filteredMedia = (when { media = (when {
getVideosOnly -> filteredMedia.filter { it.type == TYPE_VIDEOS } getVideosOnly -> media.filter { it.type == TYPE_VIDEOS }
getImagesOnly -> filteredMedia.filter { it.type == TYPE_IMAGES } getImagesOnly -> media.filter { it.type == TYPE_IMAGES }
else -> filteredMedia.filter { else -> media.filter {
(filterMedia and TYPE_IMAGES != 0 && it.type == TYPE_IMAGES) || (filterMedia and TYPE_IMAGES != 0 && it.type == TYPE_IMAGES) ||
(filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) || (filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) ||
(filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS) (filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS)
} }
}) as ArrayList<Medium> }) as ArrayList<Medium>
MediaFetcher(this).sortMedia(filteredMedia, config.getFileSorting(path)) MediaFetcher(this).sortMedia(media, config.getFileSorting(path))
callback(filteredMedia) callback(media)
media.filter { !getDoesFilePathExist(it.path) }.forEach { media.filter { !getDoesFilePathExist(it.path) }.forEach {
mediumDao.deleteMediumPath(it.path) mediumDao.deleteMediumPath(it.path)

View file

@ -8,9 +8,6 @@ import com.simplemobiletools.gallery.models.Medium
@Dao @Dao
interface MediumDao { interface MediumDao {
@Query("SELECT * FROM media")
fun getAll(): List<Medium>
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type FROM media WHERE parent_path = :path") @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type FROM media WHERE parent_path = :path")
fun getMediaFromPath(path: String): List<Medium> fun getMediaFromPath(path: String): List<Medium>