diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index 791cabd78..a8390793d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -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 + 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, isFromCache: Boolean = false) { + private fun gotMedia(media: ArrayList, isFromCache: Boolean) { mIsGettingMedia = false checkLastMediaChanged() mMedia = media