delete invalid files from cache at loading thumbnails

This commit is contained in:
tibbi 2018-12-11 12:47:18 +01:00
parent b7a19908c7
commit b64f164742
1 changed files with 10 additions and 2 deletions

View File

@ -585,7 +585,15 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
mCurrAsyncTask?.stopFetching()
mCurrAsyncTask = GetMediaAsynctask(applicationContext, mPath, mIsGetImageIntent, mIsGetVideoIntent, mShowAll) {
Thread {
gotMedia(it)
val oldMedia = mMedia.clone() as ArrayList<ThumbnailItem>
val newMedia = it
gotMedia(newMedia, false)
try {
oldMedia.filter { !newMedia.contains(it) }.mapNotNull { it as? Medium }.filter { !File(it.path).exists() }.forEach {
mMediumDao.deleteMediumPath(it.path)
}
} catch (e: Exception) {
}
}.start()
}
@ -820,7 +828,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
}
}
private fun gotMedia(media: ArrayList<ThumbnailItem>, isFromCache: Boolean = false) {
private fun gotMedia(media: ArrayList<ThumbnailItem>, isFromCache: Boolean) {
mIsGettingMedia = false
checkLastMediaChanged()
mMedia = media