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 mIsGettingMedia = true
if (!mLoadedInitialPhotos) { if (!mLoadedInitialPhotos) {
getCachedMedia(mPath) { getCachedMedia(mPath) {
val shouldShowHidden = config.shouldShowHidden if (it.isEmpty()) {
var media = it
if (!shouldShowHidden) {
media = media.filter { !it.name.startsWith('.') } as ArrayList<Medium>
}
if (media.isEmpty()) {
media_refresh_layout.isRefreshing = true media_refresh_layout.isRefreshing = true
} else { } else {
gotMedia(media, true) gotMedia(it, true)
} }
} }
} else { } else {
@ -485,8 +479,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
deleteDirectoryIfEmpty() deleteDirectoryIfEmpty()
finish() finish()
true true
} else } else {
false false
}
} }
private fun tryToggleTemporarilyShowHidden() { private fun tryToggleTemporarilyShowHidden() {

View file

@ -258,7 +258,12 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList<Medium>) -> Unit)
Thread { Thread {
val mediumDao = galleryDB.MediumDao() val mediumDao = galleryDB.MediumDao()
val media = mediumDao.getMediaFromPath(path) as ArrayList<Medium> 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 { media.filter { !File(it.path).exists() }.forEach {
mediumDao.deleteMediumPath(it.path) mediumDao.deleteMediumPath(it.path)