do the hidden file filtering right inside getCachedMedia

This commit is contained in:
tibbi 2018-04-22 10:20:32 +02:00
parent d479baa625
commit a90f48889d
2 changed files with 10 additions and 10 deletions

View file

@ -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<Medium>
}
if (media.isEmpty()) {
if (it.isEmpty()) {
media_refresh_layout.isRefreshing = true
} else {
gotMedia(media, true)
gotMedia(it, true)
}
}
} else {
@ -485,9 +479,10 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
deleteDirectoryIfEmpty()
finish()
true
} else
} else {
false
}
}
private fun tryToggleTemporarilyShowHidden() {
if (config.temporarilyShowHidden) {

View file

@ -258,7 +258,12 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList<Medium>) -> Unit)
Thread {
val mediumDao = galleryDB.MediumDao()
val media = mediumDao.getMediaFromPath(path) as ArrayList<Medium>
callback(media)
val shouldShowHidden = config.shouldShowHidden
var filteredMedia = media
if (!shouldShowHidden) {
filteredMedia = media.filter { !it.name.startsWith('.') } as ArrayList<Medium>
}
callback(filteredMedia)
media.filter { !File(it.path).exists() }.forEach {
mediumDao.deleteMediumPath(it.path)